Change the hot colormap so that the default value of 1 is white

9 visualizaciones (últimos 30 días)
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).
Example 2: Another subset of the reflectivity map. Now 1 is yellow instead of orange.
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?

Respuesta aceptada

David Goodmanson
David Goodmanson el 25 de Ag. de 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 comentarios
Matthew Kehoe
Matthew Kehoe el 25 de Ag. de 2021
Hello David. Thanks for your answer - I don't think there is a better option for R values >=1. My program will produce R values slightly bigger than 1. However, I don't think these will go above 1.1 or perhaps 1.2 (unless I send in bad parameter data). One solution is to make the maximum of the caxis one as written above. I don't see a viable alternative since
caxis([Rmin 1.2])
would make R == 1.2 white instead of R == 1.0.
Image Analyst
Image Analyst el 25 de Ag. de 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.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 25 de Ag. de 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;
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.

Categorías

Más información sobre Red en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by