[vtkusers] Image Resampling

Andrew Crozier andrew.crozier at medunigraz.at
Thu Sep 4 09:00:47 EDT 2014

I and a colleague are working on an image segmentation problem, where we 
use marching cubes to generate the surface of a segmentation, apply a 
custom smoothing operation to the surface mesh with numpy in python, 
then re-render as a vtk image at an arbitrary higher resolution before 
writing out for the rest of our workflow.

The original data set is, however, not simply a binary data set, but 
both the 'ones' and 'zeros' are further subdivided into integer 'tag' 
values. We would like to map said tags to the resampled image, but I am 
trying to figure out the most efficient way to do that in VTK.


Say, for example, we have an image with four 'tags'; 10, 11, 12 and 13. 
10 and 11 are assigned a zero value for the surface extraction and 
smoothing, and 12 and 13 are assigned ones. The surface is extracted, 
smoothed, and resampled image generated, which now also has ones and 
zeros as values. I would now like to reassign the appropriate tags, such 
that zeros always become either 10 or 11 and ones become either 12 or 13.

Conceptually, I consider this problem as requiring something like a 
'masked nearest neighbour' approach, meaning that each zero pixel in the 
resampled image should be assigned the tag of the spatially closest 10 
or 11 pixel in the original image. I say masked nearest neighbour as it 
seems equivalent to a nearest neighbour interpolation (such as by using 
vtkImageInterpolator) but where pixels with a 12 or 13 value are 
ignored.  The equivaltent mapping would of course be done for 'one' 
pixels in the resampled image, finding the closest in the original with 
a 12 or 13 value.


I could, or course, implement this algorithm in pure python as part of 
my script, but I am keen not to do so unless necessary as the resampled 
data sets can be quite large. I have fairly limited experience using vtk 
and would appreciate any suggestions or pointers on how to achieve the 
desired result.

Best wishes,

More information about the vtkusers mailing list