[Insight-users] Question on itk::ResampleImageFilter for up and downsampling images

Lodron, Gerald Gerald.Lodron at joanneum.at
Thu Dec 3 11:41:29 EST 2009


I already saw that but i want to allow upscaling as well as downscaling (and i think the shrink filter is only for one direction). The other thing is that i want also to specify the up/downscaling per direction (anisotropic, the shrink filter makes it isotropic). I read DICOM images so i should not change the position of the image at all (the images which should be down/upscaled are registered and should also be registered after  up/downscaling). 


 

-----Ursprüngliche Nachricht-----
Von: Bill Lorensen [mailto:bill.lorensen at gmail.com]
Gesendet: Donnerstag, 03. Dezember 2009 17:36
An: Lodron, Gerald
Cc: insight-users at itk.org
Betreff: Re: [Insight-users] Question on itk::ResampleImageFilter for up and downsampling images

Gerald,

Another approach we used in itkShrinkImageFIlter modifies the origin of the output so that the center's of the input and output align. I think this is what you want. Here is a snippet from Code/BasicFilters/itkShrinkImageFilter.txx. In your case, the input and output start index should be 0.

  // Compute origin offset
  // The physical center's of the input and output should be the same
  ContinuousIndex<double, TOutputImage::ImageDimension> inputCenterIndex;
  ContinuousIndex<double, TOutputImage::ImageDimension> outputCenterIndex;
  for (i = 0; i < TOutputImage::ImageDimension; i++)
    {
    inputCenterIndex[i] = inputStartIndex[i] + (inputSize[i] - 1) / 2.0;
    outputCenterIndex[i] = outputStartIndex[i] + (outputSize[i] - 1) / 2.0;
    }

  typename TOutputImage::PointType inputCenterPoint;
  typename TOutputImage::PointType outputCenterPoint;
  inputPtr->TransformContinuousIndexToPhysicalPoint(inputCenterIndex,
inputCenterPoint);
  outputPtr->TransformContinuousIndexToPhysicalPoint(outputCenterIndex,
outputCenterPoint);

  typename TOutputImage::PointType outputOrigin = outputPtr->GetOrigin();
  outputOrigin = outputOrigin + (inputCenterPoint - outputCenterPoint);
  outputPtr->SetOrigin(outputOrigin);



On Thu, Dec 3, 2009 at 11:07 AM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> Sorry I read your e-mail too quickly.
> Attached is code I wrote a while back. It keep the same origin, but 
> adjusts the spacing.
>
> Bill
>
> On Thu, Dec 3, 2009 at 10:37 AM, Lodron, Gerald 
> <Gerald.Lodron at joanneum.at> wrote:
>> No, i am already using 3.16 and i did not changed such a flag.
>>
>> Best regards
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Bill Lorensen [mailto:bill.lorensen at gmail.com]
>> Gesendet: Donnerstag, 03. Dezember 2009 16:35
>> An: Lodron, Gerald
>> Cc: insight-users at itk.org
>> Betreff: Re: [Insight-users] Question on itk::ResampleImageFilter for 
>> up and downsampling images
>>
>> What version of itk are you using? Prior to itk 3.16 there was an issue with the location of sample points. IN 3.16 we changed the default for ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY to be ON.
>> This made itk consistent with the behavior described in the software guide. It also corrected the 1/2 pixel offset you are seeing when down/up sampling.
>>
>> If you are using 3.14, you can set
>> ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY ON when you run cmake.
>>
>> Bill
>>
>> On Thu, Dec 3, 2009 at 9:49 AM, Lodron, Gerald <Gerald.Lodron at joanneum.at> wrote:
>>>
>>>
>>> Hello,
>>>
>>> I want to write a code to reduce/increase the resolution of an image and i am using the itk::ResampleImageFilter. The code works fine but there is one small problem: When i compare the original and the resampled image with a checkerboard i see that the images are not registered any more (so there must be a problem with the origin). How should i set the origin? Here my code:
>>>
>>> Input:
>>>
>>> Int *iDownsampleFactor;                                 // = e.g.
>>> {2,0.5,4}; Itk::OrientedImage<PixelType ,3>::Pointer image;
>>>
>>> Code:
>>>
>>> Typedef itk::ResampleImageFilter<InputImageType, OutputImageType,
>>> InterpolationPrecisionType> ResampleType;
>>>
>>> ResampleType::Pointer  resampler = ResampleType::New();
>>>
>>> OutputImageType::SpacingType                    Spacing; 
>>> OutputImageType::PointType                      Origin; 
>>> OutputImageType::DirectionType          Direction =
>>> image->GetDirection(); OutputImageType::SizeType
>>> Size; OutputImageType::RegionType::IndexType  Index =
>>> image->getLargestPossibleRegion().GetIndex();
>>>
>>> For (int i=0; i<3; i++)
>>> {
>>>        Spacing[i] = image->GetSpacing()[i] * iDownsampleFactor[i] ;
>>>        Origin[i] = image->GetOrigin()[i];//????????????????????
>>>        Size[i] =
>>> image->GetLargestPossibleRegion().GetSize()[i]/iDownsampleFactor[i]
>>> image->;
>>> }
>>>
>>> Resampler->SetInput(image);
>>> resampler->SetOutputSpacing( Spacing ); SetOutputOrigin(  Origin  ); 
>>> resampler->SetOutputDirection(  Direction  ); SetSize( Size ); 
>>> resampler->SetOutputStartIndex(  Index );
>>>
>>> Output = resampler->GetOutput();        //Wrong 
>>> alignment/registration to input
>>>
>>> Best regards
>>>
>>>
>>> _____________________________________
>>> 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
>>>
>>
>


More information about the Insight-users mailing list