[ITK] [ITK-dev] problems itk resample filter

Pfaehler, EAG (ngmb) e.a.g.pfaehler at umcg.nl
Fri Sep 8 15:12:30 EDT 2017


Thanks Samuel and Matt for the help. However, it is unfortunatly still not working.

I deleted the line resizeFilter->SetTransform, but unfortunately it did not change anything.

Then I tried to set the direction and the origin. But maybe here is the problem. I set as direction the same direction as in the original image because I do not want to have any rotation.

But I am a bit insecure how to set the origin. First I set the origin in the resampled image to the same as in the original image, what did not work.
Then I tried different things, e.g

        origin[0] = origin[0] + inputSpacing[0] * (newWidth - oldWidth);
        origin[1] = origin[1] + inputSpacing[1] * (newHeight - oldHeight);
        origin[2] = origin[2] + inputSpacing[2] * (newDepth - oldDepth);

where newWidth etc is the width of the new image and oldWidth of the original image. And origin[0] is the x value of the original origin etc.

But this was also not working. ( In all of these cases I get an image full of zeros.

If I make originalImage->Print(std::cout) I get the following:

Image (000000000282A800)
  RTTI typeinfo:   class itk::Image<float,3>
  Reference Count: 3
  Modified Time: 705
  Debug: Off
  Object Name:
  Observers:
    none
  Source: (none)
  Source output name: (none)
  Release Data: Off
  Data Released: False
  Global Release Data: Off
  PipelineMTime: 692
  UpdateMTime: 704
  RealTimeStamp: 0 seconds
  LargestPossibleRegion:
    Dimension: 3
    Index: [0, 0, 0]
    Size: [11, 11, 19]
  BufferedRegion:
    Dimension: 3
    Index: [0, 0, 0]
    Size: [11, 11, 19]
  RequestedRegion:
    Dimension: 3
    Index: [0, 0, 0]
    Size: [11, 11, 19]
  Spacing: [3.1819, 3.1819, 2]
  Origin: [48.5757, -171.979, 20.5]
  Direction:
1 0 0
0 1 0
0 0 1

  IndexToPointMatrix:
3.1819 0 0
0 3.1819 0
0 0 2

  PointToIndexMatrix:
0.314278 0 0
0 0.314278 0
0 0 0.5

  Inverse Direction:
1 0 0
0 1 0
0 0 1

  PixelContainer:
    ImportImageContainer (00000000027B59F0)
      RTTI typeinfo:   class itk::ImportImageContainer<unsigned __int64,float>
      Reference Count: 1
      Modified Time: 701
      Debug: Off
      Object Name:
      Observers:
        none
      Pointer: 00000000028542E0
      Container manages memory: true
      Size: 2299
      Capacity: 2299

If I do the same for the resampled image I get:

Image (000000000282B100)
  RTTI typeinfo:   class itk::Image<float,3>
  Reference Count: 2
  Modified Time: 11626
  Debug: Off
  Object Name:
  Observers:
    none
  Source: (000000000282BB80)
  Source output name: Primary
  Release Data: Off
  Data Released: False
  Global Release Data: Off
  PipelineMTime: 11614
  UpdateMTime: 11627
  RealTimeStamp: 0 seconds
  LargestPossibleRegion:
    Dimension: 3
    Index: [0, 0, 0]
    Size: [17, 17, 19]
  BufferedRegion:
    Dimension: 3
    Index: [0, 0, 0]
    Size: [17, 17, 19]
  RequestedRegion:
    Dimension: 3
    Index: [0, 0, 0]
    Size: [17, 17, 19]
  Spacing: [2, 2, 2]
  Origin: [67.6671, -152.888, 20.5]
  Direction:
1 0 0
0 1 0
0 0 1

  IndexToPointMatrix:
2 0 0
0 2 0
0 0 2

  PointToIndexMatrix:
0.5 0 0
0 0.5 0
0 0 0.5

  Inverse Direction:
1 0 0
0 1 0
0 0 1

  PixelContainer:
    ImportImageContainer (00000000027B5EC0)
      RTTI typeinfo:   class itk::ImportImageContainer<unsigned __int64,float>
      Reference Count: 1
      Modified Time: 11625
      Debug: Off
      Object Name:
      Observers:
        none
      Pointer: 0000000002A8D520
      Container manages memory: true
      Size: 5491
      Capacity: 5491

Does that maybe help to find out whats going wrong?

Thanks in advance



________________________________________
Van: Matt McCormick [matt.mccormick at kitware.com]
Verzonden: vrijdag 8 september 2017 15:32
Aan: Pfaehler, EAG (ngmb)
CC: Samuel Gerber; insight-developers at itk.org
Onderwerp: Re: [ITK-dev] [ITK] problems itk resample filter

Hi Elli,

The OutputOrigin and OutputDirection may need to be set so the
sampling grids overlap.

HTH,
Matt

On Fri, Sep 8, 2017 at 9:13 AM, Pfaehler, EAG (ngmb)
<e.a.g.pfaehler at umcg.nl> wrote:
> Thanks, I did this. Now I get an image, with the desired size, but there all
> image values are 0. I get the same when I use linear interpolation…
>
> Does someone know, what could be the reason?
>
>
>
> Thanks in advance,
>
>
>
> Regards
>
>
>
> Elli
>
>
>
> Van: Samuel Gerber [mailto:samuel.gerber at kitware.com]
> Verzonden: vrijdag 8 september 2017 14:51
> Aan: Pfaehler, EAG (ngmb)
> CC: insight-developers at itk.org
> Onderwerp: Re: [ITK] [ITK-dev] problems itk resample filter
>
>
>
> I believe you might need to call resizeFilter2->Update()
>
>
>
>
>
>
>
> On Fri, Sep 8, 2017 at 8:32 AM, Pfaehler, EAG (ngmb)
> <e.a.g.pfaehler at umcg.nl> wrote:
>
> Dear all,
>
>
>
> I would need some help to resample so that it has isotropic voxels in the
> end.
>
> For this, I wanted to use the Nearest Neighbor Interpolator and the
> ResampleFilterType.
>
> My code is running, but the output of the filter has always the dimensions
> [0 0 0], so is not existent.
>
> What am I doing wrong? (see code below)
>
>
>
> Thanks in advance!
>
> Elli
>
>
>
> typedef itk::NearestNeighborInterpolateImageFunction<ImageType, T>
> NearestNeighborInterpolatorType;
>
> typedef itk::ResampleImageFilter<ImageType, ImageType>
> ResampleFilterType;
>
> typedef itk::AffineTransform <double, 3> TransformType;
>
> //use nearest neighbor interpolation
>
> typename NearestNeighborInterpolatorType::Pointer
> nearestNeighborInterpolator = NearestNeighborInterpolatorType::New();
>
> typename ImageType::DirectionType direction;
>
> typename TransformType::Pointer transform = TransformType::New();
>
>     //transform->SetIdentity();
>
> typedef itk::NearestNeighborInterpolateImageFunction<ImageType, double>
> InterpolatorType;
>
> //typedef itk::LinearInterpolateImageFunction<ImageType, double >
> InterpolatorType;
>
> typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
>
>
>
> typename ResampleFilterType::Pointer resizeFilter2 =
> ResampleFilterType::New();
>
> resizeFilter2->SetTransform(transform);
>
>
>
> resizeFilter2->SetInterpolator( interpolator );
>
> resizeFilter2->SetDefaultPixelValue(0);
>
>     //resizeFilter2->SetInterpolator();
>
>
>
> const typename ImageType::SpacingType& inputSpacing = image->GetSpacing();
>
> //sampling
>
> double outputSpacing[3];
>
>     // Fetch original image size
>
>    const typename ImageType::RegionType& inputRegion =
> image->GetLargestPossibleRegion();
>
>    const typename ImageType::SizeType& inputSize = inputRegion.GetSize();
>
>     unsigned int oldWidth = inputSize[0];
>
>     unsigned int oldHeight = inputSize[1];
>
>     unsigned int oldDepth = inputSize[2];
>
>     unsigned int newWidth;
>
>     unsigned int newHeight;
>
>     unsigned int newDepth;
>
>        //get the new height etc of image
>
>        double minimum = inputSpacing[0];
>
>        if (inputSpacing[1]<minimum){
>
>            minimum = inputSpacing[1];
>
>        }
>
>        if (inputSpacing[2] < minimum){
>
>            minimum = inputSpacing[2];
>
>        }
>
>        outputSpacing[0] = minimum;
>
>        outputSpacing[1] = minimum;
>
>        outputSpacing[2] = minimum;
>
>        newWidth = (double) oldWidth * inputSpacing[0]/minimum;
>
>        ewHeight = (double) oldHeight * inputSpacing[1]/minimum;
>
>        newDepth = (double) oldDepth * inputSpacing[2]/minimum;
>
>        // Set the output spacing as specified on the command line
>
>       resizeFilter2->SetOutputSpacing(outputSpacing);
>
>     // Set the computed size
>
>     itk::Size<3> outputSize = { {newWidth, newHeight, newDepth} };
>
>     resizeFilter2->SetSize(outputSize);
>
>     // Specify the input for the resamplers
>
>     resizeFilter2->SetInput(image);
>
>     ImageType::Pointer imageNew = resizeFilter2->GetOutput();
>
>    const typename ImageType::RegionType& outputRegion =
> imageNew->GetLargestPossibleRegion();
>
>        const typename ImageType::SizeType& outputSize2 =
> outputRegion.GetSize();
>
>
>
> ________________________________
>
> De inhoud van dit bericht is vertrouwelijk en alleen bestemd voor de
> geadresseerde(n). Anderen dan de geadresseerde(n) mogen geen gebruik maken
> van dit bericht, het niet openbaar maken of op enige wijze verspreiden of
> vermenigvuldigen. Het UMCG kan niet aansprakelijk gesteld worden voor een
> incomplete aankomst of vertraging van dit verzonden bericht.
>
> The contents of this message are confidential and only intended for the eyes
> of the addressee(s). Others than the addressee(s) are not allowed to use
> this message, to make it public or to distribute or multiply this message in
> any way. The UMCG cannot be held responsible for incomplete reception or
> delay of this transferred message.
>
>
> _______________________________________________
> 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://kitware.com/products/protraining.php
>
> 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://public.kitware.com/mailman/listinfo/insight-developers
>
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
>
>
>
>
>
> --
>
> Samuel Gerber
> R&D Engineer
> Kitware, Inc.
>
> ________________________________
> De inhoud van dit bericht is vertrouwelijk en alleen bestemd voor de
> geadresseerde(n). Anderen dan de geadresseerde(n) mogen geen gebruik maken
> van dit bericht, het niet openbaar maken of op enige wijze verspreiden of
> vermenigvuldigen. Het UMCG kan niet aansprakelijk gesteld worden voor een
> incomplete aankomst of vertraging van dit verzonden bericht.
>
> The contents of this message are confidential and only intended for the eyes
> of the addressee(s). Others than the addressee(s) are not allowed to use
> this message, to make it public or to distribute or multiply this message in
> any way. The UMCG cannot be held responsible for incomplete reception or
> delay of this transferred message.
>
> _______________________________________________
> 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://kitware.com/products/protraining.php
>
> 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://public.kitware.com/mailman/listinfo/insight-developers
>
________________________________
 De inhoud van dit bericht is vertrouwelijk en alleen bestemd voor de geadresseerde(n). Anderen dan de geadresseerde(n) mogen geen gebruik maken van dit bericht, het niet openbaar maken of op enige wijze verspreiden of vermenigvuldigen. Het UMCG kan niet aansprakelijk gesteld worden voor een incomplete aankomst of vertraging van dit verzonden bericht.

The contents of this message are confidential and only intended for the eyes of the addressee(s). Others than the addressee(s) are not allowed to use this message, to make it public or to distribute or multiply this message in any way. The UMCG cannot be held responsible for incomplete reception or delay of this transferred message.
_______________________________________________
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://kitware.com/products/protraining.php

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://public.kitware.com/mailman/listinfo/insight-developers


More information about the Community mailing list