문제

I have two 16-bit grayscale images. One is a subimage of the bigger image. They are centred. bigger and the smaller notice, that the smaller looks slightly brighter.

When the two are displayed, the smaller looks brighter. Basically what I would like to do is them to keep the same grayscale value representation, i.e. I would like the smaller image have the same intensity appearance as the bigger one (since the GS intensity values in the respective pixels are the same). Any suggestions ?

for j in xrange(windows_a.shape[0]):
    print j

    pl.imshow(windows_a[j], interpolation='nearest') 
    pl.xticks(np.arange(0,window_size_1,1))
    pl.yticks(np.arange(0,window_size_1,1))
    pl.gray()
    pl.grid( color = 'y' ) 
    pl.savefig('./IW_small/IW_small_' + str("%05d" %i) + "_" + str("%05d" %j) + '.png')
    pl.close()   


    pl.imshow(windows_b[j], interpolation='nearest') 
    pl.xticks(np.arange(0,window_size_2,1))
    pl.yticks(np.arange(0,window_size_2,1))    
    pl.gray()
    pl.grid( color = 'y' ) 
    pl.savefig('./IW_big/IW_big_' + str("%05d" %i) + "_" + str("%05d" %j) + '.png') 
    pl.close() 
도움이 되었습니까?

해결책

You may set the intensity values yourself using the vmin and vmax arguments of the imshow function:

for j in xrange(windows_a.shape[0]):
    print j

    vmin, vmax = windows_b[j].min(), windows_b[j].max()

    pl.imshow(windows_a[j], vmin=vmin, vmax=vmax, interpolation='nearest') 
    pl.xticks(np.arange(0,window_size_1,1))
    pl.yticks(np.arange(0,window_size_1,1))
    pl.gray()
    pl.grid( color = 'y' ) 
    pl.savefig('./IW_small/IW_small_' + str("%05d" %i) + "_" + str("%05d" %j) + '.png')
    pl.close()   


    pl.imshow(windows_b[j], vmin=vmin, vmax=vmax, interpolation='nearest') 
    pl.xticks(np.arange(0,window_size_2,1))
    pl.yticks(np.arange(0,window_size_2,1))    
    pl.gray()
    pl.grid( color = 'y' ) 
    pl.savefig('./IW_big/IW_big_' + str("%05d" %i) + "_" + str("%05d" %j) + '.png') 
    pl.close()

Additionally, I would recommend to use the interpolation='none' argument, since that usually works better with vector graphics. This doesn't make a difference for you PNG file, though.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top