[Insight-users] Revisiting resampling

Richard Beare richard.beare at gmail.com
Mon Mar 8 18:40:16 EST 2010


Hi,
I thought I had sorted out the resampling issue I raised in earlier
messages, with my error being caused by failing to set an output
index. However there are still some problems setting the size.
Basically things aren't quite working using the "obvious" approach and
I assume I'm missing something simple.

I'm upsampling an image by specifying new spacing (a factor of 2 in my
test cases). I'm not resampling into the space of an existing image,
so I need to set things manually. The other oddity is that the image
is a subset that I've extracted from a larger image. My problem is
that the "last" planes of the 3D volume, that is those planes with the
highest index, are all blank, indicating that I'm sampling outside of
my volume. However, I don't think I should be.

Here's how I'm setting the values:

  typename RawIm::IndexType idx = input->GetLargestPossibleRegion().GetIndex();
  for (int i = 0; i < dim; i++)
    {
    float factor = inputSpacing[i]/NewSpacing[i];
    size[i] = static_cast< SizeValueType >( inputSize[i] * factor);
    idx[i] *= factor;
    }

  resampler->SetSize( size );
  resampler->SetOutputSpacing( NewSpacing );
  resampler->SetOutputOrigin( input->GetOrigin() );

  // need to be careful setting the index
  resampler->SetOutputStartIndex ( idx );
  resampler->SetOutputDirection(input->GetDirection());

I suspect that I'm miss-indexing somewhere, or there is an interaction
between size and index that I'm missing. I can't see any reason why I
shouldn't be able to request a new spacing that is half the original
and not get twice as many voxels in each dimension.

The image I'm trying to upsample is:

Image (0x2f74460)
  RTTI typeinfo:   itk::Image<short, 3u>
  Reference Count: 3
  Modified Time: 212
  Debug: Off
  Observers:
    none
  Source: (0x2f72400)
  Source output index: 0
  Release Data: Off
  Data Released: False
  Global Release Data: Off
  PipelineMTime: 203
  UpdateMTime: 213
  LargestPossibleRegion:
    Dimension: 3
    Index: [103, 95, 0]
    Size: [40, 40, 30]
  BufferedRegion:
    Dimension: 3
    Index: [103, 95, 0]
    Size: [40, 40, 30]
  RequestedRegion:
    Dimension: 3
    Index: [103, 95, 0]
    Size: [40, 40, 30]
  Spacing: [1.25, 1.25, 5]
  Origin: [-160.625, 120.062, -4.8184]
  Direction:
1 0 0
0 -1 0
0 0 1

  IndexToPointMatrix:
  1.25 0 0
0 -1.25 0
0 0 5

  PointToIndexMatrix:
  0.8 0 0
0 -0.8 0
0 0 0.2

  PixelContainer:
    ImportImageContainer (0x2f74260)
      RTTI typeinfo:   itk::ImportImageContainer<unsigned long, short>
      Reference Count: 1
      Modified Time: 211
      Debug: Off
      Observers:
        none
      Pointer: 0x2e1b000
      Container manages memory: true
      Size: 48000
      Capacity: 48000


More information about the Insight-users mailing list