<br>Hi Mike,<br><br>I recently observed similar results using some microscope images (in tiff format).  The solution for me was to have a program input to specify the &quot;real&quot; pixel spacing.  Those input values were given to an itkChangeInformationImageFilter and the output of that filter was fed into the resampler (along with the transform and the spacing etc. from the ChangeInformationFilter), so that everything was in &quot;real world coordinates&quot;.  The output of the resampler was sent to the image writer.<br>
<br><a href="http://www.itk.org/Doxygen316/html/classitk_1_1ChangeInformationImageFilter.html">http://www.itk.org/Doxygen316/html/classitk_1_1ChangeInformationImageFilter.html</a><br><br>Let me know if you want an example src file.<br>
<br>Take care,<br>Darren<br><br><br><br><div class="gmail_quote">On Thu, Jun 4, 2009 at 6:22 AM, Michael Jackson <span dir="ltr">&lt;<a href="mailto:mike.jackson@bluequartz.net">mike.jackson@bluequartz.net</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I took the code directly from the RescaleExample5.cxx and just substituted my reader class in for the &quot;itkImageFileReader&quot; class and I still get a black image. The code is pasted below. The general characteristics of my image are:<br>

<br>
Input Size: 1292,968 (pixels)<br>
Input Origin: 46978.9,48347.8  (Microns)<br>
Input Spacing: 0.207987,0.207987 (Microns/pixel)<br>
Image Center:  47113.3,48448.5 (Microns)<br>
<br>
Is it possible my itkR3DImageIO class is not setting something correctly?<div class="im"><br>
<br>
  const     unsigned int   Dimension = 2;<br>
  typedef   unsigned char  InputPixelType;<br>
  typedef   unsigned char  OutputPixelType;<br>
<br>
  typedef itk::Image&lt; InputPixelType,  Dimension &gt;   InputImageType;<br>
  typedef itk::Image&lt; OutputPixelType, Dimension &gt;   OutputImageType;<br>
<br></div>
  //typedef itk::ImageFileReader&lt; InputImageType  &gt;  ReaderType;<br>
  typedef itkR3DImageIO ReaderType;<div class="im"><br>
  typedef itk::ImageFileWriter&lt; OutputImageType &gt;  WriterType;<br>
<br>
  ReaderType::Pointer reader = ReaderType::New();<br>
  WriterType::Pointer writer = WriterType::New();<br>
<br>
  reader-&gt;SetFileName( argv[1] );<br></div>
  reader-&gt;SetDatasetPath( argv[2]);<br>
  writer-&gt;SetFileName( argv[3] );<br>
<br>
  const double angleInDegrees = 45.0;// atof( argv[3] );<br>
  const double scale          = 0.5; //atof( argv[4] );<div class="im"><br>
<br>
  typedef itk::ResampleImageFilter&lt;<br>
                  InputImageType, OutputImageType &gt;  FilterType;<br>
<br>
  FilterType::Pointer filter = FilterType::New();<br>
<br></div>
  typedef itk::Similarity2DTransform&lt; double &gt;  TransformType;<div class="im"><br>
  TransformType::Pointer transform = TransformType::New();<br></div>
 typedef itk::LinearInterpolateImageFunction&lt;<div class="im"><br>
                       InputImageType, double &gt;  InterpolatorType;<br>
  InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>
<br>
  filter-&gt;SetInterpolator( interpolator );<br>
<br>
  filter-&gt;SetDefaultPixelValue( 0 );<br>
<br></div>
  reader-&gt;Update();<div class="im"><br>
  const InputImageType::SpacingType&amp;<br>
    spacing = reader-&gt;GetOutput()-&gt;GetSpacing();<br>
  const InputImageType::PointType&amp;<br>
    origin  = reader-&gt;GetOutput()-&gt;GetOrigin();<br>
  InputImageType::SizeType size =<br>
      reader-&gt;GetOutput()-&gt;GetLargestPossibleRegion().GetSize();<br>
<br>
  filter-&gt;SetOutputOrigin( origin );<br>
  filter-&gt;SetOutputSpacing( spacing );<br>
  filter-&gt;SetSize( size );<br>
<br>
<br>
  filter-&gt;SetInput( reader-&gt;GetOutput() );<br>
  writer-&gt;SetInput( filter-&gt;GetOutput() );<br>
<br></div>
  TransformType::InputPointType rotationCenter;<br>
  rotationCenter[0] = origin[0] + spacing[0] * size[0] / 2.0;<br>
  rotationCenter[1] = origin[1] + spacing[1] * size[1] / 2.0;<br>
  transform-&gt;SetCenter( rotationCenter );<div class="im"><br>
  const double degreesToRadians = atan(1.0) / 45.0;<br></div>
  const double angle = angleInDegrees * degreesToRadians;<br>
  transform-&gt;SetAngle( angle );<br>
<br>
  transform-&gt;SetScale( scale );<br>
  TransformType::OutputVectorType translation;<br>
