utils_visualise.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:DeepVis-PredDiff 作者: lmzintgraf 项目源码 文件源码
def get_overlayed_image(x, c, gray_factor_bg = 0.3):    
    '''
    For an image x and a relevance vector c, overlay the image with the 
    relevance vector to visualise the influence of the image pixels.
    '''
    imDim = x.shape[0]

    if np.ndim(c)==1:
        c = c.reshape((imDim,imDim))
    if np.ndim(x)==2: # this happens with the MNIST Data
        x = 1-np.dstack((x, x, x))*gray_factor_bg # make it a bit grayish
    if np.ndim(x)==3: # this is what happens with cifar data        
        x = color.rgb2gray(x)
        x = 1-(1-x)*0.5
        x = np.dstack((x,x,x))

    alpha = 0.8

    # Construct a colour image to superimpose
    im = plt.imshow(c, cmap = cm.seismic, vmin=-np.max(np.abs(c)), vmax=np.max(np.abs(c)), interpolation='nearest')
    color_mask = im.to_rgba(c)[:,:,[0,1,2]]

    # Convert the input image and color mask to Hue Saturation Value (HSV) colorspace
    img_hsv = color.rgb2hsv(x)
    color_mask_hsv = color.rgb2hsv(color_mask)

    # Replace the hue and saturation of the original image
    # with that of the color mask
    img_hsv[..., 0] = color_mask_hsv[..., 0]
    img_hsv[..., 1] = color_mask_hsv[..., 1] * alpha

    img_masked = color.hsv2rgb(img_hsv)

    return img_masked
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号