Adjust the color bar of all thermal images to be consistent
14 views (last 30 days)
Show older comments
I want to adjust the color bar of some series of thermal images to be consistent for the convenience of studying the temperature change trend. May I ask what I should do? thank you
Edited: DGM on 2 Nov 2022
Unless you have the underlying thermal data, you're going to have to convert the false-color image back into a grayscale thermal image. In order to do that, you need to extract the colorbar from the image and convert it to a colormap. You'll have to then extract the colorbar limit numbers from the image so that you can know how to scale the data.
At that point, you can take this RGB false color image and convert it to an indexed image and then rescale it into nominal temperature units. It may make sense to crop off the colorbar and other decorations from the image, since they'll be mapped to nonsense temperature values if you don't get rid of them.
You could then either display them on a common scale using the extracted colormap, or you could convert them back to RGB using ind2rgb() and some appropriate scaling.
This would be a good place to start.
Try this for a start:
% start with an image
A = imread('thermal1.bmp');
% extract the colormap from one image
% if the colormap is the same for all images, this can be reused
CT = A(50:270,219:229,:); % extract the colorbar region
CT = permute(mean(CT,2),[1 3 2]); % sample average
CT = unique(CT,'rows','stable'); % discard duplicate rows
CT = CT/255; % assuming input was uint8
CT = flipud(CT);
% somehow extract the numbers from the image
% i don't have any OCR stuff, so i'm just going to do this manually
cblimits = [26.1 32.3];
% crop out the usable part of the image
A = A(32:end,1:200,:);
% now you have one image rescaled into temperature units
Ath = double(rgb2ind(A,CT))/size(CT,1);
Ath = rescale(Ath,cblimits(1),cblimits(2));
% do the same things again for another image
B = imread('thermal2.bmp');
B = B(32:end,1:200,:);
cblimits = [22.3 26.9];
Bth = double(rgb2ind(B,CT))/size(CT,1);
Bth = rescale(Bth,cblimits(1),cblimits(2));
% display both images with a common scale and colormap
displaycbrange = [22 34]; % the common scale
DGM on 3 Nov 2022
Edited: DGM on 3 Nov 2022
What does CT look like?
What does colormap(gca) look like? Are they the same?
If it's an issue of the map not being assigned, you could always be more explicit:
ax1 = subplot(1,2,1);
ax2 = subplot(1,2,2);
... though I don't think it should be necessary.
If you're running an older version, or if you've adapted the code, it would help to know.
More Answers (1)
Hiro Yoshino on 2 Nov 2022
You can control the range of colorbar with clim:
[X,Y] = meshgrid(-5:.5:5);
Z = X.^2 + Y.^2;
% Left plot
ax1 = nexttile;
% Right plot
ax2 = nexttile;
clim(ax2,[20 50]) % fix the color range of ax2
The images are RGB images from a camera. Setting caxis has no effect on the rendering of a truecolor image.
Find more on Modify Image Colors 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!