How to display indexed images from .mat file using colormap?

5 views (last 30 days)
I have a vector matrix 'X' which contains 700 indexed images. I want to display some of images on grid. For displaying purpose I am using a function displayData which is meant for grayscale images. How can I display indexed images ? I am using following displayData function. https://github.com/aptiva0985/MachineLearning-Andrew-Ng-Coursera-/blob/master/ML003/mlclass-ex3/displayData.m

Answers (2)

Image Analyst
Image Analyst on 7 Sep 2018
Try using imshow() and colormap().
What is X? A vector matrix sounds contradictory. Do have a 1-D array of 700 cells, where inside each cell is one indexed image?
By the way, a gray scale image can be considered an indexed image - you just apply a colormap to it just like you do to any indexed image.
  19 Comments
Walter Roberson
Walter Roberson on 11 Sep 2018
You can use up to uint64 for indexed images. However rgb2ind is limited to 65536 colours.
Walter Roberson
Walter Roberson on 11 Sep 2018
It would be completely valid for rgb2ind to return different color indices for any given color for two images that are exactly the same except one is the upside down of the other. There is no inherent ordering of the colors. For the same image in different rotations then the same colors should be found, but the index order is not fixed by the algorithm.

Sign in to comment.


Guillaume
Guillaume on 10 Sep 2018
Having looked at the code for your displayData, it is not possible to use it with indexed images with different colour maps without a major rewrite. That function builds a single matrix out of all the images so whatever colour map you'd use would always apply to all images.
The simplest way to do what you want would be to use subplot and imshow to let matlab build the grid of images. The one downside with that is that by default matlab leaves a lot of spacing between the subplots. The code to be a 5x10 array of images would be something like:
%inputs:
%clothingimages: a cell array of images
%colourmaps: a cell array of colourmaps
imgindex = 1;
figure;
for row = 1:5
for col = 1:10
subplot(5, 10, imgindex);
imshow(clothingimages{imgindex}, colourmaps{imgindex});
imgindex = imgindex + 1;
end
end

Community Treasure Hunt

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

Start Hunting!