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

Problem reading 16 Bit Tiff images? - Matlab

325 views
Skip to first unread message

Elena Diaz

unread,
Apr 28, 2000, 3:00:00 AM4/28/00
to
Hi,

How can I read 16Bit Tiff Images with Matlab?

I am using the function imread but it doesn't work. The matrix that it
returns is empty.
I have Matlab version 5.1.

Has someone a .m file to do it?

Thanks a lot.

Elena

Steve Eddins

unread,
Apr 28, 2000, 3:00:00 AM4/28/00
to

16-bit TIFF support was added in MATLAB 5.3, which was released about
a year ago.

Steve

Elena Diaz <ed...@embl-heidelberg.de> writes:

--
Steve Eddins
The MathWorks, Inc.
edd...@mathworks.com
http://www.mathworks.com

Daniel H Dolan

unread,
Apr 28, 2000, 3:00:00 AM4/28/00
to

I had some problems with imread in MATLAB 5.3 on some images, so I
wrote an M-file to read the TIFF header and then read the file
appropriately. It seems to work on 8, 16, and 32 bit TIFF files with a
single image per file and no compression. It does not require the image
processing toolbox, but does require imfinfo (I don't know if that comes
with 5.1). Perhaps you may find it useful.

Dan Dolan
Washington State University
ddo...@wsu.edu
Office: 934 Webster
Phone: (509)335-5930

%TIFF_read
function data=TIFF_read(filename)

% extract format info
fileinfo=imfinfo(filename);

% make sure file is indeed in TIFF format
filetype=getfield(fileinfo,'Format');
if ~(filetype=='tif')
disp('This is not a TIFF file');
return;
end

width=getfield(fileinfo,'Width');
height=getfield(fileinfo,'Height');
bits=getfield(fileinfo,'BitDepth');
switch bits
case 8
precision='uint8';
case 16
precision='uint16';
case 32
precision='uint32';
case 64
precision='uint64'
otherwise
disp('Unknown Bit Size');
return;
end

order=getfield(fileinfo,'ByteOrder');
compress=getfield(fileinfo,'Compression');

offset=getfield(fileinfo,'StripOffsets');

% Read entire TIFF file into array
fid=fopen(filename,'rb');
junk=fread(fid,offset);
data=fread(fid,[width height],precision);
fclose(fid);
data=data';

Steve Eddins

unread,
Apr 28, 2000, 3:00:00 AM4/28/00
to

imfinfo was introduced in MATLAB 5.0.

Your function will work if the image is stored in a single strip, in
which case the StripOffsets field returned by imfinfo is a scalar.
With multiple strips you have to read each strip and piece together
the results.

I'd be interested to hear more about the problems you had with
imread. We'd like to fix them if we can!

Steve

--

0 new messages