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
Elena Diaz <ed...@embl-heidelberg.de> writes:
--
Steve Eddins
The MathWorks, Inc.
edd...@mathworks.com
http://www.mathworks.com
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';
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
--