Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Read multichannel .tiff image

156 views
Skip to first unread message

megha bhatt

unread,
Aug 10, 2009, 11:23:04 AM8/10/09
to
Hi,
I have a file with 6o channels in it and I want to read it in MATLAB. I tried using imread and imshow but its giving me error message that :
" RGB image has 60 (not 3) samples per pixel"
Can you please tell me the way to import this kind of image files in MATLAB?

Many thanks in advance.
Megha

megha bhatt

unread,
Aug 10, 2009, 12:39:02 PM8/10/09
to
"megha bhatt" <mubh...@yahoo.co.in> wrote in message <h5pe0o$ilj$1...@fred.mathworks.com>...

I mean I want to read a multi-channel image (.tiff format) and want to display it!! How to do it??

ImageAnalyst

unread,
Aug 10, 2009, 9:28:54 PM8/10/09
to
On Aug 10, 12:39 pm, "megha bhatt" <mubhat...@yahoo.co.in> wrote:
> "megha bhatt" <mubhat...@yahoo.co.in> wrote in message <h5pe0o$il...@fred.mathworks.com>...

> > Hi,
> > I have a file with 6o channels in it and I want to read it in MATLAB. I tried using imread and imshow but its giving me error message that :
> > " RGB image has 60 (not 3) samples per pixel"
> > Can you please tell me the way to import this kind of image files in MATLAB?
>
> > Many thanks in advance.
> > Megha
>
> I mean I want to read a multi-channel image (.tiff format) and want to display it!! How to do it??

---------------------------------------------------------------------------
Show us your call to imread. imread claims that it can handle multi-
page, multi-spectral images, so you're probably calling it wrong (with
parameters out of range). Did you specify the correct bit depth?
What bit depth? 480? It says it will handle up to 64 bit, so that is
8 channels at 8 bits per channel. If you have 60 channels, that is
more than 8 and you'll need to write your own or find someone who can
handle 60 channels because 60*8 =480 bits which is more than the 64
bits that imread can handle.

megha bhatt

unread,
Aug 12, 2009, 9:49:19 AM8/12/09
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <b2ba6767-4fe9-49ed...@v2g2000vbb.googlegroups.com>...
Hi,
Thanks for your reply.

I am calling the function as follows:

[X,map] = imread('ap15-reflec-60b.tif');

and its giving me error :

Warning: RGB image has 60 (not 3) samples per pixel.
??? Unsupported bit-depth for RGB TIFF image file.

Error in ==> imagesci\private\readtif at 32
[X, map, details] = rtifc(filename, args.index);

Error in ==> imread at 308
[X, map] = feval(fmt_s.read, filename, extraArgs{:});

I also tried to open only one channel by writting :
[X,map] = imread('ap15-reflec-60b.tif', 1);
but again I get the same warning!!

I used the following call to know the details of file :
imfinfo('ap15-reflec-60b.tif')

its giving me following description about the file :

Filename: 'ap15-reflec-60b.tif'
FileModDate: '10-Aug-2009 16:11:10'
FileSize: 65058010
Format: 'tif'
FormatVersion: []
Width: 342
Height: 788
BitDepth: 1920
ColorType: 'truecolor'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubfileType: 0
BitsPerSample: [1x60 double]
Compression: 'Uncompressed'
PhotometricInterpretation: 'RGB'
StripOffsets: [47280x1 double]
SamplesPerPixel: 60
RowsPerStrip: 1
StripByteCounts: [47280x1 double]
XResolution: 100
YResolution: 100
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Planar'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: [1x60 double]
MinSampleValue: 0
Thresholding: 1
NewSubFileType: 0
SampleFormat: {60x1 cell}


I am sure I can not open the image at once using "imread" but I am not getting how to do it in loop because even if I just give one channel its giving me the same warning as written above.

Please help, my work is stuck because of this problem.

Best regards,
Megha

Steve Eddins

unread,
Aug 12, 2009, 10:31:14 AM8/12/09
to

A bit of TIFF terminology ... Your file contains only one image. It is
an image that contains 60 samples per pixel.

I believe that recent MATLAB versions should be able to read this file.
What version of MATLAB are you using?

However, imread does NOT support reading a subset of the samples per
pixel for a given image. It will read them all, so you'll get a
788-by-342-by-60 image.

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

megha bhatt

unread,
Aug 12, 2009, 11:04:19 AM8/12/09
to
Steve Eddins <Steve....@mathworks.com> wrote in message <h5ujni$pab$1...@fred.mathworks.com>...

I am using MATLAB version 7.0.4.365(R14) service pack.
If imread doesn't support reading this kind of file what is another way to read this file??

Ashish Uthama

unread,
Aug 12, 2009, 11:14:28 AM8/12/09
to

