hi , <br>I am trying to make my stack of images isotropic without rescaling . <br>I used the example in the Examples folder called &quot;Resamplevolumetobeisotropic.cxx&quot; and  and modified it a bit to remove the  rescaling part, the resulting grey scales are visibly bad. I have added my code below;<br>
<br><a href="http://dl.dropbox.com/u/2989703/Screen%20shot%202011-06-29%20at%2011.03.18%20AM.png">http://dl.dropbox.com/u/2989703/Screen%20shot%202011-06-29%20at%2011.03.18%20AM.png</a><br><br>the image on the left is one slice of the original and one on the left is the output.<br>
<br>// 25-6-2011 <br>// wound micro enviornment :<br>// step1 : read and write an image <br><br>#include &quot;itkImage.h&quot;<br>#include &quot;itkImageFileReader.h&quot; <br>#include &quot;itkImageFileWriter.h&quot;<br>
#include &quot;itkBinaryThresholdImageFilter.h&quot;<br>#include &quot;itkResampleImageFilter.h&quot;<br><br><br>#include &quot;itkRecursiveGaussianImageFilter.h&quot;<br><br>using namespace std;<br>int main( int argc, char ** argv )<br>
{<br>  if( argc &lt; 3 )<br>    {<br>    std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; std::endl;<br>    std::cerr &lt;&lt; argv[0] &lt;&lt; &quot; inputImageFile  outputImageFile &quot; &lt;&lt; std::endl;<br>    return EXIT_FAILURE;<br>
    }<br>    <br>    typedef unsigned short PixelType;<br>    const unsigned int Dimension=3;<br>    typedef itk::Image&lt; PixelType, Dimension&gt; ImageType;<br>    typedef   unsigned char   OutputPixelType;<br><br>    typedef itk::Image&lt; OutputPixelType,   Dimension &gt;   OutputImageType;<br>
<br><br>    typedef itk::ImageFileReader&lt;ImageType&gt; ReaderType;<br>    typedef itk::ImageFileWriter&lt;OutputImageType&gt; WriterType;<br>    <br>    <br>    ReaderType::Pointer reader = ReaderType::New();<br>    WriterType::Pointer writer = WriterType::New();<br>
    <br>    <br>    const char * inputFilename  = argv[1];<br>    const char * outputFilename = argv[2];<br>  <br>    reader-&gt;SetFileName( inputFilename );<br>      try <br>    {<br>    cerr &lt;&lt; &quot;reading file &quot;&lt;&lt; inputFilename &lt;&lt;endl;<br>
    reader-&gt;Update();<br>    }<br>  catch( itk::ExceptionObject &amp; excep )<br>    {<br>    std::cerr &lt;&lt; &quot;Exception caught!&quot; &lt;&lt; std::endl;<br>    std::cerr &lt;&lt; excep &lt;&lt; std::endl;<br>
    }<br>    <br>    typedef itk::RecursiveGaussianImageFilter&lt; ImageType, ImageType &gt; GaussianFilterType;<br>    GaussianFilterType::Pointer smootherX = GaussianFilterType::New();<br>    GaussianFilterType::Pointer smootherY = GaussianFilterType::New();<br>
<br>    smootherX-&gt;SetInput( reader-&gt;GetOutput() );<br>    smootherY-&gt;SetInput( smootherX-&gt;GetOutput() );<br>    <br>    ImageType::ConstPointer inputImage = reader-&gt;GetOutput();<br><br>    const ImageType::SpacingType &amp; inputSpacing = inputImage-&gt;GetSpacing();<br>
    const double isoSpacing = vcl_sqrt( inputSpacing[2] * inputSpacing[0] );<br>  <br>      //debug <br>      cerr &lt;&lt;&quot; inputSpacing &quot; &lt;&lt; inputSpacing[0] &lt;&lt; &quot; + &quot;&lt;&lt;<br>              inputSpacing[1] &lt;&lt; &quot; + &quot; &lt;&lt; inputSpacing[2]&lt;&lt;endl;<br>
              <br>      cerr &lt;&lt;&quot; isospacing &quot;&lt;&lt; isoSpacing &lt;&lt; endl;<br>      <br>    smootherX-&gt;SetSigma( isoSpacing );<br>    smootherY-&gt;SetSigma( isoSpacing );<br>    smootherX-&gt;SetDirection( 0 );<br>
    smootherY-&gt;SetDirection( 1 );<br><br>    smootherX-&gt;SetNormalizeAcrossScale( true );<br>    smootherY-&gt;SetNormalizeAcrossScale( true );<br>    <br>    <br>    typedef   unsigned char   OutputPixelType;<br><br>
    typedef itk::Image&lt; OutputPixelType,   Dimension &gt;   OutputImageType;<br>    typedef itk::ResampleImageFilter&lt; ImageType, OutputImageType &gt;  ResampleFilterType;<br><br>      ResampleFilterType::Pointer resampler = ResampleFilterType::New();<br>
      <br>       typedef itk::IdentityTransform&lt; double, Dimension &gt;  TransformType;<br><br>     TransformType::Pointer transform = TransformType::New();<br>     transform-&gt;SetIdentity();<br><br>     resampler-&gt;SetTransform( transform );<br>
     <br>     typedef itk::LinearInterpolateImageFunction &lt;ImageType, double &gt;  InterpolatorType;<br><br>     InterpolatorType::Pointer interpolator = InterpolatorType::New();<br><br>     resampler-&gt;SetInterpolator( interpolator );<br>
     <br>     resampler-&gt;SetDefaultPixelValue( 4095 );<br>     <br>      OutputImageType::SpacingType spacing;<br><br>     spacing[0] = isoSpacing;<br>     spacing[1] = isoSpacing;<br>     spacing[2] = isoSpacing;<br><br>
     resampler-&gt;SetOutputSpacing( spacing );<br>     resampler-&gt;SetOutputOrigin( inputImage-&gt;GetOrigin() );<br>     resampler-&gt;SetOutputDirection( inputImage-&gt;GetDirection() );<br>     <br>     ImageType::SizeType   inputSize = inputImage-&gt;GetLargestPossibleRegion().GetSize();<br>
  <br>     typedef ImageType::SizeType::SizeValueType SizeValueType;<br><br>  const double dx = inputSize[0] * inputSpacing[0] / isoSpacing;<br>  const double dy = inputSize[1] * inputSpacing[1] / isoSpacing;<br><br>  const double dz = (inputSize[2] - 1 ) * inputSpacing[2] / isoSpacing;<br>
  <br>  ImageType::SizeType   size;<br><br>  size[0] = static_cast&lt;SizeValueType&gt;( dx );<br>  size[1] = static_cast&lt;SizeValueType&gt;( dy );<br>  size[2] = static_cast&lt;SizeValueType&gt;( dz );<br>  resampler-&gt;SetSize( size );<br>
  resampler-&gt;SetInput( smootherY-&gt;GetOutput() );<br><br>  resampler-&gt;Update();<br>   try <br>    {<br>    cerr &lt;&lt; &quot; resampler update &quot; &lt;&lt; endl;<br>     resampler-&gt;Update();<br>    }<br>    catch (itk::ExceptionObject &amp; err)<br>
    {<br>           cerr &lt;&lt; &quot;Exception &quot;&lt;&lt;endl;<br>           return EXIT_FAILURE;   <br>       }<br>     <br>     <br>    writer-&gt;SetFileName( outputFilename );<br>    <br> <br><br>  writer-&gt;SetInput( resampler-&gt;GetOutput() );<br>
<br>  try <br>    {<br>    cerr &lt;&lt;&quot; the final write &quot;&lt;&lt;endl;<br>    writer-&gt;Update();<br>    }<br>  catch( itk::ExceptionObject &amp; excep )<br>    {<br>    std::cerr &lt;&lt; &quot;Exception caught !&quot; &lt;&lt; std::endl;<br>
    std::cerr &lt;&lt; excep &lt;&lt; std::endl;<br>    }<br>   return EXIT_SUCCESS;<br>}<br><br><br>