# Can we use vtkprobefilter to extract data along a curve in a volume?

**URL:** <https://discourse.vtk.org/t/can-we-use-vtkprobefilter-to-extract-data-along-a-curve-in-a-volume/14038>\
**Category:** Development\
**Created:** [June 13, 2024, 1:15pm UTC](https://discourse.vtk.org/t/can-we-use-vtkprobefilter-to-extract-data-along-a-curve-in-a-volume/14038 "2024-06-13T13:15:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kiran\_shaji](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kiran_shaji/32/8880_2.png) [@Kiran\_shaji](https://discourse.vtk.org/u/Kiran_shaji)\
**Post date:** [June 13, 2024, 1:15pm UTC](https://discourse.vtk.org/t/can-we-use-vtkprobefilter-to-extract-data-along-a-curve-in-a-volume/14038/1 "2024-06-13T13:15:09Z")

</div>

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);  
}  
}

contourPolyData-\>SetPoints(contourPoints);  
contourPolyData-\>SetLines(contourLines);

vtkSmartPointer probeFilter = vtkSmartPointer::New();  
probeFilter-\>SetInputData(contourPolyData); // Input: contour  
probeFilter-\>SetSourceData(combinedImageData); // Source: DICOM image  
probeFilter-\>Update();

 ![image](https://discourse.vtk.org/uploads/default/original/2X/e/e2b751d7c36c3b096aca21779be4e877787f765e.png)  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/3/36b5cdc71a1a8b915d2788ded3280b2d0b59aff7.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [June 15, 2024, 2:57am UTC](https://discourse.vtk.org/t/can-we-use-vtkprobefilter-to-extract-data-along-a-curve-in-a-volume/14038/2 "2024-06-15T02:57:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kiran\_shaji](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kiran_shaji/32/8880_2.png) [@Kiran\_shaji](https://discourse.vtk.org/u/Kiran_shaji)\
**Post date:** [June 20, 2024, 12:57pm UTC](https://discourse.vtk.org/t/can-we-use-vtkprobefilter-to-extract-data-along-a-curve-in-a-volume/14038/3 "2024-06-20T12:57:27Z")

</div>

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?

vtkSmartPointer probeFilter = vtkSmartPointer::New();  
probeFilter-\>SetInputData(contourPolyData);  
probeFilter-\>SetSourceData(volume);  
probeFilter-\>Update();

```
vtkSmartPointer<vtkImageData> sampledImageData = vtkSmartPointer<vtkImageData>::New();
sampledImageData->ShallowCopy(probeFilter->GetOutput());

```

double\* scalarValue = sampledImageData-\>GetPointData()-\>GetScalars()-\>GetTuple(i);

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [June 20, 2024, 6:58pm UTC](https://discourse.vtk.org/t/can-we-use-vtkprobefilter-to-extract-data-along-a-curve-in-a-volume/14038/4 "2024-06-20T18:58:42Z")

</div>

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.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/9/9799b0c1e1c01647c26a9463cff3a50ca72522ae.jpeg)

Probing with curve is implemented in `Line profile` module in `Sandbox` extension.
