Borrar filtros
Borrar filtros

Using imagesc to plot two matrices on top of each other with different colormaps?

4 visualizaciones (últimos 30 días)
I have two images:
orgImage, which is a 1298x320 matrix of values that I wish to show in gray scale.
And
ChemMap, which is a 1298x320 matrix where a majority of the elements are NaNs, but some of which are values that I want to plot on top of orgImage with a colormap such as jet for example.
Plotting these on top of each other should be the simplest thing in the world but I have literally been trying for hours to get it the way I want it to but it doesn’t work.
First I was hoping to be able to start by plotting image number one like:
imagesc(orgImage), colormap('gray'),axis equal, hold on
and then add the other one on top;
imagesc(ChemMap), colormap('jet')
But that doesn’t work since the NaN’s are still plotted on the image but as the lowest possible value of the jet colormap.
I’ve tried plotting the images on different axis as suggested here: https://se.mathworks.com/matlabcentral/answers/101346-how-do-i-use-multiple-colormaps-in-a-single-figure
and I’ve tried messing around with the freezeColors routine on fileexchange but I can’t quite get it to work which is overwhelmingly frustrating.
Does anyone know how I can make the NaN’s transparent in imagesc(ChemMap) so I can plot these images on top of each other?
Thanks.

Respuesta aceptada

Thorsten
Thorsten el 16 de Ag. de 2016
Editada: Thorsten el 16 de Ag. de 2016
This is a bit tricky, because you need two colormaps combined in a single colormap and scale the values in one image to match the second colormap. The code below works if you have scaled the values in your images to the range 1,256.
Fake some data:
Ncolors = 256;
orgImage = randi(Ncolors, 10);
ChemMap = randi(Ncolors, 10); ChemMap(ChemMap > 128) = NaN; ChemMap = 2*ChemMap;
Define your color map
cmap = [gray(Ncolors); jet(Ncolors)];
colormap(cmap)
Combine both images and scale the values to the right indices in the new colormap
I = Ncolors + ChemMap;
ind = isnan(I);
I(ind) = orgImage(ind);
imagesc(I)
  1 comentario
Peta
Peta el 16 de Ag. de 2016
Not 100% ideal and pretty, but I guess it sort of did what I was trying to do. Thank you for your help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by