Moving from RGB to scalars in matplotlib colormap

I am using matplotlib to convert arrays of 400 floats (read from a text file) to 100x100 pixel images using a predefined color scheme:

vec = [ float(i) for i in l.split()[1:] ]
v = normalise(np.array(vec).reshape((20,20)))
im = Image.fromarray(np.uint8(cm.coolwarm(v)*255))
im = im.resize((100, 100))

      

This works great. But now I would like to reverse this process. That is, given the image, I would like to go from the RGB values ​​of each pixel back to scalars (to get the original array). How should I do it?

NB: my question is related to this , except that I don't want to take any image and convert it back to an array - only the ones that were generated by my color palette in the first place.

+2
python matplotlib colormap


source to share


No one has answered this question yet

See similar questions:

3
How to decode color mapping in matplotlib Colormap?
3
Invert (not vice versa) color map in matplotlib?

or similar:

1667
How can I resize drawings drawn with matplotlib?
1621
How to randomly select an item from the list?
1015
Save the image to an image file instead of displaying it with Matplotlib
752
How to make matplotlib laptop IP address
480
Problem installing matplotlib Python
121
Invert colormap in matplotlib
3
Matplotlib imshow inverts colors of 2D IFFT array
2
Change matrix to rgb matrix
1
Simple scalar RGB color mapping with matplotlib
0
Using Matplotlib imshow to display GIF image



All Articles
Loading...
X
Show
Funny
Dev
Pics