[vtkusers] Image Resampling
andrew.crozier at medunigraz.at
Fri Sep 5 18:08:43 EDT 2014
If anyone following up this thread is interested, I settled on a
solution using a python/numpy C extension.
We were already doing some array operations using numpy in this project,
and a small python C module is fast and easy to build on new systems
(whereas building vtk and python bindings from source is non-trivial -
at present we use vanilla vtk from system package managers).
On 05/09/14 11:46, Andrew Crozier wrote:
> Hi David,
> Thanks very much for the feedback. Your code has given some good ideas.
> On 04/09/14 17:59, David Gobbi wrote:
>> Hi Andrew,
>> The "masking" part is what makes this especially tricky. Also, the NN
>> interpolator is very specifically a "nearest neighbor" interpolator,
>> its code would have to be changed drastically in order for it to
>> instead look for the "nearest neighbor that has a value of X or Y".
>> It would need a whole new inner loop to perform the search.
>> I have a class that doesn't do quite what you need, but it might
>> provide you with ideas: it is an interpolator specifically written for
>> label images. It models the voxel positions as random variables
>> (Gaussian) and, for each voxel in the resampled image, it finds the
>> highest-probability label for that voxel. It does not, however, allow
>> you to ignore specific label values.
>> - David
>> On Thu, Sep 4, 2014 at 7:00 AM, Andrew Crozier
>> <andrew.crozier at medunigraz.at> wrote:
>>> 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
>>> smoothing operation to the surface mesh with numpy in python, then
>>> 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
>>> 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
>>> and 12 and 13 are assigned ones. The surface is extracted, smoothed,
>>> 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
>>> nearest neighbour' approach, meaning that each zero pixel in the
>>> 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
>>> but where pixels with a 12 or 13 value are ignored. The equivaltent
>>> 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
>>> sets can be quite large. I have fairly limited experience using vtk and
>>> would appreciate any suggestions or pointers on how to achieve the
>>> Best wishes,
> Powered by www.kitware.com
> Visit other Kitware open-source projects at
> Please keep messages on-topic and check the VTK FAQ at:
> Follow this link to subscribe/unsubscribe:
More information about the vtkusers