Help with forming a temperature image using black and white scale?
Show older comments
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
More Answers (2)
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)
% scales data extrema to outrange
T2 = rescale(graypict,outrange(1),outrange(2))
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.
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);
Categories
Find more on Blue in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!