Change the hot colormap so that the default value of 1 is white
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Matthew Kehoe
il 24 Ago 2021
Commentato: Image Analyst
il 25 Ago 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 Commenti
Risposta accettata
David Goodmanson
il 25 Ago 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 Commenti
Image Analyst
il 25 Ago 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.
Più risposte (1)
Image Analyst
il 25 Ago 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 Commenti
Vedere anche
Categorie
Scopri di più su Blue in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!