vtkImageReslice and vtkImageExtractComponents

Hi All, I have a method in application that uses ImageReslice and ExtractComponents together to etract the slice z from the 3d image m_imageSrc and fill an imagebuffer using the transform xform as follows:


    m_slicer->SetOutputExtent(0, static_cast<int>(size.x) - 1,
                                                0, static_cast<int>(size.y) - 1,
                                                 z, z);

    const int extent[6] = { 0, static_cast<int>(size.x) - 1,
                                      0, static_cast<int>(size.y) - 1,
                                      z, z};


    im->SetDimensions(static_cast<int>(size.x), static_cast<int>(size.y), 1);
    im->AllocateScalars(m_extractor->GetOutput()->GetScalarType(), 1);

and it works properly. Yet I needed to perform the same operation for a small region defined by origin point p and newsize, from the slice (p.z+z) and modified two lines above (parameter to the SetOutputextent and updateExtent) as follows:

    m_slicer->SetOutputExtent(p.x+0, p.x+static_cast<int>(newsize.x) - 1,
                                                p.y+0, p.y+static_cast<int>(newsize.y) - 1,
                                                p.z+z, p.z+z);

    const int extent[6] = {p.x+0, p.x+static_cast<int>(newsize.x) - 1,
                                      p.y+0, p.y+static_cast<int>(newsize.y) - 1,
                                      p.z+z, p.z+z};

It returns a small region in the end, yet it is not the proper part of the image defined by p0&newsize. I also used identity transform for testing to be safe. What am I doing wrong here? Thanks!

Regarding the SetDimension() call, please note that

im->SetDimensions(static_cast<int>(newsize.x), static_cast<int>(newsize.y), 1);

is just a shortcut for

im->SetExtent(0, static_cast<int>(newsize.x) - 1, static_cast<int>(newsize.y) - 1, 0, 0);

But, anyway, for cropping an ROI you can try using SetOutputOrigin() instead.

m_slicer->SetOutputOrigin(p.x, p.y, p.z);
m_slicer->SetOutputExtent(static_cast<int>(newsize.x) - 1, static_cast<int>(newsize.y) - 1, z, z);

Thank you so much for your reply, David. In this case, how should the extent parameter

const int extent[6] = {p.x+0, p.x+static_cast(newsize.x) - 1,
p.y+0, p.y+static_cast(newsize.y) - 1,
p.z+z, p.z+z};

that goes to the vtkImageExtractComponents’s updateExtent be modified in regards to slicer call above?

If used, it should be identical to the OutputExtent of vtkImageReslice.

However, it shouldn’t be necessary at all. Just call Update().