[Insight-users] Insight-users Digest, Vol 67, Issue 85

Simon Warfield simon.warfield at childrens.harvard.edu
Mon Nov 16 10:00:01 EST 2009


insight-users-request at itk.org wrote:

> Date: Mon, 16 Nov 2009 11:28:50 +0100
> From: stan <stan.oubel at gmail.com>
> Subject: Re: [Insight-users] Boundary problem when resampling?
> To: Bill Lorensen <bill.lorensen at gmail.com>
> Cc: itk-users <insight-users at itk.org>
> Message-ID: <1258367330.23212.161.camel at tapies.u-strasbg.fr>
> Content-Type: text/plain; charset=utf-8
>
> Hi again Bill
>
> I would like to understand what the flag
> ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY does ...
>
> Could you explain what's the difference with respect to physical
> coordinates when this flag is ON and OFF?
>
>   

With this flag OFF, some of the code considers the coordinates of a 
pixel index to  indicate the center of a pixel,
and some of the code consider the coordinates of a pixel index to be a 
corner of the pixel. This causes errors when doing certain resampling 
operations,
and with certain boundary calculations, as these combined code paths 
with different conventions.

With the flag ON, all of the code considers the coordinates of a pixel 
index to indicate the center of a pixel, and boundary calculations etc. 
are consistent with this notion.
This convention matches the documentation of the physical coordinate 
system in the software guide.

--Simon
> Thanks !
>
> stan
>
>
>
> Le lundi 16 novembre 2009 ? 09:47 +0100, stan a ?crit :
>   
>> Thanks a lot Bill, now it works correctly.
>>
>> stan
>>
>>
>> Le vendredi 13 novembre 2009 ? 11:12 -0500, Bill Lorensen a ?crit :
>>     
>>> Statring in 3.16 we made the default for
>>> ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY to be ON.
>>>
>>> In 3.14 the default was OFF. If you have not turned this on in your
>>> build, can you try that.
>>>
>>> Bill
>>>
>>> On Fri, Nov 13, 2009 at 11:02 AM, stan <stan.oubel at gmail.com> wrote:
>>>       
>>>> I'm using itk 3.14 ...
>>>>
>>>>
>>>> Le vendredi 13 novembre 2009 ? 10:52 -0500, Bill Lorensen a ?crit :
>>>>         
>>>>> What version of itk are you using?
>>>>>
>>>>> On Fri, Nov 13, 2009 at 10:13 AM, stan <stan.oubel at gmail.com> wrote:
>>>>>           
>>>>>> Dear all,
>>>>>>
>>>>>> I'm using the ITK resampling filter to upscale 3D images
>>>>>> (BSplineInterpolateImageFunction).
>>>>>>
>>>>>> I encountered two problems with this filter:
>>>>>>
>>>>>> - there is a misregistration between high-resolution images and
>>>>>> resampled low-resolution images. To correct that, I modified the origin
>>>>>> ( origin = origin - spacing/2). Now images are well registered,
>>>>>>
>>>>>> - but now, there is a problem at image boundaries. All voxels close to
>>>>>> the boundary (less than spacing/2 in all directions) are set to zero.
>>>>>> This is incorrect since the size of the low-resolution have been setup
>>>>>> to be exactly a multiple of the high-resolution image size.
>>>>>>
>>>>>> Here a screenshot and some code I use.
>>>>>>
>>>>>> Thank you
>>>>>>
>>>>>> stan
>>>>>>
>>>>>>
>>>>>>
>>>>>>  typedef short      PixelType;
>>>>>>  const   unsigned int        Dimension = 3;
>>>>>>  typedef itk::Image< PixelType, Dimension >    ImageType;
>>>>>>  typedef itk::ImageFileReader< ImageType >  ReaderType;
>>>>>>  typedef itk::ImageFileWriter< ImageType >  WriterType;
>>>>>>  ReaderType::Pointer reader = ReaderType::New();
>>>>>>  ReaderType::Pointer reader_input = ReaderType::New();
>>>>>>  WriterType::Pointer writer = WriterType::New();
>>>>>>
>>>>>>  //Reading reference image
>>>>>>  reader->SetFileName( reference_file  );
>>>>>>  reader->Update();
>>>>>>  ImageType::Pointer referenceImage = reader->GetOutput();
>>>>>>
>>>>>>  //Reading input image
>>>>>>  reader_input->SetFileName( input_file  );
>>>>>>  reader_input->Update();
>>>>>>  ImageType::Pointer inputImage = reader_input->GetOutput();
>>>>>>
>>>>>>  typedef itk::ResampleImageFilter<ImageType,ImageType> FilterType;
>>>>>>  FilterType::Pointer filter = FilterType::New();
>>>>>>
>>>>>>  typedef itk::AffineTransform< double, Dimension >  TransformType;
>>>>>>  TransformType::Pointer transform = TransformType::New();
>>>>>>  transform -> SetIdentity();
>>>>>>  filter->SetTransform( transform );
>>>>>>
>>>>>>  typedef itk::BSplineInterpolateImageFunction< ImageType, double, int
>>>>>>  >  InterpolatorType;
>>>>>>
>>>>>>  InterpolatorType::Pointer interpolator = InterpolatorType::New();
>>>>>>  interpolator->SetSplineOrder(interp);
>>>>>>  filter->SetInterpolator( interpolator );
>>>>>>
>>>>>>  filter->SetDefaultPixelValue( 0 );
>>>>>>
>>>>>>  //Initialize with reference image information
>>>>>>  filter->SetOutputSpacing( referenceImage->GetSpacing() );
>>>>>>
>>>>>>  ImageType::SpacingType spacing = inputImage->GetSpacing();
>>>>>>  ImageType::PointType origin = inputImage->GetOrigin();
>>>>>>  origin[0] -= spacing[0]/2;
>>>>>>  origin[1] -= spacing[1]/2;
>>>>>>  origin[2] -= spacing[2]/2;
>>>>>>
>>>>>>  filter->SetOutputOrigin( origin );
>>>>>>
>>>>>>  filter->SetSize( referenceImage->GetLargestPossibleRegion().GetSize() );
>>>>>>
>>>>>>  //Do the resampling
>>>>>>  filter->SetInput( inputImage );
>>>>>>  filter->Update();
>>>>>>  ImageType::Pointer outputImage = filter->GetOutput();
>>>>>>
>>>>>>  //Saving the result
>>>>>>  writer->SetFileName( output_file );
>>>>>>  writer->SetInput( outputImage );
>>>>>>  writer->Update();
>>>>>>
>>>>>>
>>>>>> _____________________________________
>>>>>> Powered by www.kitware.com
>>>>>>
>>>>>> Visit other Kitware open-source projects at
>>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>>
>>>>>> Kitware offers ITK Training Courses, for more information visit:
>>>>>> http://www.kitware.com/products/protraining.html
>>>>>>
>>>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>>>
>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>>>
>>>>>>
>>>>>>             
>>>>         
>
>
>   


-- 
Simon 



More information about the Insight-users mailing list