raacampbell / matlab_elastix

MATLAB Elastix wrapper
http://www.mathworks.com/matlabcentral/fileexchange/52982-matlab-elastix
GNU Lesser General Public License v3.0
26 stars 12 forks source link

mhd_write failing with out in-house atlas.mhd images #11

Open raacampbell opened 8 years ago

raacampbell commented 8 years ago

looks like an integer overflow is happening

raacampbell commented 8 years ago

Hmmm.. Reading seems to work correctly

>> Aorig = mhd_read('~/atlas.mhd');

Then I can save and re-read an the results are the same:

>> mhd_write(Aorig,'atlas_write')
>> Areadwritten  = mhd_read('atlas_write.mhd');
>> all(Aorig(:) == Areadwritten(:))
ans =

     1

And atlas_write looks fine in Lasagna. In MATLAB these are int32 files and they are ints in the MHD.

However, if I run the in-house function atlasInSampleSpace (which returns the transformed atlas [via transformix] to the workspace) then I get an int16 and things fuck up from there.

raacampbell commented 8 years ago

Ah, shit, it's transformix that's fucking this up:

$ transformix -in atlas.mhd  -tp TransformParameters.1.txt -out ./

The result is toast. transformix is saving it as shorts even though the input mhd is listed as unit.

raacampbell commented 8 years ago

Things that seem to fix this:

(FinalBSplineInterpolationOrder 0)
(ResultImagePixelType "int")

The first stops it interpolating. The second is needed because the parameters were calculated with the template images, which are shorts.