Create new segment from binary vtkimagedata object

Hello,
I create a 3D vtkImageData objet using this code:

``
vtkNew imageTumor;
** imageTumor->SetExtent(0, 100, 0, 100, 0, 100);**
** imageTumor->AllocateScalars(VTK_DOUBLE, 1);**
** imageTumor->SetSpacing(1.5, 2.25, 8);**
** imageTumor->SetOrigin(0.0, 0.0, 0.0);**
** int* extent = imageTumor->GetExtent();**


And I inisilize this image by 0 and 1 depending on a certain conditions,  using this code:

for (int x = extent[0]; x < extent[1]; x++)
** {**
** for (int y = extent[2]; y < extent[3]; y++)**
** {**
** for (int z = extent[4]; z < extent[5]; z++)**
** {**
** if(imageMTT->GetScalarComponentAsDouble(x, y, z, 0)>150)**
** imageTumor->SetScalarComponentFromDouble(x, y, z, 0, 1.0);**
** else**
** imageTumor->SetScalarComponentFromDouble(x, y, z, 0, 0.0);**
** }**
** }**
** }**


the question is how can visualize this image? i don't know if we can transform a vtkimagedata ona segment. any ideas to help me.
thanks

You can import a vtkImageData into a vtkMRMLSegmentationNode using ImportLabelmapToSegmentationNode method.

A small comment: GetScalarComponentAsDouble is intended for testing or get/set single values in a volume. It is not intended for filling an entire volume. It may be 10x or more slower than using VTK image filters or iterating through an image using a pointer. The loop in the example above is also much slower because the hottest loop jumps between slices instead of processing neighbor voxels (for (int x... for (int y... for (int z... should be changed to for (int z... for (int y... for (int x...). Processing all voxels in a single thread also slows down the operation. I would recommend to either learn more about how to implement image processing filters or use existing VTK filters to achieve reasonable processing speed. If you describe the processing you want to do (initialize this image by 0 and 1 depending on a certain conditions) then we may give advice on how to fill the volume more efficiently.

thanks for your responce and the important comment

I try to select the value of Perfusion parameters (MTT, TPP, rCBV, rCBF) from a vtkImageData object. And depending on those parameters, Idecide whether this voxel contains tumors or not.
After this, we obtain a vtkImagedata object (0 or 1) I need to visualize this object…
thanks

I believe you could use simpleITK for creating the label map from a numpy array. Should be easier I think.

Hope it helps

I agree that it would make sense to start prototyping in Python and then if you need better speed then vectorize the code and/or port slowest parts to C++. By “vectorizing” the operations I mean process an entire line, slice, or volume of voxels at a time (using numpy, ITK, or other tools) then you may be able to implement the whole computation in Python.

Note that there have been previous projects for processing time-resolved images, such PK modeling extension for analyzing DCE-MRI.

I’m not sure if there are CT perfusion modeling extensions (or algorithms that could be easily converted to extensions) for computing MTT, TP, rCBV, rCBF. @fedorov has features like this been developed as part of the QIICR project?

1 Like

No, nothing like that was done in QIICR. There is also this relevant extension, but it is for PET: Documentation/Nightly/Modules/dPetBrainQuantification - Slicer Wiki.

1 Like