Thread Subject: Getting only single-colored images from a TIF-file with imread

Subject: Getting only single-colored images from a TIF-file with imread

From: Ralf

Date: 6 Oct, 2009 07:58:25

Message: 1 of 5

Hello all,

I'm getting strange results when opening a TIFF-file with imread.
Opening the same picture as a JPEG-file, when it had been converted
externally, it is no problem but the result is not usable for me
because too much information is lost due to storage in JPEG even if
choosing no compression. Resaving the picture with an external program
as TIFF does not help, too.

After performing RGB=imread('test.tif') I get the following values in
RGB (showing a small section). RGB is only a n x n x 1 matrix,
although it should be n x n x 3, which means that somehow no colormap
is imported. If I change the standard colormap, it is possible to see
the picture with image(RGB), but only with a one-color-based picture.
With the standard colormap, it is just black. Do you have any hints?

Thank you,
Ralf

***************************************
RGB=imread('test.tif');
size(RGB)
ans =

         802 1024
RGB(1:10,1:10)

ans =

   20 20 20 20 20 20 20 20 20 20
   20 20 20 20 20 20 20 20 20 20
   20 20 13 13 13 13 13 13 13 13
   20 20 13 13 13 13 13 13 13 13
   20 20 13 13 13 13 13 13 13 13
   20 20 13 13 13 13 13 13 13 13
   20 20 13 13 13 13 13 13 13 13
   20 20 13 13 13 13 13 13 13 13
   20 20 13 13 13 13 13 13 13 13
   20 20 13 13 13 13 13 13 13 13

*****************************

imfinfo gives the following result:

                     Filename: 'test.tif'
                  FileModDate: '06-Jun-2007 13:08:12'
                     FileSize: 183092
                       Format: 'tif'
                FormatVersion: []
                        Width: 1024
                       Height: 802
                     BitDepth: 8
                    ColorType: 'indexed'
              FormatSignature: [77 77 0 42]
                    ByteOrder: 'big-endian'
               NewSubFileType: 0
                BitsPerSample: 8
                  Compression: 'LZW'
    PhotometricInterpretation: 'RGB Palette'
                 StripOffsets: [101x1 double]
              SamplesPerPixel: 1
                 RowsPerStrip: 8
              StripByteCounts: [101x1 double]
                  XResolution: []
                  YResolution: []
               ResolutionUnit: 'Inch'
                     Colormap: [256x3 double]
          PlanarConfiguration: 'Chunky'
                    TileWidth: []
                   TileLength: []
                  TileOffsets: []
               TileByteCounts: []
                  Orientation: 1
                    FillOrder: 1
             GrayResponseUnit: 0.0100
               MaxSampleValue: 255
               MinSampleValue: 0
                 Thresholding: 1
             ImageDescription: 'converted PNM file'

Subject: Getting only single-colored images from a TIF-file with imread

From: ImageAnalyst

Date: 6 Oct, 2009 10:49:20

Message: 2 of 5

Any hints on what? You've saved the data as a monochrome image.
What's the issue?

Subject: Getting only single-colored images from a TIF-file with imread

From: Ralf

Date: 6 Oct, 2009 12:01:49

Message: 3 of 5

Hi,

it is definitively no monochrome image. I should add, that opening the
image with standard software correctly shows the color imaga. And
after converting to JPEG the matrix storing the image consists of the
RGB data as it should be.
RGB=imread('test.jpg');
size(RGB)

ans =

         802 1024 3

 It must be some problem in reading the colormap, which is [256x3
double] .according to imfinfo.

Ralf

On 6 Okt., 12:49, ImageAnalyst <imageanal...@mailinator.com> wrote:
> Any hints on what? You've saved the data as a monochrome image.
> What's the issue?

Subject: Getting only single-colored images from a TIF-file with imread

From: Steve Eddins

Date: 6 Oct, 2009 12:21:25

Message: 4 of 5

Ralf wrote:
> Hello all,
>
> I'm getting strange results when opening a TIFF-file with imread.
> Opening the same picture as a JPEG-file, when it had been converted
> externally, it is no problem but the result is not usable for me
> because too much information is lost due to storage in JPEG even if
> choosing no compression. Resaving the picture with an external program
> as TIFF does not help, too.
>
> After performing RGB=imread('test.tif') I get the following values in
> RGB (showing a small section). RGB is only a n x n x 1 matrix,
> although it should be n x n x 3, which means that somehow no colormap
> is imported. If I change the standard colormap, it is possible to see
> the picture with image(RGB), but only with a one-color-based picture.
> With the standard colormap, it is just black. Do you have any hints?
>
> Thank you,
> Ralf
>
> ***************************************
> RGB=imread('test.tif');
> size(RGB)
> ans =
>
> 802 1024
> RGB(1:10,1:10)
>
> ans =
>
> 20 20 20 20 20 20 20 20 20 20
> 20 20 20 20 20 20 20 20 20 20
> 20 20 13 13 13 13 13 13 13 13
> 20 20 13 13 13 13 13 13 13 13
> 20 20 13 13 13 13 13 13 13 13
> 20 20 13 13 13 13 13 13 13 13
> 20 20 13 13 13 13 13 13 13 13
> 20 20 13 13 13 13 13 13 13 13
> 20 20 13 13 13 13 13 13 13 13
> 20 20 13 13 13 13 13 13 13 13
>
> *****************************
>
> imfinfo gives the following result:
>
> Filename: 'test.tif'
> FileModDate: '06-Jun-2007 13:08:12'
> FileSize: 183092
> Format: 'tif'
> FormatVersion: []
> Width: 1024
> Height: 802
> BitDepth: 8
> ColorType: 'indexed'
> FormatSignature: [77 77 0 42]
> ByteOrder: 'big-endian'
> NewSubFileType: 0
> BitsPerSample: 8
> Compression: 'LZW'
> PhotometricInterpretation: 'RGB Palette'
> StripOffsets: [101x1 double]
> SamplesPerPixel: 1
> RowsPerStrip: 8
> StripByteCounts: [101x1 double]
> XResolution: []
> YResolution: []
> ResolutionUnit: 'Inch'
> Colormap: [256x3 double]
> PlanarConfiguration: 'Chunky'
> TileWidth: []
> TileLength: []
> TileOffsets: []
> TileByteCounts: []
> Orientation: 1
> FillOrder: 1
> GrayResponseUnit: 0.0100
> MaxSampleValue: 255
> MinSampleValue: 0
> Thresholding: 1
> ImageDescription: 'converted PNM file'

