Frage

I have images (4000x2000 pixels) that are derived from the same image, but with subtle differences in less than 1% of the pixels. I'd like to plot the two images side-by-side and highlight the regions of the array's that are different (by highlight I mean I want the pixels that differ to jump out, but still display the color that matches their value. I've been using rectangles that are unfilled to outline the edges of such pixels so far. I can do this very nicely in small images (~50x50) with:

    fig=figure(figsize=(20,15))
    ax1=fig.add_subplot(1,2,1)
    imshow(image1,interpolation='nearest',origin='lower left')
    colorbar()
    ax2=fig.add_subplot(122,sharex=ax1, sharey=ax1)
    imshow(image2,interpolation='nearest',origin='lower left')
    colorbar()
    #now show differences
    Xspots=im1!=im2
    Xx,Xy=nonzero(Xspots)
    for x,y in zip(Xx,Xy):
           rect=Rectangle((y-.5,x-.5),1,1,color='w',fill=False,ec='w')
           ax1.add_patch(rect)
           ax2.add_patch(rect)

However this doesn't work so well when the image is very large. Strange things happen, for example when I zoom in the patch disappears. Also, this way sucks because it takes forever to load things when I zoom in/out.

I feel like there must be a better way to do this, maybe one where there is only one patch that determines where all of the things are, rather than a whole bunch of patches. I could do a scatter plot on top of the imshow image, but I don't know how to fix it so that the points will stay exactly the size of the pixel when I zoom in/out.

Any ideas?

War es hilfreich?

Lösung

I would try something with the alpha channel:

import copy
N, M = 20, 40
test_data = np.random.rand(N, M)
mark_mask = np.random.rand(N, M) < .01 # mask 1%
# this is redundant in this case, but in general you need it
my_norm = matplotlib.colors.Normalize(vmin=0, vmax=1)
# grab a copy of the color map
my_cmap = copy.copy(cm.get_cmap('cubehelix'))
c_data= my_cmap(my_norm(test_data))
c_data[:, :, 3] = .5 # make everything half alpha
c_data[mark_mask, 3] = 1 # reset the marked pixels as full opacity
# plot it
figure()
imshow(c_data, interpolation='none')

No idea if this will work with your data or not.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top