<br>
  translation[0] =   13.0;<br>
  translation[1] =   17.0;<br>
<br>
  transform-&gt;SetTranslation( translation );<div class="im"><br>
<br>
  filter-&gt;SetTransform( transform );<br>
<br>
  try<br>
    {<br>
    writer-&gt;Update();<br>
    }<br>
  catch( itk::ExceptionObject &amp; excep )<br>
    {<br></div>
    std::cerr &lt;&lt; &quot;Exception catched !&quot; &lt;&lt; std::endl;<div class="im"><br>
    std::cerr &lt;&lt; excep &lt;&lt; std::endl;<br>
    }<br>
  return EXIT_SUCCESS;<br></div><div class="im">
_________________________________________________________<br>
Mike Jackson                  <a href="mailto:mike.jackson@bluequartz.net" target="_blank">mike.jackson@bluequartz.net</a><br>
BlueQuartz Software                    <a href="http://www.bluequartz.net" target="_blank">www.bluequartz.net</a><br>
Principal Software Engineer                  Dayton, Ohio<br>
<br>
<br>
<br></div><div class="im">
On Jun 3, 2009, at 8:42 PM, Luis Ibanez wrote:<br>
<br>
</div><div><div></div><div class="h5"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
Hi Michael,<br>
<br>
<br>
We define as &quot;Origin&quot; of an image the physical coordinates of its<br>
pixel with index [0,0,0].<br>
<br>
Rotations, are performed by default, with respect to the origin<br>
of the coordinate system (the point with physical coordinates<br>
(0.0, 0.0, 0.0), which doesn&#39;t have to coincide with the first<br>
pixel of the image, nor with the central pixel of the image.<br>
<br>
In ITK we assume that your image is a representation of some<br>
physical reality (for example a patient&#39;s body), and therefore<br>
all transformations should be performed in the context of the<br>
physical coordinates, not the grid of pixels.<br>
<br>
The purpose of the &quot;Origin&quot; is that if you use your physical<br>
image acquisition device (microscope, telescope, CT scanner,<br>
MRI scanner, ultrasound device, lidar...) and you acquire<br>
images of different sections of an object that has a physical<br>
manifestation in the real world, then you should be able to<br>
recreate a mosaic of such real object by simply placing the<br>
images in a common coordinate system according to the coordinates<br>
of their origin.<br>
<br>
<br>
----<br>
<br>
<br>
In order to understand the behavior of the transformations,<br>
you should think of your image in the context of the physical<br>
coordinate system.<br>
<br>
If you want your image to rotate around the one of the pixel<br>
in one of the image corners the you should do the following:<br>
<br>
<br>
 A) Compute the Index of that pixel<br>
<br>
 B) Call image-&gt;TransformIndexToPhysicalPoint( index, point )<br>
    to compute the physical coordinates corresponding to this<br>
    pixel. This transformation will take into account the<br>
    image origin, pixel spacing and image orientation.<br>
<br>
 C) Call transform-&gt;SetCenter( point )<br>
    to tell the transform that you want to use this point<br>
    as the center of rotation.<br>
<br>
 D) Connect the transform to the resample filter.<br>
<br>
 E) call Update() in the resample filter.<br>
<br>
<br>
<br>
Please let us know if you still find any problem,<br>
<br>
<br>
   Thanks,<br>
<br>
<br>
      Luis<br>
<br>
<br>
<br>
---------------------------<br>
Michael Jackson wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Just to follow up with this, If I force my origins to be (0,0) then  the rotation seems to work. So I guess I am not understanding what  exactly the origins are? I have reread through several sections of the  ITK guide and I thought I had it figured out. The origins of where the  image is taken is actually stored in our data files so I just thought  I would use that. The values are in Microns and are typically around  the 48,000 to 50,000 range.<br>

Is there an implicit units (like mm) in vtkImage that I don&#39;t know  about? I just can not get this figured out.<br>
Explanations are truly appreciated at this point.<br>
_________________________________________________________<br>
Mike Jackson                  <a href="mailto:mike.jackson@bluequartz.net" target="_blank">mike.jackson@bluequartz.net</a><br>
BlueQuartz Software                    <a href="http://www.bluequartz.net" target="_blank">www.bluequartz.net</a><br>
Principal Software Engineer                  Dayton, Ohio<br>
On Jun 3, 2009, at 5:50 PM, Michael Jackson wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I am trying to rotate an image about the &quot;upper left&quot; corner. I had  to write my own ImageSource derived class to read the data from and  HDF5 file. I am pretty sure the &quot;Hdf5 reader&quot; works as I can create  the ImageReader instance from it, read an image and write the image  to disk as a tiff file.<br>

<br>
Where my code seems to be failing is in the application of an  AffineTransformFilter. I am basically taking the code straight from  one of the examples adapting it to use my ImageSource derived reader  and running it. And I get the dreaded &quot;black image&quot;. Here is the  code and the output from the program. Oddly, if I switch the reader  back to the usual ImageFileReader and read up a tiff image I get the  correct result, so maybe my custom reader class is not quite correct?<br>