Could you show us the contents of 'SampleFormat' in the above?

megha bhatt

unread,
Aug 12, 2009, 11:46:05 AM8/12/09
to
"Ashish Uthama" <first...@mathworks.com> wrote in message <op.uyj1y...@uthamaa.dhcp.mathworks.com>...

Its 'IEEE floating point' and same for all 60 cells. Please let me know how to read this file?

Steve Eddins

unread,
Aug 12, 2009, 12:08:40 PM8/12/09
to
megha bhatt wrote:
> [snip]

>
> I am using MATLAB version 7.0.4.365(R14) service pack.
> If imread doesn't support reading this kind of file what is another way to read this file??

You'll need to upgrade your MATLAB in order to read the file with imread.

I don't know what other application to suggest. 60 samples per pixel is
fairly unusual, even for TIFF.

If you feel up to writing your own MATLAB code, you can read in your
data using the MATLAB functions fopen, fseek, and fread. This is
feasible because (according to imfinfo) the file is uncompressed. The
StripOffsets field of the output of imfinfo tells you where each row of
your image is stored. If you fseek to the beginning of a row, the next
342 single-precision floats in the file are the first channel, followed
by another 342 single-precision floats for the second channel, and so on.

Ashish Uthama

unread,
Aug 12, 2009, 12:11:51 PM8/12/09
to
On Wed, 12 Aug 2009 11:04:19 -0400, megha bhatt <mubh...@yahoo.co.in>
wrote:

IMREAD in R14 did not have this capability.
The earliest version of MATLAB that would be able to read in this file is
R2007b.

If upgrading the MATLAB version is not an option, you could look at other
software to convert this file to something (multiple 3 samples/pixel tiff
files) that your version can read. It might be tedious to find a tool
which does this though.

megha bhatt

unread,
Aug 12, 2009, 1:09:19 PM8/12/09
to
Steve Eddins <Steve....@mathworks.com> wrote in message <h5upe8$8p6$1...@fred.mathworks.com>...

Thanks atleast I got an idea how to start!!
I tried like this :

fid = fopen('ap15-reflec-60b.tif', 'r');
for i=1:length(A.StripOffsets)
fseek(fid, A.StripOffsets(i), 'bof');
B(:,i) = fread(fid, 342);
end

First of all I don't understand what StripOffsets field mean? It has total 47280 elements. what does it mean? The program takes a long time to generate the matrix B, I get some numbers inside each column but can you please tell me what exactly is this?
I am sorry for asking so many Qs, I never did image processing in MATLAB before.

Many thanks in advance,
Megha

megha bhatt

unread,
Aug 13, 2009, 9:10:20 AM8/13/09
to
"megha bhatt" <mubh...@yahoo.co.in> wrote in message <h5usvv$9ll$1...@fred.mathworks.com>...

Hi Steve,
I have few confusions. You said me to read channels one by one. Actually this is a hyper spectral image which is like a data cube having three dimensions in each cell and combination of these cells conclude 60 channels it means [342X788X60] each cell has 1 reflectance value per pixel which finally I want to extract. the combination of 60 reflectance values for 1 pixel will finally give me one spectrum.
When I start to read the image from beginning of the row specified by StripOffsets field I get a 342X60 matrix with most of the places Zero. Do you have any idea what exactly is missing to bring back the third dimension in picture which contains reflectance values?

Thanks once again,
Megha

Ashish Uthama

unread,
Aug 13, 2009, 9:18:57 AM8/13/09
to
On Wed, 12 Aug 2009 13:09:19 -0400, megha bhatt <mubh...@yahoo.co.in>
wrote:

> Steve Eddins <Steve....@mathworks.com> wrote in message

Have a look at the doc for FREAD. You want to use this syntax:

A = fread(fileID, sizeA, precision) interprets values in the file
according to the form and size described by the precision. The sizeA
parameter is optional.

The doc also mentions that the default precision is: 'uint8=>double'. i.e
it reads in a byte and then interprets it as a double. I believe you might
want 'single=>double' since your earlier post appear to indicate that your
data is 32 bits, IEEE floating point.

Ashish Uthama

unread,
Aug 13, 2009, 9:32:56 AM8/13/09
to
On Thu, 13 Aug 2009 09:10:20 -0400, megha bhatt <mubh...@yahoo.co.in>
wrote:

> "megha bhatt" <mubh...@yahoo.co.in> wrote in message

IMFINFO output appears to indicate a 788x342x60 data.

*air code, please verify*

indOffset=1;
data=zeros(788,342,60);
for h=1:788
for c=1:60
fseek(fid,A.StripOffsets(indOffset),'bof');
data(h,:,c)=fread(fid,342,'single=>double') %populate individual row,
look up doc for ':'
indOffset=indOffset+1;
end
end

0 new messages