Your color image is stored in indexed form, not truecolor form. (See
the ColorType field in the output of imfinfo.) That means you need to
call imread with two output arguments in order to get the colormap.

[X,map] = imread('test.tif');
image(X)
colormap(map)

JPEG doesn't support indexed image storage, so your external program
converted the image from indexed to truecolor form in order to store it
as a JPEG. That's why you got an M-by-N-by-3 array when you read in the
converted JPEG file.

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

Subject: Getting only single-colored images from a TIF-file with imread

From: Ralf

Date: 6 Oct, 2009 12:55:05

Message: 5 of 5

Hi Steve,

this is the solution. Now it works perfectly.

Thank you very much,
Ralf

On 6 Okt., 14:21, Steve Eddins <Steve.Edd...@mathworks.com> wrote:
> Ralf wrote:
> > Hello all,
>
> > I'm getting strange results when opening a TIFF-file with imread.
> > Opening the same picture as a JPEG-file, when it had been converted
> > externally, it is no problem but the result is not usable for me
> > because too much information is lost due to storage in JPEG even if
> > choosing no compression. Resaving the picture with an external program
> > as TIFF does not help, too.
>
> > After performing RGB=imread('test.tif') I get the following values in
> > RGB (showing a small section). RGB is only a n x n x 1 matrix,
> > although it should be n x n x 3, which means that somehow no colormap
> > is imported. If I change the standard colormap, it is possible to see
> > the picture with image(RGB), but only with a one-color-based picture.
> > With the standard colormap, it is just black. Do you have any hints?
>
> > Thank you,
> > Ralf
>
> > ***************************************
> > RGB=imread('test.tif');
> > size(RGB)
> > ans =
>
> > 802 1024
> > RGB(1:10,1:10)
>
> > ans =
>
> > 20 20 20 20 20 20 20 20 20 20
> > 20 20 20 20 20 20 20 20 20 20
> > 20 20 13 13 13 13 13 13 13 13
> > 20 20 13 13 13 13 13 13 13 13
> > 20 20 13 13 13 13 13 13 13 13
> > 20 20 13 13 13 13 13 13 13 13
> > 20 20 13 13 13 13 13 13 13 13
> > 20 20 13 13 13 13 13 13 13 13
> > 20 20 13 13 13 13 13 13 13 13
> > 20 20 13 13 13 13 13 13 13 13
>
> > *****************************
>
> > imfinfo gives the following result:
>
> > Filename: 'test.tif'
> > FileModDate: '06-Jun-2007 13:08:12'
> > FileSize: 183092
> > Format: 'tif'
> > FormatVersion: []
> > Width: 1024
> > Height: 802
> > BitDepth: 8
> > ColorType: 'indexed'
> > FormatSignature: [77 77 0 42]
> > ByteOrder: 'big-endian'
> > NewSubFileType: 0
> > BitsPerSample: 8
> > Compression: 'LZW'
> > PhotometricInterpretation: 'RGB Palette'
> > StripOffsets: [101x1 double]
> > SamplesPerPixel: 1
> > RowsPerStrip: 8
> > StripByteCounts: [101x1 double]
> > XResolution: []
> > YResolution: []
> > ResolutionUnit: 'Inch'
> > Colormap: [256x3 double]
> > PlanarConfiguration: 'Chunky'
> > TileWidth: []
> > TileLength: []
> > TileOffsets: []
> > TileByteCounts: []
> > Orientation: 1
> > FillOrder: 1
> > GrayResponseUnit: 0.0100
> > MaxSampleValue: 255
> > MinSampleValue: 0
> > Thresholding: 1
> > ImageDescription: 'converted PNM file'
>
> Your color image is stored in indexed form, not truecolor form. (See
> the ColorType field in the output of imfinfo.) That means you need to
> call imread with two output arguments in order to get the colormap.
>
> [X,map] = imread('test.tif');
> image(X)
> colormap(map)
>
> JPEG doesn't support indexed image storage, so your external program
> converted the image from indexed to truecolor form in order to store it
> as a JPEG. That's why you got an M-by-N-by-3 array when you read in the
> converted JPEG file.
>
> ---
> Steve Eddinshttp://blogs.mathworks.com/steve/

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com