Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Imwrite with colormap

Subject: Imwrite with colormap

From: Nicolás

Date: 19 Oct, 2012 09:25:08

Message: 1 of 5

Good morning.

I am trying to use imwrite to save a image with a colormap( for example, 'jet'), and with a value of 25 levels, such as this:

imwrite(handles.image,handles.colorMap,filename,pathname);

However, the image is not saved with the value of levels established previously. Thus the image is saved with a value of 256 leves, instead of 25.

Anyone knows do it?

Thanks in advance.

Subject: Imwrite with colormap

From: Steve Eddins

Date: 19 Oct, 2012 11:58:10

Message: 2 of 5

On 10/19/2012 5:25 AM, Nicolás wrote:
> Good morning.
> I am trying to use imwrite to save a image with a colormap( for example,
> 'jet'), and with a value of 25 levels, such as this:
> imwrite(handles.image,handles.colorMap,filename,pathname);
>
> However, the image is not saved with the value of levels established
> previously. Thus the image is saved with a value of 256 leves, instead
> of 25.
>
> Anyone knows do it?
> Thanks in advance.

The same question came in from a MathWorks training engineer this week.

You didn't say what file format you are using, but I'll assume you are
writing a TIFF file.

In the TIFF file format spec, it says that the number of colors in the
colormap is 2^n, where n is the number of bits per sample. (For
details, see section 5, "Palette-color images," of the TIFF spec.
http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf)

So it is not possible to make a TIFF file that has a colormap with only
25 colors in it.

--
Steve Eddins
http://blogs.mathworks.com/steve/

Subject: Imwrite with colormap

From: Nicolás

Date: 19 Oct, 2012 15:08:09

Message: 3 of 5

"Steve Eddins" wrote in message <k5rf8i$nuh$1@newscl01ah.mathworks.com>...
> On 10/19/2012 5:25 AM, Nicolás wrote:
> > Good morning.
> > I am trying to use imwrite to save a image with a colormap( for example,
> > 'jet'), and with a value of 25 levels, such as this:
> > imwrite(handles.image,handles.colorMap,filename,pathname);
> >
> > However, the image is not saved with the value of levels established
> > previously. Thus the image is saved with a value of 256 leves, instead
> > of 25.
> >
> > Anyone knows do it?
> > Thanks in advance.
>
> The same question came in from a MathWorks training engineer this week.
>
> You didn't say what file format you are using, but I'll assume you are
> writing a TIFF file.
>
> In the TIFF file format spec, it says that the number of colors in the
> colormap is 2^n, where n is the number of bits per sample. (For
> details, see section 5, "Palette-color images," of the TIFF spec.
> http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf)
>
> So it is not possible to make a TIFF file that has a colormap with only
> 25 colors in it.
>
> --
> Steve Eddins
> http://blogs.mathworks.com/steve/


Sorry, but the file format can be jpeg,jpeg 2000,gif,etc,etc, in summary those supported by Matlab.
And another thing. I don't want to save the level of color. What I want to save is the level of intensitiy. When you have a image, you have from 0 to 255 levels of intensity. I want to modify the colormap of the image and then, modifying the level of intensity.

I hope now it is more clear the question.

Thanks you a lot !

Subject: Imwrite with colormap

From: Steve Eddins

Date: 19 Oct, 2012 15:37:50

Message: 4 of 5

