[vtkusers] Iterate over an image

Francisco Lopez de la Franca franciscolopezdelafranca at gmail.com
Wed Jun 24 06:22:13 EDT 2015

Hi everybody,
I've got a 3D image in NIFTI format. It is a binary image with 0 values for
background and 1 values for objects.

I've coded a function to count the number of 1's in the image in the
following way:

int* dims = _imageData->GetDimensions();

    int count= 0;
    int * voxel;
    for (int z = 0; z < dims[2]; z++)
        for (int y = 0; y < dims[1]; y++)
            for (int x = 0; x < dims[0]; x++)
                voxel =

                if ( voxel[0] == 1 ) {

However, this function does not detect any 1 in the image.

I've implemented another function in ITK, by using ITK image iterators, and
the result is the expected. It detects hundreds of voxels with value 1
(also checked with the 3D Slicer tool).

Does anyone know what the problem could be in my VTK code? Does VTK provide
iterators like ITK does?

Thank you very much.
My best regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150624/fb4b04e9/attachment.html>

More information about the vtkusers mailing list