[Insight-users] Question on itk::ResampleImageFilter for up and downsampling images
Bill Lorensen
bill.lorensen at gmail.com
Thu Dec 3 11:07:59 EST 2009
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] ;
>> }
>>
>> 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
>>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MetaResample.cxx
Type: application/octet-stream
Size: 5652 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091203/bf5dedf9/attachment.obj>
More information about the Insight-users
mailing list