# Adjust the color bar of all thermal images to be consistent

21 vues (au cours des 30 derniers jours)
wenze le 2 Nov 2022
Modifié(e) : DGM le 3 Nov 2022
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
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

DGM le 2 Nov 2022
Modifié(e) : DGM le 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.
EDIT:
Try this for a start:
% 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));
imshow(Ath,[])
% do the same things again for another image
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
subplot(1,2,1)
imshow(Ath,displaycbrange)
colormap(CT)
colorbar
subplot(1,2,2)
imshow(Bth,displaycbrange)
colormap(CT)
colorbar
##### 2 commentairesAfficher AucuneMasquer Aucune
wenze le 3 Nov 2022
Modifié(e) : Image Analyst le 3 Nov 2022
DGM le 3 Nov 2022
Modifié(e) : DGM le 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);
imshow(Ath,displaycbrange,'parent',ax1)
colormap(ax1,CT)
colorbar(ax1)
ax2 = subplot(1,2,2);
imshow(Bth,displaycbrange,'parent',ax2)
colormap(ax2,CT)
colorbar(ax2)
... 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.

Connectez-vous pour commenter.

### Plus de réponses (1)

Hiro Yoshino le 2 Nov 2022
You can control the range of colorbar with clim:
[X,Y] = meshgrid(-5:.5:5);
Z = X.^2 + Y.^2;
tiledlayout(1,2)
% Left plot
ax1 = nexttile;
surf(ax1,Z);
colorbar
% Right plot
ax2 = nexttile;
surf(ax2,Z);
colorbar
clim(ax2,[20 50]) % fix the color range of ax2
##### 3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Hiro Yoshino le 2 Nov 2022
clim was introduced in R2020a, which was renamed from caxis.
Please try caxis with reference to the function in the old documentations (here).
DGM le 2 Nov 2022
The images are RGB images from a camera. Setting caxis has no effect on the rendering of a truecolor image.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Red dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by