<br>
<br>
#define USE_MXA_FILE 1<br>
int main(int argc, char **argv) {<br>
int exampleAction =0;<br>
const     unsigned int   Dimension = 2;<br>
typedef   unsigned char  InputPixelType;<br>
typedef   unsigned char  OutputPixelType;<br>
<br>
typedef itk::Image&lt; InputPixelType,  Dimension &gt;   InputImageType;<br>
typedef itk::Image&lt; OutputPixelType, Dimension &gt;   OutputImageType;<br>
<br>
#if USE_MXA_FILE<br>
typedef itkR3DImageIO  ReaderType;<br>
#else<br>
typedef itk::ImageFileReader&lt; InputImageType &gt;  ReaderType;<br>
#endif<br>
typedef itk::ImageFileWriter&lt; OutputImageType &gt;  WriterType;<br>
<br>
ReaderType::Pointer reader = ReaderType::New();<br>
WriterType::Pointer writer = WriterType::New();<br>
<br>
reader-&gt;SetFileName( argv[1] );<br>
#if USE_MXA_FILE<br>
reader-&gt;SetDatasetPath(argv[2]);<br>
#endif<br>
reader-&gt;Update();<br>
writer-&gt;SetFileName( argv[3]);<br>
typedef itk::ResampleImageFilter&lt;InputImageType, OutputImageType &gt;   FilterType;<br>
FilterType::Pointer filter = FilterType::New();<br>
typedef itk::AffineTransform&lt; double, Dimension &gt;  TransformType;<br>
TransformType::Pointer transform = TransformType::New();<br>
<br>
typedef  itk::NearestNeighborInterpolateImageFunction&lt;InputImageType, double  &gt;  InterpolatorType;<br>
InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>
filter-&gt;SetInterpolator( interpolator );<br>
filter-&gt;SetDefaultPixelValue( 0 );<br>
const InputImageType::SpacingType&amp; spacing = reader-&gt;GetOutput()- &gt;GetSpacing();<br>
const InputImageType::PointType&amp; origin = reader-&gt;GetOutput()- &gt;GetOrigin();<br>
InputImageType::SizeType size = reader-&gt;GetOutput()- &gt;GetLargestPossibleRegion().GetSize();<br>
filter-&gt;SetOutputOrigin( origin );<br>
filter-&gt;SetOutputSpacing( spacing );<br>
filter-&gt;SetSize( size );<br>
<br>
filter-&gt;SetInput( reader-&gt;GetOutput() );<br>
writer-&gt;SetInput( filter-&gt;GetOutput() );<br>
<br>
std::cout &lt;&lt; &quot;Input Size: &quot; &lt;&lt; size[0] &lt;&lt; &quot;,&quot; &lt;&lt; size[1] &lt;&lt;  std::endl;<br>
std::cout &lt;&lt; &quot;Input Origin: &quot; &lt;&lt; origin[0] &lt;&lt; &quot;,&quot; &lt;&lt; origin[1] &lt;&lt;  std::endl;<br>
std::cout &lt;&lt; &quot;Input Spacing: &quot; &lt;&lt; spacing[0] &lt;&lt; &quot;,&quot; &lt;&lt; spacing[1]  &lt;&lt; std::endl;<br>
<br>
TransformType::OutputVectorType translation1;<br>
translation1[0] =   -origin[0];<br>
translation1[1] =   -origin[1];<br>
transform-&gt;Translate( translation1 );<br>
<br>
const double degreesToRadians = atan(1.0) / 45.0;<br>
transform-&gt;Rotate2D( -10.0 * degreesToRadians, false );<br>
<br>
TransformType::OutputVectorType translation2;<br>
translation2[0] =   origin[0];<br>
translation2[1] =   origin[1];<br>
transform-&gt;Translate( translation2, false );<br>
filter-&gt;SetTransform( transform );<br>
try<br>
  {<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>
<br>
return EXIT_SUCCESS;<br>
}<br>
<br>
<br>
output:<br>
GenerateData()<br>
GenerateData()<br>
Input Size: 1292,968<br>
Input Origin: 46978.9,48347.8<br>
Input Spacing: 0.207987,0.207987<br>
GenerateData()<br>
<br>
Any help would be great.<br>
_________________________________________________________<br>
Mike Jackson                  <a href="mailto:mike.jackson@bluequartz.net" target="_blank">mike.jackson@bluequartz.net</a><br>
BlueQuartz Software                    <a href="http://www.bluequartz.net" target="_blank">www.bluequartz.net</a><br>
Principal Software Engineer                  Dayton, Ohio<br>
<br>
<br>
<br>
</blockquote>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><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>
Please keep messages on-topic and check the ITK FAQ at: <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><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>
</blockquote></blockquote>
<br>
_____________________________________<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: <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>
</div></div></blockquote></div><br>