<div>Hello Bill, thanx for answering!</div><div><br></div>The filter I use are:<div><br></div><div>Registration part (same for both cases):</div><div><br></div><div><div>itkImageRegistrationMethod</div><div>itkMattesMutualInformationImageToImageMetric</div>
<div>itkLinearInterpolateImageFunction</div><div><div>itkVersorRigid3DTransform</div><div>itkVersorRigid3DTransformOptimizer</div><div>itkCenteredTransformInitializer</div><div><br></div><div>Reading images from memory:</div>
<div><br></div><div>itkImportImageFilter</div></div><div>itkChangeInformationImageFilter</div><div><br></div><div>Reading images from DICOM:</div><div><br></div><div><div>itkImageSeriesReader</div><div>itkGDCMImageIO</div>
<div>itkGDCMSeriesFileNames</div><div><br></div><div><b>The code to read images from memory is:</b></div><div><br></div><div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"> </font><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif">ty</font></span><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif">pedef itk::ImportImageFilter<PixelType,Dimension> ImportFilterType;</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> ImportFilterType::Pointer fixedImageReader = ImportFilterType::New();</font></span></div><div>
<span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> ImportFilterType::Pointer movingImageReader = ImportFilterType::New();</font></span></div><div>
<span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> const</font></span><span class="Apple-tab-span" style="white-space:pre"><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif">                </font></span></span><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif">mwSize*</font></span><span class="Apple-tab-span" style="white-space:pre"><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif">                </font></span></span><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> dimsFix = mxGetDimensions(prhs[0]);</font></span><span class="Apple-tab-span" style="white-space:pre"><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif">                        </font></span></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> const</font></span><span class="Apple-tab-span" style="white-space:pre"><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif">                </font></span></span><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif">mwSize*</font></span><span class="Apple-tab-span" style="white-space:pre"><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif">                </font></span></span><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> dimsMov = mxGetDimensions(prhs[1]);</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> ImportFilterType::SizeType sizeFix;</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> ImportFilterType::SizeType sizeMov;</font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> sizeFix[0] = dimsFix[0];</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> sizeFix[1] = dimsFix[1]; </font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> sizeFix[2] = dimsFix[2];</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> sizeMov[0] = dimsMov[0];</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> sizeMov[1] = dimsMov[1];</font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> sizeMov[2] = dimsMov[2];</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> ImportFilterType::IndexType start;</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> start.Fill( 0 );</font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> ImportFilterType::RegionType regionFix;</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> regionFix.SetIndex( start );</font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> regionFix.SetSize( sizeFix );</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> ImportFilterType::RegionType regionMov;</font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> regionMov.SetIndex( start );</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> regionMov.SetSize( sizeMov );</font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> fixedImageReader->SetRegion( regionFix );</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> movingImageReader->SetRegion(regionMov );</font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br>
</font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> //Import image from memory, passed from MATLAB</font></span></div><div>
<span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> fixedImageReader->SetImportPointer((PixelType*)mxGetData(prhs[0]),mxGetNumberOfElements(prhs[0]),false);</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> movingImageReader->SetImportPointer((PixelType*)mxGetData(prhs[1]),mxGetNumberOfElements(prhs[1]),false);</font></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> fixedImageReader->Update();</font></span></div><div><span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="arial, helvetica, sans-serif"> movingImageReader->Update();</font></span></div>
<div><br></div><div><b>...and the code to set the relevant info is:</b></div><div><br></div><div><div> double *fixedSpacingInput = mxGetPr(prhs[2]);</div><div> double *movingSpacingInput = mxGetPr(prhs[3]);</div><div>
<br></div><div> double *fixedOrientationInput<span class="Apple-tab-span" style="white-space:pre">        </span>= mxGetPr(prhs[4]);</div><div> double *movingOrientationInput<span class="Apple-tab-span" style="white-space:pre">        </span>= mxGetPr(prhs[5]);</div>
<div><br></div><div> double *fixedOriginInput<span class="Apple-tab-span" style="white-space:pre">        </span>= mxGetPr(prhs[6]);</div><div> double *movingOriginInput = mxGetPr(prhs[7]);</div><div><br></div><div> **Code for casting input to correct types are skipped, not important for this question**</div>
<div><br></div><div> typedef itk::ChangeInformationImageFilter< FixedImageType > ChangeInfoType;</div><div> ChangeInfoType::Pointer changeFixedInfo = ChangeInfoType::New();</div><div> ChangeInfoType::Pointer changeMovingInfo = ChangeInfoType::New();</div>
<div><br></div><div><div> changeFixedInfo->SetInput(fixedImageReader->GetOutput());</div><div> changeMovingInfo->SetInput(movingImageReader->GetOutput());</div><div><br></div><div> changeFixedInfo->SetOutputSpacing(fixedSpacing);</div>
<div> changeMovingInfo->SetOutputSpacing(movingSpacing);</div><div> changeFixedInfo->SetChangeSpacing(true);</div><div> changeMovingInfo->SetChangeSpacing(true);</div><div><br></div><div> changeFixedInfo->SetOutputDirection(fixedOrientation);</div>
<div> changeMovingInfo->SetOutputDirection(movingOrientation);</div><div><div> changeFixedInfo->SetChangeDirection(true);</div><div> changeMovingInfo->SetChangeDirection(true);</div></div><div><br></div><div> changeFixedInfo->SetOutputOrigin(fixedOrigin);</div>
<div> changeMovingInfo->SetOutputOrigin(movingOrigin);</div><div><div> changeFixedInfo->SetChangeOrigin(true);</div><div> changeMovingInfo->SetChangeOrigin(true);</div><div><br></div><div> changeFixedInfo->Update();</div>
<div> changeMovingInfo->Update();</div><div><br></div><div><div> registration->SetFixedImage( changeFixedInfo->GetOutput() );</div><div> registration->SetMovingImage( changeMovingInfo->GetOutput() );</div>
<div> registration->SetFixedImageRegion( changeFixedInfo->GetOutput()->GetBufferedRegion() );</div></div></div><div><br></div><div>As a check I print the origin, spacing and direction for the images and they are identical to when reading from DICOM files. I read the DICOM series just as described in chapter 7.12 in the ITK manual.</div>
<div><br></div><div>Any ideas to what might be wrong here?</div><div><br></div><div>Thanks in advance!</div><div><br></div><div>//Patrik Brynolfsson</div></div></div></div></div><div><div><br></div><div><br></div></div><br>
<div class="gmail_quote">2009/9/16 Bill Lorensen <span dir="ltr"><<a href="mailto:bill.lorensen@gmail.com">bill.lorensen@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
You should get the same answers. Exactly what filters are you using in<br>
each of the cases. I can't tell from your description.<br>
<br>
Bill<br>
<div><div></div><div class="h5"><br>
On Tue, Sep 15, 2009 at 4:38 PM, Patrik Brynolfsson<br>
<<a href="mailto:patrik.brynolfsson@gmail.com">patrik.brynolfsson@gmail.com</a>> wrote:<br>
> Hello,<br>
> I'm working on a Matlab mex-implementation of an ITK registration. This<br>
> means that instead of loading the images from files I will load them from<br>
> memory as 3D matrices. All the DICOM information needs to be passed to ITK<br>
> from Matlab as well, and this is where my problems begin. The information<br>
> that I thought was essential for a correct registration is:<br>
> * Origin<br>
> * Spacing<br>
> * Direction<br>
> I set these using the "ChangeInformationImageFilter" and it is working; the<br>
> images have the origin, spacing and directional cosines that are assigned to<br>
> them, and they are the same as if the dicom images were loaded from files.<br>
> However, the result of the registration is different from that when loading<br>
> the images from files, with all other components set the same, (of course I<br>
> reinitialize the seed). Not by much, but they should be exactly the same! I<br>
> use Mattes mutual information metric, linear interpolation, Versor rigid 3D<br>
> transform and the accompanying Versor rigid 3D optimizer together with the<br>
> "CenteredTransformInitializer".<br>
> I know that the difference in results are due to the way I read the data. If<br>
> I change the input from memory to reading the dicom files I get the same<br>
> result as with a stand-alone .exe-application, so this is where the error<br>
> is.<br>
> Does anyone have any idea as to what other information I need to pass from<br>
> matlab to get identical results?<br>
> Thanks in advance<br>
> --<br>
> Patrik Brynolfsson<br>
><br>
><br>
><br>
</div></div>> _____________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
><br>
><br>
</blockquote></div><br><br clear="all"><br>-- <br>Patrik Brynolfsson<br><br><br>
</div>