I’m trying to extract pixel values from each slice in a stack of slices by drawing a contour curve. I’m getting a curve like this. How can I extract the pixel values which are inside the curve line?
This is my code
vtkSmartPointer contourPoints = vtkSmartPointer::New();
for (int i = 0; i < numNodes; ++i) {
double node[3];
contourRep->GetNthNodeWorldPosition(i, node);
vtkIdType id = contourPoints->InsertNextPoint(node);
if (i > 0) {
contourLines->InsertNextCell(2);
contourLines->InsertCellPoint(id - 1);
contourLines->InsertCellPoint(id);
}
}
You did not get the expected result because used the curve control points as input of the probe filter. You should have used the interpolated curve points as probe filter input.
The values inside contourPolyData when printed is this (since we are selecting points on a 2D)
Point 0 : 79.0363 120.503 0
Point 1 : 92.7065 146.932 0
Point 2 : 107.288 194.322 0
Do we need to give Z coordinate value other than 0 to get a 3D curve? Also if I interpolate the point do I need to take the scalar value?
The widget shows the smooth interpolated curve, so you may be able to get the points you need from the widget or representation object.
If you have trouble figuring this out then you may switch from VTK core to the higher-level VTK classes provided by 3D Slicer. You can use these classes in C++, Python scripting, and/or graphical user interface.