extracting values from an image with color legend

17 views (last 30 days)
howdy folks,
I want to extract numerical values from this figure. each circle is a fuel rod, that has a "power peaking factor" I would like to obtain a numerical value for that.

Answers (3)

Adam Danz
Adam Danz on 20 May 2024
One way to see the color value is to add the color data to the data tip. When you click on or hover over one of the points, you can see the color data in addition to the other data tip information.
Here are three demos where that is implemented.
  1 Comment
Adam Danz
Adam Danz on 21 May 2024
Based on the other answers, I think I may have misinterpretted the question. My answer offers a solution for MATLAB figures. The other answers, which seem more relevant, offer solution for working with flat images.

Sign in to comment.


DGM
DGM on 20 May 2024
% the image
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1699336/image.png');
% extract the colorbar
CT = imcrop(inpict,[87.51 229.51 41.98 263.98]);
CT = permute(mean(im2double(CT),2),[1 3 2]);
CT = flipud(unique(CT,'rows','stable'));
% these are the extreme colorbar ticks
% i'm assuming everything is linearly spaced
outrange = [0.83 1.19]; % the colorbar scale
% crop out just the area of interest
inpict = imcrop(inpict,[233.51 50.51 631.98 629.98]);
% create a mask which selects the background
[~,S,V] = rgb2hsv(inpict);
bgmask = 1 - (S.*V);
bgmask(11:130,550:end) = 1; % get rid of the remnants of the legend box
% get the distance map
D = -bwdist(bgmask);
% split blobs with watershed segmentation
regionmin = imextendedmin(D,2); % the basin minima (ideally one per cell)
D = imimposemin(D,regionmin);
ridgelines = watershed(D);
mask = ~bgmask;
mask(ridgelines == 0) = false;
imshow(mask)
% estimate zdata from the pseudocolor image
PF = rgb2ind(inpict,CT,'nodither'); % remap to integer indices
inrange = [0 size(CT,1)-1]; % rescale to data units
PF = (outrange(2)-outrange(1))*(double(PF)-inrange(1))/(inrange(2)-inrange(1))+outrange(1);
% get the centroids and mean zdata in each mask blob
% centroids are given [x y]
% mean intensity is the PF as corresponds to the colorbar
% blobs are ordered as the image is scanned from top-bottom, left-right
stats = regionprops(mask,PF,'centroid','meanintensity');
% you can do what you want with that information. I'm just going to dump it into a table.
table(vertcat(stats.Centroid),vertcat(stats.MeanIntensity))
ans = 2112x2 table
Var1 Var2 ________________ _______ 67.346 198.35 0.95375 67.333 212.12 0.93125 67.4 226.04 0.9425 67.4 240.04 0.965 67.4 253.96 0.9875 67.5 268 1.01 67.4 281.96 1.01 67.32 295.76 1.01 67.346 309.65 1.01 67.4 323.56 1.01 67.308 337.5 0.9875 67.32 351.24 0.9875 67.333 365.12 0.97625 67.346 379.35 0.965 67.4 393.04 0.965 67.4 407.04 0.95375

Image Analyst
Image Analyst on 21 May 2024
Edited: Image Analyst on 21 May 2024
See my thermal image demo in my File Exchange. I do essentially this but for a thermal image with a colorbar.
It's a generic, general purpose demo that lets you locate the color bar interactively, then converts the RGB image into an image where the pixel value is the actual underlying pixel value corresponding to the colors.

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!