Converting a color image into a set of data
23 views (last 30 days)
Show older comments
Hi, I have a thermal image in png form, with a color scale/map to go with it of a cell. I am just looking to try and converrt the colors to the designated values based on the color scale/map to the different values based on the color map. Then I am looking to create a graph of the color intesnsity verus distance along the cell. I have attached an image of what I am trying to convert, if you have any tips or information that may help that would be greately appreciated.
0 Comments
Accepted Answer
DGM
on 27 Jun 2024
Edited: DGM
on 27 Jun 2024
I've posted a number of demos on estimating data from a pseducolor image, including thermal images. You need a clean pseudocolor image, a good copy of the colormap it uses, and some idea how the mapping relates to the original data.
% read the image
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1723241/image.png');
% crop out the colorbar and convert it to a color table
CT0 = imcrop(inpict,[622.51 67.51 21.98 545.98]);
CT0 = permute(mean(im2double(CT0),2),[1 3 2]);
CT0 = unique(CT0,'rows','stable');
CT0 = flipud(CT0);
% crop out the main image region
inpict = imcrop(inpict,[0.51 29.51 620.98 631.98]);
% estimate the original data from the pseudocolor visualization
zrange = [1 10];
Z = rgb2ind(inpict,CT0,'nodither');
Z = rescale(Z,zrange(1),zrange(2),'inputmin',0,'inputmax',size(CT0,1)-1);
% visualize the remapping
imagesc(Z)
colorbar
colormap(CT0)
As you can see, we can go through the motions, but the output is terrible. The colors in the ROI aren't present in the colorbar, so everything gets mapped inaccurately.
Either that's a composite thermal image, or the figure itself is a composite image and the colorbar doesn't belong. If it's a composite image, could it be decomposed? Maybe, but not based on a single image without having any other information about what it is or isn't.
I can only guess, but it really looks like it's the wrong colorbar, and thus, the wrong colormap.
Note that I have made no attempt to deal with how the padded areas outside the ROI are mapped.
EDIT:. Yes. That's a fake plot. That is not the colormap used in the ROI. It's just jet(). This is the color population in the ROI.
This is the color population in the colorbar.
This is jet().
So now that you know it's a fake plot, how do you estimate the data? You don't. You throw it away because it's a fake image. It's just a bunch of colors on the screen. There is no information to map it back to the original data. It's just a wild goose chase.
More Answers (0)
See Also
Categories
Find more on Red in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!