Help with forming a temperature image using black and white scale?

6 views (last 30 days)
I need to form a temperature image by assigning a black and white (thermal greyscale image) scale to a temperature scale - so by matching max/min temperatures to 255/0 values respectively, e.g. min temp 7 = 0 and max temp 42 = 255 (or 1 if this is easier going forwards?). Just wondering if someone can point me in the right direction of how to put this into code as simply as possible please? The reason for doing so is to use the temperature image data in a 2D plot.

Accepted Answer

Image Analyst
Image Analyst on 6 Feb 2022
Edited: Image Analyst on 6 Feb 2022
If your matrix has values going from 0 to 255 and you want temperature values of 7 to 42 you can do this:
temperatureMatrix = rescale(grayLevelMatrix, 7, 42);
It's not just 0 and 255. It will put whatever the min is to 7 and whatever the max is to 42.
If your matrix has values going from 7 to 42 and you want gray levels of 0 to 255 you can do this:
grayLevelMatrix = rescale(temperatureMatrix, 0, 255);
If all you have is a pseudocolor image with a colorbar, you can adapt the attached demo.
  4 Comments
Image Analyst
Image Analyst on 6 Feb 2022
I hope you know about emissivity. Maybe the emissivity of trees and grass might be similar. Not sure about the sky so the temp might not be comparable. Also you need to know the emissitivy that your camera was set to. If it was set to the wrong value, the temperatures won't be accurate.
Image Analyst
Image Analyst on 12 Feb 2022
Looks like you're trying to build a visualization of two images taken of a scene
  1. The thermal (gray scale, infrared, temperature) image
  2. The visible color image which has been converted to HSV color space.
I'm not really sure from the plot which data points you want to extract and which you want to discard. You can try thresholding if you think slicing off slabs from that thing might reveal what you want. If there's other stuff in there and thresholding can't reveal it, you'd have to somehow define the data points you want to extract or discard. Maybe start a new question with the thermal (gray scale) temperature image, and the RGB image both attached and say what in the image you want to visualize in that 3-D scatterplot.

Sign in to comment.

More Answers (2)

DGM
DGM on 6 Feb 2022
If you know what the exact relationship is between gray levels and temperatures (and you can presume that it's linear), why not just scale based on those knowns?
inrange = [0 255];
outrange = [7 42];
graypict = [10 250]; % pretend this is our very small image (does not span inrange)
% scales inrange to outrange
T1 = range(outrange)*(double(graypict)-inrange(1))/range(inrange) + outrange(1)
T1 = 1×2
8.3725 41.3137
% scales data extrema to outrange
T2 = rescale(graypict,outrange(1),outrange(2))
T2 = 1×2
7 42
This will result in the same scaling regardless of whether the image data spans the entire input range. This will be different than the results from rescale(), which will map the input extrema to [7 42], regardless of what they actually are. You need to decide whether that suits your needs. If you can guarantee that your data range always spans [0 255], then the two methods will be the same.

yanqi liu
yanqi liu on 7 Feb 2022
yes,sir,may be use colormap to get image,such as
a = randi([7 42], 64, 1);
a = repmat(a, 1, 64);
map = linspace(0, 255, 64);
map = repmat(map(:), 1, 3);
figure; imagesc(a);colormap(map/255);

Community Treasure Hunt

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

Start Hunting!