How to measure CT values within the region of interest on MPR images?

Hello,
How to measure CT values within the region of interest on MPR images. Such as maximum value, minimum value, mean square deviation, etc. Any reply will be appreciated.

You can use vtkImageHistogramStatistics with a stencil to get basic statistics (min, max, mean, stdev). You can compute a lot of features using ITK (SimpleITK or ITKPython), too. If you need even more then you can get the voxel data as a numpy array and use numpy, scipy, etc. packages.

Thanks for you reply. Can you show me some examples?

You can find examples on the VTK examples website or generate them using AI assistants such as Microsoft Copilot or ChatGPT.

I created an elliptical region as the area of interest and counted the values within it, but got the wrong result. I don’t know where the mistake lies, here is the code:

int extent[6];
double spacing[3];
double origin[3];
reader->GetOutput()->GetExtent(extent);
reader->GetOutput()->GetSpacing(spacing);
reader->GetOutput()->GetOrigin(origin);

double center[3];
center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]);
center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]);
center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]);

vtkNew<vtkEllipseArcSource> ellipse;
ellipse->SetCenter(center);
ellipse->SetSegmentAngle(360);
ellipse->SetRatio(2.0);
ellipse->SetStartAngle(0);
ellipse->SetMajorRadiusVector(50, 0, 0);
ellipse->SetNormal(0, 0, 1);
ellipse->Update();

vtkNew<vtkPolyDataToImageStencil> imageStencil;
imageStencil->SetInputData(ellipse->GetOutput());
imageStencil->SetOutputOrigin(origin[0], origin[1], 0);
imageStencil->SetOutputSpacing(spacing[0], spacing[1], 1);
int* re = reslice->GetOutputExtent(); 
int ex[6] = { re[0], re[1], re[2], re[3], 0, 0 };
imageStencil->SetOutputWholeExtent(ex);
imageStencil->Update();

vtkNew<vtkImageHistogramStatistics> statics;
statics->SetInputConnection(reslice->GetOutputPort());   //vtkImageSlabReslice* reslice
statics->SetStencilData(imageStencil->GetOutput());
statics->GenerateHistogramImageOff();
statics->Update();
double dmax = statics->GetMaximum();
double dmin = statics->GetMinimum();
double dsq = statics->GetStandardDeviation();

Anyone can help me check this code?

@ Jaswant Panchumarti (Kitware)jaswantp @ Andras Lasso @ Lucas Givord (Kitware)
Hi guys, can you help me solve this problem?

Polygon source, stencil, histogram statistics connected looks good. The code snippet is incomplete (we don’t know the image geometry, we don’t know how the reslice filter is set up), so we could only guess what’s wrong.

It can help you if you view the output of each filter in an image viewer. For prototyping and getting to know VTK, I would recommend using Python instead of C++, with PyVista (to visualize with scripting) or 3D Slicer (to visualize with an interactive GUI).

Hi Andras,
Thank you for your prompt reply. The image is an axis direction MPR image with an ellipse drawn on it. I want to calculate the values of the elliptical region, as shown in the figure. And here is the definition of ‘reslice’:
vtkNew< vtkResliceCursor> resliceCursor;
vtkNew resliceCursorWidget;
vtkNew resliceCursorRep;
resliceCursorWidget->SetInteractor(interactor);
resliceCursorWidget->SetRepresentation(resliceCursorRep);
resliceCursorRep->GetResliceCursorActor()->GetCursorAlgorithm()->SetReslicePlaneNormal(2);
resliceCursorRep->GetResliceCursorActor()->GetCursorAlgorithm()->SetResliceCursor(resliceCursor);
vtkImageSlabReslice* reslice = vtkImageSlabReslice::SafeDownCast(resliceCursorRep->GetReslice());
image