[vtkusers] Iterate over an image

Francisco Lopez de la Franca franciscolopezdelafranca at gmail.com
Wed Jun 24 07:04:18 EDT 2015


Hi again,
I answer to myself in case it can help someone someday.
I've changed the voxel type to unsigned char and it works as expected, that
is, instead of "int* voxel", I've changed it to "unsigned char* voxel".
Only with this little change it works right.
Greetings.

2015-06-24 12:22 GMT+02:00 Francisco Lopez de la Franca <
franciscolopezdelafranca at gmail.com>:

> 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 =
> static_cast<int*>(_imageData->GetScalarPointer(x,y,z));
>
>                 if ( voxel[0] == 1 ) {
>                     count++;
>                 }
>             }
>         }
>     }
>
> 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.
> /Francisco
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150624/09da9827/attachment.html>


More information about the vtkusers mailing list