How can I change the colormap of an image?

조회 수: 114 (최근 30일)
BGranato
BGranato 2018년 8월 16일
댓글: BGranato 2018년 8월 20일
I have an image I saved with the pink colormap and I would like to display it with jet. How can I do that?
The way I managed to do it seems like a really round about way:
I = imread('myimage.png');
I = ind2rgb(rgb2gray(I),jet);
imshow(I)
  댓글 수: 12
BGranato
BGranato 2018년 8월 17일
Great, thank you! I found it on here somewhere, you guys are great! :)
Long story short, I saved thousands of images with pink but then realized some of the features are difficult to see, at least for some of the photos. So I wanted to change it to something else (jet) when I use imshow without having to re-do the whole extraction and saving process.
BGranato
BGranato 2018년 8월 20일
Thank you everyone!

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2018년 8월 16일
Try this:
[indexedImage, pinkMap] = imread('myimage.png');
imshow(indexedImage);
colormap(gca, jet(256)); % Ignore pink map and use jet instead.
colorbar(gca);
  댓글 수: 2
BGranato
BGranato 2018년 8월 16일
It didn't work, unfortunately, the image still appears as pink.
Image Analyst
Image Analyst 2018년 8월 17일
As long as you saved the gray scale image and the colormap, you can simply recall the grayscale image and use a different colormap when displaying, basically using the gray levels as indexes. This is preferred because gray levels are ordered in units of increasing intensity, whereas arbitrary indexes are not in any kind of order with intensity. This is the preferred way and what I'd hoped you did in my answer.
If you, unfortunately, got an indexed image from an RGB image by calling rgb2ind(rgbImage, pink) then those indexes are probably unique/special to the pink colormap and you can't simply use a different colormap with that same indexed image because they don't have any special ordering with respect to gray level intensity. To illustrate, just call imshow(), colormap(gray(256)), and colorbar() and check out the colorbar - you will see it's basically a bunch of random gray colors because they are not ordered. You'd have to get back to the original rgb image by using ind2rgb(indexedImage, pink) and then convert to grayscale with rgb2gray(). Once it's in grayscale, you can then use any other colormap you want, like jet.
I hope that explains it better.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Orange에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by