[Insight-users] RE: How can i pass 3D Data from ITK to Matlab?

Padfield, Dirk R (Research) padfield at research.ge.com
Tue May 17 13:54:46 EDT 2005


Hello Sotiris,
	I have done this often.  Write the volume out as a .mhd file; this will create a .raw file and a .mhd header.  Then, you can read the .raw file in Matlab.  I have a function that I use for this that I have pasted below.  Put this code in a .m file called "readRaw.m" and use this function to read your volume.  The description of the function is hopefully fairly clear.
	I hope this helps.
	Dirk.


function  rawData = readRaw(filename,imSize,type,endian,skip);

% Reads a raw file
% Inputs: filename, image size, image type, byte ordering, skip
% If you are using an offset to access another slice of the volume image
% be sure to multiply your skip value by the number of bytes of the 
% type (ie. float is 4 bytes).
% Inputs: filename, image size, pixel type, endian, number of values to
% skip.
% Output: image


fid = fopen(filename,'rb',endian);
if (fid < 0)
    fprintf('Filename %s does not exist\n',filename);
    rawData = -1;
else
    status = fseek(fid,skip,'bof');
	if status == 0
        rawData = fread(fid,prod(imSize),type);
        fclose(fid);
        if (length(imSize == 3))
            slices = length(rawData)/imSize(1)/imSize(2);
            imSize(3) = slices;
        end
        rawData = reshape(rawData,imSize);
	else
        rawData = status;
	end
end


------------------------------

Message: 2
Date: Tue, 17 May 2005 09:33:10 +0100 (BST)
From: Sotiris Dimopoulos <vtksot_dimopoulos at yahoo.gr>
Subject: [Insight-users] How can i pass 3D Data from ITK to Matlab?
To: insight-users at itk.org
Message-ID: <20050517083311.48070.qmail at web26410.mail.ukl.yahoo.com>
Content-Type: text/plain; charset=iso-8859-7

Hi!

I have created a 3d data set in ITK and i want to pass
them in matlab...
1)Is it feasible?
2)If yes, in what way?
3)In what kind of file should i write my set,so it can
be read from matlab? 

Many thanks!
   Sotiris


More information about the Insight-users mailing list