<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&lt;PixelType,Dimension&gt; 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-&gt;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-&gt;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-&gt;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-&gt;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-&gt;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-&gt;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&lt; FixedImageType &gt; ChangeInfoType;</div><div>  ChangeInfoType::Pointer changeFixedInfo = ChangeInfoType::New();</div><div>  ChangeInfoType::Pointer changeMovingInfo = ChangeInfoType::New();</div>
<div><br></div><div><div>  changeFixedInfo-&gt;SetInput(fixedImageReader-&gt;GetOutput());</div><div>  changeMovingInfo-&gt;SetInput(movingImageReader-&gt;GetOutput());</div><div><br></div><div>  changeFixedInfo-&gt;SetOutputSpacing(fixedSpacing);</div>
<div>  changeMovingInfo-&gt;SetOutputSpacing(movingSpacing);</div><div>  changeFixedInfo-&gt;SetChangeSpacing(true);</div><div>  changeMovingInfo-&gt;SetChangeSpacing(true);</div><div><br></div><div>  changeFixedInfo-&gt;SetOutputDirection(fixedOrientation);</div>
<div>  changeMovingInfo-&gt;SetOutputDirection(movingOrientation);</div><div><div>  changeFixedInfo-&gt;SetChangeDirection(true);</div><div>  changeMovingInfo-&gt;SetChangeDirection(true);</div></div><div><br></div><div>  changeFixedInfo-&gt;SetOutputOrigin(fixedOrigin);</div>
<div>  changeMovingInfo-&gt;SetOutputOrigin(movingOrigin);</div><div><div>  changeFixedInfo-&gt;SetChangeOrigin(true);</div><div>  changeMovingInfo-&gt;SetChangeOrigin(true);</div><div><br></div><div>  changeFixedInfo-&gt;Update();</div>
<div>  changeMovingInfo-&gt;Update();</div><div><br></div><div><div>  registration-&gt;SetFixedImage(    changeFixedInfo-&gt;GetOutput()    );</div><div>  registration-&gt;SetMovingImage(   changeMovingInfo-&gt;GetOutput()   );</div>
<div>  registration-&gt;SetFixedImageRegion( changeFixedInfo-&gt;GetOutput()-&gt;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">&lt;<a href="mailto:bill.lorensen@gmail.com">bill.lorensen@gmail.com</a>&gt;</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&#39;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>
&lt;<a href="mailto:patrik.brynolfsson@gmail.com">patrik.brynolfsson@gmail.com</a>&gt; wrote:<br>
&gt; Hello,<br>
&gt; I&#39;m working on a Matlab mex-implementation of an ITK registration. This<br>
&gt; means that instead of loading the images from files I will load them from<br>
&gt; memory as 3D matrices. All the DICOM information needs to be passed to ITK<br>
&gt; from Matlab as well, and this is where my problems begin. The information<br>
&gt; that I thought was essential for a correct registration is:<br>
&gt; * Origin<br>
&gt; * Spacing<br>
&gt; * Direction<br>
&gt; I set these using the &quot;ChangeInformationImageFilter&quot; and it is working; the<br>
&gt; images have the origin, spacing and directional cosines that are assigned to<br>
&gt; them, and they are the same as if the dicom images were loaded from files.<br>
&gt; However, the result of the registration is different from that when loading<br>
&gt; the images from files, with all other components set the same, (of course I<br>
&gt; reinitialize the seed). Not by much, but they should be exactly the same! I<br>
&gt; use Mattes mutual information metric, linear interpolation, Versor rigid 3D<br>
&gt; transform and the accompanying Versor rigid 3D optimizer together with the<br>
&gt; &quot;CenteredTransformInitializer&quot;.<br>
&gt; I know that the difference in results are due to the way I read the data. If<br>
&gt; I change the input from memory to reading the dicom files I get the same<br>
&gt; result as with a stand-alone .exe-application, so this is where the error<br>
&gt; is.<br>
&gt; Does anyone have any idea as to what other information I need to pass from<br>
&gt; matlab to get identical results?<br>
&gt; Thanks in advance<br>
&gt; --<br>
&gt; Patrik Brynolfsson<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div></div>&gt; _____________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
&gt;<br>
&gt;<br>
</blockquote></div><br><br clear="all"><br>-- <br>Patrik Brynolfsson<br><br><br>
</div>