python matplotlib, get pixel value after colormap applied -


i display image matplotlib using imshow(). imshow apply lut , retrieve pixel value (at x, y) after lut applied.

for exemple

  • i have full black image
  • i display imshow
  • the image becomes yellow (cause of lut)

get_pixel(x, y) -> yellow

is there way code function get_pixel ?

so, color of pixels, have @ how matplotlib maps scalar values of pixels colors:

it 2 step process. first, normalization applied map values interval [0,1]. then, colormap maps [0,1] colors. both steps matplotlib provides various options.

if call imshow apply basic linear normalization using minimum , maximum of data. normalization class instance saved attribute of artist. same thing holds colormap.

so compute color of specific pixel have apply these 2 steps manually:

import matplotlib.pyplot plt import numpy np  # set seed ensure reproducability np.random.seed(100)  # build random image img = np.random.rand(10,10)  # create image , save artist  img_artist = plt.imshow(img, interpolation='nearest')  # plot red cross "mark" pixel in question plt.plot(5,5,'rx', markeredgewidth=3, markersize=10)  # color @ pixel 5,5 (use normalization , colormap) print img_artist.cmap(img_artist.norm(img[5,5]))  plt.axis('image') plt.show() 

result:

enter image description here

and color:

(0.0, 0.84901960784313724, 1.0, 1.0)


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -