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

4 次查看(过去 30 天)
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

回答(2 个)

Image Analyst
Image Analyst 2018-9-7
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 个评论
Walter Roberson
Walter Roberson 2018-9-11
You can use up to uint64 for indexed images. However rgb2ind is limited to 65536 colours.
Walter Roberson
Walter Roberson 2018-9-11
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.

请先登录,再进行评论。


Guillaume
Guillaume 2018-9-10
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

类别

Help CenterFile Exchange 中查找有关 Modify Image Colors 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by