Problems with mha_read_volume when reading MHA-File from Slicer3D

413 views
Skip to first unread message

Christian Richter

unread,
Jan 2, 2015, 12:33:45 PM1/2/15
to cerr-...@googlegroups.com
Dear CERR community,

I have a problem with importing mha files (contours saved with Slicer3D).

For this task I wrote a small function (SlicerSS2CERR):

rois_header=mha_read_header(filelocation);
rois_volume = mha_read_volume(rois_header);
rois_zflipped = flipdim(rois_volume,3);
rois_zflipped_perm = permute(rois_zflipped,[2 1 3]);
planC=maskToCERRStructure(rois_zflipped_perm, 1, 1, SSname);

This code was working when I wrote it a few years ago. However, when I use it now, I get the following error:

Reference to non-existent field 'ElementNumberOfChannels'.

Error in mha_read_volume (line 79)
V = reshape(V,[str2num(info.ElementNumberOfChannels) info.Dimensions]);

Error in SlicerSS2CERR (line 9)
rois_volume = mha_read_volume(rois_header);

Indeed this field is not part of the header.. 

Filename: [1x107 char]
                   Format: 'MHA'
           CompressedData: 'true'
               ObjectType: 'image'
       NumberOfDimensions: 3
               BinaryData: 'true'
                ByteOrder: 'false'
       CompressedDataSize: 116764
          TransformMatrix: [1 0 0 0 1 0 0 0 1]
                   Offset: [-325 -325 -257.5000]
         CenterOfRotation: [0 0 0]
    AnatomicalOrientation: 'RAI'
          PixelDimensions: [1.2700 1.2700 2.5000]
               Dimensions: [512 512 168]
                 DataType: 'short'
                 DataFile: 'LOCAL'
                 BitDepth: 16
               HeaderSize: 344

Does anybody has an idea what could be wrong? Is there another way to read MHA files (Contours) from Slicer into CERR?

Best regards,
Christian

ap...@mskcc.org

unread,
Jan 2, 2015, 2:20:17 PM1/2/15
to cerr-...@googlegroups.com

Here is the script I use to import .mha structures that are deformed using Plastimatch. readmha.m is distributed along with CERR and it reads the ElementNumberOfChannels field. Hope this works for you.

 

[data3M,infoS] = readmha(structMhaFileName);

data3M = flipdim(permute(data3M,[2,1,3]),3);

isUniform = 1;

strName = ‘StructName’;

strCreationScanNum = 1;

planC = maskToCERRStructure(data3M,isUniform,strCreationScanNum,strName,planC);

 

Regards,

Aditya

--
You received this message because you are subscribed to the Google Groups "CERR FORUM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cerr-forum+...@googlegroups.com.
To post to this group, send email to cerr-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cerr-forum/3fa5a147-b684-4c1a-bc9f-c75efa1f0a4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

     =====================================================================

Please note that this e-mail and any files transmitted from
Memorial Sloan-Kettering Cancer Center may be privileged, confidential,
and protected from disclosure under applicable law. If the reader of
this message is not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient,
you are hereby notified that any reading, dissemination, distribution,
copying, or other use of this communication or any of its attachments
is strictly prohibited. If you have received this communication in
error, please notify the sender immediately by replying to this message
and deleting this message, any attachments, and all copies and backups
from your computer.

Christian Richter

unread,
Jan 5, 2015, 8:47:43 AM1/5/15
to cerr-...@googlegroups.com, ap...@mskcc.org
Dear Aditya,

Thank you for your fast response. Unfortunately, when I tried your script, I got the following error message:

Error using reshape
To RESHAPE the number of elements must not change.

Error in readmha (line 119)
A = reshape(A,nchannels,sz(1),sz(2),sz(3));

A has 58382 elements (double). sz(1)=sz(2)=512, sz(3)=168, nchannels=1..

Do you have an idea what could be wrong?

Best regards,
Christian

To post to this group, send email to cerr...@googlegroups.com.

ap...@mskcc.org

unread,
Jan 7, 2015, 11:10:56 AM1/7/15
to cerr-...@googlegroups.com
Can you tell me what is the ElementType is  for your data? You can put a breakpoint on line 70 in readmha.m and print out the element_id variable.

Thanks,
Aditya

Marta

unread,
Jan 8, 2015, 10:42:17 AM1/8/15
to cerr-...@googlegroups.com
Hi Everyone,
I think Slicer3D uses compressed data Format for MHA volumes (you can look it up in the Header).
This cannot be read from matlab...

Can CERR read MHDs? These are uncompressed. Otherwise, I would suggest the following workflow:
1) save from Slicer3D in MHD Format (thus generating an mhd - header- and a raw data file)
2) Open up the mhd and raw files with text Editor.
3) modify in the mhd file the line Element Data File to say LOCAL (it should contain the Name of the raw data file at the beginning)
4) copy paste the Content of .raw file in a new line after the Element Data File line in the .mhd
5) save as .mha

This should work :)
my 2 cents
Marta

Christian Richter

unread,
Jan 9, 2015, 12:35:53 PM1/9/15
to cerr-...@googlegroups.com
Hi Marta and Aditya,

Thanks for your response. 

The data type is MET_SHORT

Hier is the header of the MHA:
ObjectType = Image
NDims = 3
BinaryData = True
BinaryDataByteOrderMSB = False
CompressedData = True
CompressedDataSize = 126812
TransformMatrix = 1 0 0 0 1 0 0 0 1
Offset = -325 -325 -297.3
CenterOfRotation = 0 0 0
AnatomicalOrientation = RAI
ElementSpacing = 1.27 1.27 2.50055
DimSize = 512 512 184
ElementType = MET_SHORT
ElementDataFile = LOCAL

@Marta: When I tried to export MHD from Slicer3D, it was also compressed (zraw). 

Also interesting to know: In the past I was able to import MHA into CERR with my routine. But somehow this has changed (new version on new computer, but also with the old CERR version it does not work any more)..so strange

Marta Peroni

unread,
Jan 11, 2015, 3:12:13 PM1/11/15
to cerr-...@googlegroups.com
Hi Christian,
as I thought, your data are compressed.
yes, also MHDs are compressed, but any uncompressing tool (e.g. winzip) should be able to unzip the raw.
Otherwise I suggest to use other type...
Marta
Reply all
Reply to author
Forward
0 new messages