save image with a long colormap

12 views (last 30 days)
aa aa
aa aa on 7 Mar 2015
Answered: Image Analyst on 7 Mar 2015
Hi all,
I'd like to know how to save an image in matlab with colormap. For example, when I write:
imwrite(Matrix,jet,'name.png')
The image is saved with the colormap jet. So far, so good. Now say I want a longer colormap, e.g.: [jet,flipud(jet),0 0 0]. When I type:
imwrite(Matrix,[jet,flipud(jet),0 0 0],'name.png')
It returns an error massage.
Note that when I type:
colormap([jet,flipud(jet),0 0 0])
The figure is displayed with the colormap [jet,flipud(jet),0 0 0], so there's nothing wrong with the colormap. I guess it's "imwrite" that makes the troubles.
Any ideas how to solve that?
Thanks in advance!
P.S. The matrix I want to save doesn't necessarily contain integers. Usually, its elements are of type float or double.

Answers (1)

Image Analyst
Image Analyst on 7 Mar 2015
Color maps can only be 256 rows long. If you want more than that you'll have to use an RGB image, not an indexed one.
To remove a colormap from the displayed image, use a colormap of gray
colormap(gray(256));

Categories

Find more on Color and Styling in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!