How to Apply Jet Colormap to Montage?

16 次查看(过去 30 天)
Hello everyone,
I have been trying to apply the Jet colormap to a set of images (see attached file) to then display them using the function montage. Montage() has an option to input the desired colormap for the images one wants to display. However, I keep getting errors. So, does any of you know how I can display the set of images with the Jet map applied using the montage function?
Thank you in advance for your help. I highly appreciate it.

采纳的回答

DGM
DGM 2023-9-26
编辑:DGM 2023-9-26
There are two places where color tables are used:
  1. indexed color images (direct colormapping)
  2. pseudocolor representations of arbitrarily-scaled data (scaled colormapping)
montage() and imshow() perform #1 when fed a color table. You want #2.
The solution depends on what your data looks like and how you're trying to represent it. You haven't told us how you were doing the mapping, what the errors were, or what the end goal is. If you want each page mapped with respect to its own extrema (as you would with imagesc(), then no, montage() is the wrong tool. If the goal is to produce a composite image and save it, montage() isn't helpful for that either.
Here are two examples.
load QCStimVol.mat
map = jet(256);
% visualize all pages using the same extrema (global)
% imshow()/montage() do scaled mapping when the input is 2D
% the map will be gray() by default, but is otherwise specified externally
% this is equivalent to reshaping the array and displaying it with imshow()
inrange = imrange(QCStimVol); % global extrema
montage(QCStimVol,'displayrange',inrange) % specify the input range
colormap(map) % specify the map
% visualize the pages using their own extrema (local)
% use the attached files to construct the RGB data
nslices = size(QCStimVol,3);
pcolorslices = cell(nslices,1);
for k = 1:nslices
thisslice = QCStimVol(:,:,k);
inrange = imrange(thisslice); % local extrema
pcolorslices{k} = gray2pcolor(thisslice,map,inrange,'cdscale');
end
montage(pcolorslices)
In either case, montage() is a visualization tool, not a composition tool. If you want to actually save the resulting image, use imtile() and imwrite(), not montage(). If this is the goal, then both global and local mapping would need to be done similar to the second example, since imtile() cannot generate the pseudocolor image by itself.
% global mapping
nslices = size(QCStimVol,3);
pcolorslices = cell(nslices,1);
inrange = imrange(QCStimVol); % global extrema
for k = 1:nslices
thisslice = QCStimVol(:,:,k);
pcolorslices{k} = gray2pcolor(thisslice,map,inrange,'cdscale');
end
outpict = imtile(pcolorslices); % build the composite image
imwrite(outpict,'global.png') % save it
% local mapping
nslices = size(QCStimVol,3);
pcolorslices = cell(nslices,1);
for k = 1:nslices
thisslice = QCStimVol(:,:,k);
inrange = imrange(thisslice); % local extrema
pcolorslices{k} = gray2pcolor(thisslice,map,inrange,'cdscale');
end
outpict = imtile(pcolorslices); % build the composite image
imwrite(outpict,'local.png') % save it
  1 个评论
Miguel
Miguel 2023-9-29
DGM thank very much for your thorough and clear explanation. This all makes sense to me and works perfectly well. Have a good day!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Red 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by