On 10/19/2012 11:08 AM, Nicolás wrote:
> "Steve Eddins" wrote in message <k5rf8i$nuh$1@newscl01ah.mathworks.com>...
>> On 10/19/2012 5:25 AM, Nicolás wrote:
>> > Good morning.
>> > I am trying to use imwrite to save a image with a colormap( for
>> example,
>> > 'jet'), and with a value of 25 levels, such as this:
>> > imwrite(handles.image,handles.colorMap,filename,pathname);
>> >
>> > However, the image is not saved with the value of levels established
>> > previously. Thus the image is saved with a value of 256 leves, instead
>> > of 25.
>> >
>> > Anyone knows do it?
>> > Thanks in advance.
>>
>> The same question came in from a MathWorks training engineer this week.
>>
>> You didn't say what file format you are using, but I'll assume you are
>> writing a TIFF file.
>>
>> In the TIFF file format spec, it says that the number of colors in the
>> colormap is 2^n, where n is the number of bits per sample. (For
>> details, see section 5, "Palette-color images," of the TIFF spec.
>> http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf)
>>
>> So it is not possible to make a TIFF file that has a colormap with
>> only 25 colors in it.
>>
>> --
>> Steve Eddins
>> http://blogs.mathworks.com/steve/
>
>
> Sorry, but the file format can be jpeg,jpeg 2000,gif,etc,etc, in summary
> those supported by Matlab.
> And another thing. I don't want to save the level of color. What I want
> to save is the level of intensitiy. When you have a image, you have from
> 0 to 255 levels of intensity. I want to modify the colormap of the image
> and then, modifying the level of intensity.
> I hope now it is more clear the question.
>
> Thanks you a lot !

JPEG files can't store indexed images.

If you want to store the intensity values directly, then don't write an
indexed image with a colormap. For example, write a TIFF file this way:

imwrite(A,'myfilename.tif')

--
Steve Eddins
http://blogs.mathworks.com/steve/

Subject: Imwrite with colormap

From: Nicolás

Date: 19 Oct, 2012 16:29:10

Message: 5 of 5

"Steve Eddins" wrote in message <k5rs4e$fj5$1@newscl01ah.mathworks.com>...
> On 10/19/2012 11:08 AM, Nicolás wrote:
> > "Steve Eddins" wrote in message <k5rf8i$nuh$1@newscl01ah.mathworks.com>...
> >> On 10/19/2012 5:25 AM, Nicolás wrote:
> >> > Good morning.
> >> > I am trying to use imwrite to save a image with a colormap( for
> >> example,
> >> > 'jet'), and with a value of 25 levels, such as this:
> >> > imwrite(handles.image,handles.colorMap,filename,pathname);
> >> >
> >> > However, the image is not saved with the value of levels established
> >> > previously. Thus the image is saved with a value of 256 leves, instead
> >> > of 25.
> >> >
> >> > Anyone knows do it?
> >> > Thanks in advance.
> >>
> >> The same question came in from a MathWorks training engineer this week.
> >>
> >> You didn't say what file format you are using, but I'll assume you are
> >> writing a TIFF file.
> >>
> >> In the TIFF file format spec, it says that the number of colors in the
> >> colormap is 2^n, where n is the number of bits per sample. (For
> >> details, see section 5, "Palette-color images," of the TIFF spec.
> >> http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf)
> >>
> >> So it is not possible to make a TIFF file that has a colormap with
> >> only 25 colors in it.
> >>
> >> --
> >> Steve Eddins
> >> http://blogs.mathworks.com/steve/
> >
> >
> > Sorry, but the file format can be jpeg,jpeg 2000,gif,etc,etc, in summary
> > those supported by Matlab.
> > And another thing. I don't want to save the level of color. What I want
> > to save is the level of intensitiy. When you have a image, you have from
> > 0 to 255 levels of intensity. I want to modify the colormap of the image
> > and then, modifying the level of intensity.
> > I hope now it is more clear the question.
> >
> > Thanks you a lot !
>
> JPEG files can't store indexed images.
>
> If you want to store the intensity values directly, then don't write an
> indexed image with a colormap. For example, write a TIFF file this way:
>
> imwrite(A,'myfilename.tif')
>
> --
> Steve Eddins
> http://blogs.mathworks.com/steve/


Oh my god! You're completely right! I have confirmed this information and it's true.
I have wasted some hours to do an impossible thing. :(

Thanks a lot!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us