Code covered by the BSD License  

Highlights from
Read Medical Data 3D

4.64286

4.6 | 15 ratings Rate this file 235 Downloads (last 30 days) File Size: 54.5 KB File ID: #29344
image thumbnail

Read Medical Data 3D

by

 

10 Nov 2010 (Updated )

GUI to open most Medical file-formats: Dicom, V3D, ISI, NifTI, Analyze and other formats

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

This function ReadData3D allows the user to open medical 3D files. It
  supports the following formats :
 
    Dicom Files ( .dcm , .dicom )
    V3D Philips Scanner ( .v3d )
    GIPL Guys Image Processing Lab ( .gipl )
    HDR/IMG Analyze ( .hdr )
    ISI Files ( .isi )
    NifTi ( .nii )
    RAW files ( .raw , .* )
    VMP BrainVoyager ( .vmp )
    XIF HDllab/ATL ultrasound ( .xif )
    VTK Visualization Toolkit ( .vtk )
    Insight Meta-Image ( .mha, .mhd )
    Micro CT ( .vff )
    PAR/REC Philips ( .par, .rec)

  usage:
 
  [V,info]=ReadData3D;
 
  or,
 
  [V,info]=ReadData3D(filename);
 
  outputs,
    V : The 3D Volume
    info : Struct with info about the data
         Always the following fields are present
         info.Filename : Name of file
         info.Dimensions : Dimensions of Volume
         info.PixelDimensions : Size of one pixel / voxel
  
  Warning!
   The read functions are not fully implemented as defined in
   the file-format standards. Do not use this function for
   critical applications.
 

Question,
If you know an example file of GE_Version_4, GE_Version_5 or some other often used 3D medical format, please leave a comment (so I can implement that format).

Acknowledgements

This file inspired Medical Image Processing Toolbox and Dicom Import Gui.

MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (35)
16 Oct 2014 Stefan

Had the same problem as Noha and aziesel. I am pretty sure it is because I was trying to read a 2D mha file. You probably need to convert it into a 3D file (:,:,1).

13 Jun 2014 Jameson

This program is ok. Works fine with the GUI. Totally fails if you have -nodisplay turned on. Makes it impossible for server/cluster use.

10 Jun 2014 aziesel

I'm getting the same error as Noha. Any input on this problem is appreciated!

04 Jun 2014 Noha

I am trying to read mha file and I get these errors
Error using reshape
To RESHAPE the number of elements must not change.

Error in mha_read_volume (line 78)
V = reshape(V,info.Dimensions);

Error in ReadData3D>loaddata (line 379)
data.volume=feval(fhandle,data.info);

Error in ReadData3D>ReadData3D_OpeningFcn (line 227)
loaddata();

Error in gui_mainfcn (line 221)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});

Error in ReadData3D (line 68)
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

any hints?
Thanks!

23 May 2014 eman

#Dirk-Jan Kroon
what about PGM 3d images?
how can i read them?

06 May 2014 Adam

Gah! I didn't want to make either of those ratings... those were accidents. I don't see a way to get rid of them. Oh well...

06 May 2014 Adam  
06 May 2014 Adam  
17 Apr 2014 mat

I am trying to read a .mha file but I got this message:

>> ReadData3D
RescaleSlope not available, assuming 1
RescaleIntercept not available, assuming 0

26 Mar 2014 Mohamed

it works fine for reading of Insight Meta-Image (.mha, .mhd)

Thank you

17 Feb 2014 Jihun  
05 Dec 2013 Chuck Hatt

I would suggest adding the following code to mha_read_volume.m, near line 77, if working with vector data:

fclose(fid);
if isfield(info,'ElementNumberOfChannels')
V = reshape(V,[info.Dimensions,str2double(info.ElementNumberOfChannels)]);
else
V = reshape(V,info.Dimensions);
end

01 Sep 2013 Nic

thank you! very helpful to check simulated data.

26 Jul 2013 liu

Nice tools.There's a GE Voldicom format, which can be exported from GE vivid ultrasound scanner.Can this format be read?

29 Apr 2013 Max W.K. Law

I like this piece of tool. However, is it possible to take out the GUI? I have like 500 files need to be loaded and processed, and written the processed data back to the drive.

It takes about 30mins to finish one volume. I want everything to be automated so that my computer can work over weekend.

06 Feb 2013 AP

[SOLUTION]: To be able to read the par file correctly, add the following codes in par_read_header mfile:

RescaleIntercept = vald(12);
RescaleSlope = vald(13);
ScaleSlope = vald(14);

right after the line:
current_loc=current_loc+IIT.NumberOfValues;
end

Then also add the following codes:

info.RescaleIntercept = RescaleIntercept;
info.RescaleSlope = RescaleSlope;
info.ScaleSlope = ScaleSlope;

after the line:

info.ImageInformationTags=ImageInformationTags;

05 Feb 2013 AP

Another bug is that, par_read_header function does not really read 'RescaleSlope' and 'RescaleIntercept' and simply assumes 1 and 0, respectively. So it does not really matter whether we set real to true or not.

05 Feb 2013 AP

We may have the file extensions in either upper or lower case. Therefore, the following code:

if(strcmp(data.fileformat(i).ext(2:end),ext)), found=1; fileformatid=i; end

needs to be modified to:

if(strcmp(upper(data.fileformat(i).ext(2:end)),upper(ext))), found=1; fileformatid=i; end

05 Feb 2013 AP

Great tool! How can we bypass the dialog box and run everything from command line?

