Clear Filters
Clear Filters

How to Apply Jet Colormap to Montage?

16 views (last 30 days)
Miguel
Miguel on 26 Sep 2023
Commented: Miguel on 29 Sep 2023
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.

Accepted Answer

DGM
DGM on 26 Sep 2023
Edited: DGM on 26 Sep 2023
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 Comment
Miguel
Miguel on 29 Sep 2023
DGM thank very much for your thorough and clear explanation. This all makes sense to me and works perfectly well. Have a good day!

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!