Change the hot colormap so that the default value of 1 is white
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Matthew Kehoe
am 24 Aug. 2021
Kommentiert: Image Analyst
am 25 Aug. 2021
Inside my Matlab code I am using the hot colormap in order to produce plots of the calculated reflectivity.
Example 1: Subset of the reflectivity map. The hot colormap seems to set the color of the value 1 at random (in this case, it is orange).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/720219/image.png)
Example 2: Another subset of the reflectivity map. Now 1 is yellow instead of orange.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/720224/image.png)
How can I change my Matlab code so that the value of R=1 is always set to the white color inside the colorbar and the colormap? My current code calls the colorbar and colormap by
% do a bunch of calculations
figure(1);
colorbar; colormap hot;
% I don't specify additional code to adjust the hot colorbar or colormap
Can I adjust this code so that R=1 is white by default?
2 Kommentare
Akzeptierte Antwort
David Goodmanson
am 25 Aug. 2021
Hi Matthew,
The 'hot' colormap has white at one end of its scale and almost-black at the other. Suppose you successfully change things so that R=1 is white. What do you want to happen for values of R that are greater than 1, which occur in both plots?
If you are ok with all values of R >=1 mapping to white, then using the line
caxis([Rmin 1])
just after the plot command does so, where Rmin is the minimum value of R over the entire set of x,y values.
2 Kommentare
Image Analyst
am 25 Aug. 2021
@Matthew Kehoe, my code below can easily be modified to have all values above 1 be white (instead of only the value that's closest to 1 be white) if that's what you want.
Weitere Antworten (1)
Image Analyst
am 25 Aug. 2021
To make any part of any colormap white, set the 3 values to 1:
grayImage = 1.5 * im2double(imread('cameraman.tif'));
% See what we get with default colormap.
myCustomColormap = hot(256);
subplot(1, 2, 1);
imshow(grayImage, [], 'ColorMap', myCustomColormap)
colorbar;
colorBarLimits = caxis
% Find rows where value = 1
rowFor1 = round(interp1(colorBarLimits, [1, size(myCustomColormap, 1)], 1.0))
% Make that row of the colormap white:
myCustomColormap(rowFor1, :) = 1;
% See what we get with changed colormap.
subplot(1, 2, 2);
imshow(grayImage, [], 'ColorMap', myCustomColormap)
colorbar;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/720554/image.png)
Note that the image values go from 0 to 1.5 and I used a hot colormap, but I found out what row of the color map corresponds to a gray level of 1 and I set that row of the colormap to white (all 1's). See the white line in the colorbar on the right and how some of the pixels in the image on the right are now white where they used to be orange.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Blue finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!