10 Jan 2013 Antonio

btw, how do I display the volumetric data on a .mha file once it has been loaded? I want to do volume rendering with it.

11 Oct 2012 Gabriele

Really good...it allows to avoid unpleaseant .dcm -> .nii trnasformations!

03 Oct 2012 Tim Monitoring

Hi
Dear friend,
Would you help me,
How to get geometry anatomy shape from DICOM using Matlab?

02 Jul 2012 Maite Ruiz

Hi,

I'm trying to read some .mhd and .mha files and I have some errors. I tried to change the code using your comments about this problem, but I still have some errors...
Could you maybe send me the code that worked well in your case?

Thank you in advance!

Maite

20 Jun 2012 Paul Groot

atie,

First make sure to add the PAR/REC scripts to your path:

addpath('...\ReadData3D\par');

(or copy them to your current script folder)

Then just read the data in two stages:

info=par_read_header('filename.PAR')
data=par_read_volume(info);

The info struct is a collection of all the information in the PAR file. That's it!

19 Jun 2012 atie

hi, im trying to read .rec file. i thought i could use this tools because it stated there PAR/REC Philips ( .par, .rec) are among supported file. can anybody help?

12 Apr 2012 slama najla

Hello, can some body send for me an example of 3d medical data to test it with an algorithm of watermarking because i didn't arrive to find it.thanks

30 Mar 2012 Amedeo

Good Tool.
Probably you should modify source code for saving the loaded volume.
Now you save only filename and fileformatid.

look at ReadData3D.m - line 398

06 Mar 2012 Shihui

There are some problems in reading my mhd file, which are list below.

Error using fseek
Invalid file identifier. Use fopen to generate a valid file
identifier.

Error in mha_read_volume (line 36)
fseek(fid,0,'bof');

Error in ReadData3D>loaddata (line 379)
data.volume=feval(fhandle,data.info);

Error in ReadData3D>pushbutton_load_Callback (line 365)
loaddata();

Error in gui_mainfcn (line 96)
feval(varargin{:});

Error in ReadData3D (line 70)
gui_mainfcn(gui_State, varargin{:});

Error in
@(hObject,eventdata)ReadData3D('pushbutton_load_Callback',hObject,eventdata,guidata(hObject))


Error using waitfor
Error while evaluating uicontrol Callback

04 Feb 2012 maya

recently i have downloaded this tool.actually i have a setof 2D dicom slices and i converted to a 3D volume(.hdr) using a software,can i use your tool to read the intensity values of the voxels.I tried to use your tool,its giving error in the guifn
rror in ==> gui_mainfcn>local_openfig at 216
gui_hFigure = openfig(name, singleton, 'auto');

Error in ==> gui_mainfcn at 94
gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt);

Error in ==> ReadData3D at 68
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

pleases help

04 Oct 2011 Nicolas Toussaint

hi, I just have 2 or 3 corrections to your code if you are interested :

(1) : in par_read_volume.m - line 27 : replace 'short' by 'ushort'

(2) : in mha_read_volume - line 78 :

replace :

vector = info.Dimensions;

by :

if isfield(info, 'ElementNumberOfChannels')
vector = [str2double(info.ElementNumberOfChannels) info.Dimensions];
else
vector = info.Dimensions;

cheers :-)

15 Jul 2011 Felx

I had trouble reading data that I imported from DICOM (using SPM) and analyzed/modified through SPM. SPM saved the data in .hdr/.img files and I used the 'hdr_read_volume()' function to read it back into matlab. I fond that some datasets were read incorrectly and found that this happened when the value of the 'ImgDataType' in the .hdr file was 512. Both, the coustom read function ('get_info_analyze_hdr()') as well as Matlabs 'analyze75info.m' can't handle that value. After a little research I found that the datatype for 512 is DT_UNINT16 but this datatype is not known either so I tried DT_SIGNED_SHORT and the data is read in correctly.

So my fix was to add to strImgData in
'get_info_analyze_hdr()' the cell

strImgData{512}.ImgDataType = 'DT_SIGNED_SHORT';
strImgData{512}.ColorType = 'grayscale';

alternatively one could modify 'analyze76info.m' and add under

switch ImgDataType
...
case int16(512)
metadata.ImgDataType = 'DT_SIGNED_SHORT'

26 May 2011 Siyi Deng

great tool!

16 May 2011 Yannick

For the record, these are my changes:

***** old\mha_read_volume.m

datasize=prod(info.Dimensions)*info.BitDepth/8;

***** NEW\MHA_READ_VOLUME.M

datasize=prod(info.Dimensions)*info.NumberOfDimensions;

*****

***** old\mha_read_volume.m
fclose(fid);
V = reshape(V,info.Dimensions);

***** NEW\MHA_READ_VOLUME.M
fclose(fid);
V = reshape(V,[info.NumberOfDimensions, info.Dimensions]);

*****

18 Mar 2011 Yannick

Nice submission. I fixed two bugs in the parts which read .mha/mhd files (correct datasize --> work with oversized volume files; interpreting NumberOfDimensions --> work with 4D files). If interested, send me a private message with your email address and I will send you my updated files.

11 Nov 2010 Sean de

Excellent! I've always wondered what was in those HDR files. We knew the dimensions of the IMG files ahead of time but this is a great tool for ones which we've lost and because the number of slices is not always uniform.

Thanks!

Updates
23 Feb 2011

VTK bug fix by C. Aguilar

Contact us