# Get voxel intensity

**URL:** https://discourse.vtk.org/t/get-voxel-intensity/2797
**Category:** Support
**Created:** [March 10, 2020, 8:02pm UTC](https://discourse.vtk.org/t/get-voxel-intensity/2797 "2020-03-10T20:02:15Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [March 10, 2020, 8:02pm UTC](https://discourse.vtk.org/t/get-voxel-intensity/2797/1 "2020-03-10T20:02:15Z")

</div>

I have a VC++ app that use VTK for visualizing DICOM CBCT and SimpleITK for segmentation (I intend to do segmentation, until now, it doesn’t working 🙂 )

When I click on **vtkVolume** , I am using **vtkCellPicker** to know the 3d coordinates of the click. My question is, how can I use this point:

```
vtkCellPicker* pCellPicker = vtkCellPicker::New();
pCellPicker->Pick(nPosition[0], nPosition[1], 0, m_pRenderer);
pCellPicker->GetCellIJK(nCell);
pCellPicker->GetPointIJK(nPoint);

```

**nCell** and **nPoint** has the same values. But how can I use these values to collect seed values for **sitk::ConfidenceConnected** filter ?

I mean, how can I know if I click on a bone, or a soft tissue ?

Can you provide me some information regarding this domain ? Or, a proper documentation to lead me for solving this …

Thank you for you time and patience.

Flaviu.

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [March 11, 2020, 3:41pm UTC](https://discourse.vtk.org/t/get-voxel-intensity/2797/2 "2020-03-11T15:41:36Z")

</div>

I have tried this code:

```
double* d = static_cast<double*>(m_pDICOMReader->GetOutput()->GetScalarPointer(nCell[0], nCell[1], nCell[2]))

```

to check the scalar value from the picked point:

```
TRACE("%d|%d|%d\t%f|%f|%f\n", nCell[0], nCell[1], nCell[2], 
			d[0], d[1], d[2]);

```

Result: 340|421|36 0.000000|0.000000|0.000000  
Why ? As you can see, the picked point has a valid value … why the scalar value is 0 ?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [March 12, 2020, 11:42am UTC](https://discourse.vtk.org/t/get-voxel-intensity/2797/3 "2020-03-12T11:42:20Z")

</div>

Hello, friend, g’day.

You need do perform an operation called probing:

```auto
            // Output the probed value at the picked location.
            vtkDataSet* dataSet = pCellPicker->GetDataSet();
            vtkCellData* cellData = dataSet->GetCellData();
            vtkDataArray* dataArray = cellData->GetScalars();
            if( dataArray->GetNumberOfComponents() <= 200 ){
                double values[200]; //max of 200 scalar fields is large enough for most applications
                dataArray->GetTuple( cellPicker->GetCellId(), values );
                QString valuesText = "NO VALUES PICKED";
                for( int i = 0; i < dataArray->GetNumberOfComponents(); ++i )
                    if( i == 0)
                        valuesText = QString::number(values[0]);
                    else
                        valuesText = valuesText + "; " + QString::number(values[i]);
                std::cout << "Picked value(s): " << valuesText << std::endl;
            }

```

all the best,

Paulo

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [March 13, 2020, 3:15pm UTC](https://discourse.vtk.org/t/get-voxel-intensity/2797/4 "2020-03-13T15:15:31Z")

</div>

I wrote:

```
		vtkDataSet* pDataSet = pCellPicker->GetDataSet();
		vtkCellData* pCellData = pDataSet->GetCellData();
		vtkDataArray* pArrData = pCellData->GetScalars();

```

at this point

```
vtkDataArray* pArrData = pCellData->GetScalars();

```

pArrData is NULL … I don’t know why …

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [March 14, 2020, 7:47pm UTC](https://discourse.vtk.org/t/get-voxel-intensity/2797/5 "2020-03-14T19:47:30Z")

</div>

Because **pCellData-\>GetScalars()** got NULL pointers, then there no scalars pointers there … I have to mention that **pCellPicker** , **pDataSet** and **pCellData** is valid pointers.

In this case there is another way to get the voxel intensity for a giving voxel ?

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [March 14, 2020, 7:54pm UTC](https://discourse.vtk.org/t/get-voxel-intensity/2797/6 "2020-03-14T19:54:05Z")

</div>

I have taken **PrintSelf** from **pCellPicker** :

```
Debug: Off
Modified Time: 667353
Reference Count: 1
Registered Events: (none)
Picking from renderer's prop list
Renderer: 00000193DCB07410
Selection Point: (543,152,0)
Pick Position: (228.553,57.0421,138.613)
Path: 00000193DF0392E0
DataSet: 00000193DF3190D0
CompositeDataSet: (none)
FlatBlockIndex: (none)
Mapper: 00000193DAA81740
Tolerance: 1e-06
MapperPosition: (228.553,57.0421,138.613)
MapperNormal: (1,0,0)
PickNormal: (1,0,0)
Texture: (none) PickTextureData: Off
PointId: 9241087
CellId: 8943521
SubId: 0
PCoords: (1, 0.535222, 0.782796)
PointIJK: (511, 128, 35)
CellIJK: (510, 127, 34)
ClippingPlaneId: -1
PickClippingPlanes: Off
VolumeOpacityIsovalue: 0.05
UseVolumeGradientOpacity: Off
```

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [March 14, 2020, 8:43pm UTC](https://discourse.vtk.org/t/get-voxel-intensity/2797/7 "2020-03-14T20:43:09Z")

</div>

Maybe I got this pCellData as NULL pointer because I am using this **vtkCellPicker** on a **vtkImageData**? Could be the cause ?

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [March 16, 2020, 9:49am UTC](https://discourse.vtk.org/t/get-voxel-intensity/2797/8 "2020-03-16T09:49:32Z")

</div>

I think I have found the solution, I’ll write here for at least two reasons:

1. Please correct me if I wrong.
2. If is correct, then someone who need this can find here a possible solution.

` short* dResult = (short*)m_pDICOMReader->GetOutput()->GetScalarPointer(nPoint[0], nPoint[1], nPoint[2]);`

and

`m_pDICOMReader->GetOutput()->GetScalarComponentAsDouble(nPoint[0], nPoint[1], nPoint[2], 0);`

The Paulo solution I cannot used due to retrieving NULL pointer at **GetScalars()** step … I would be curios if my values is the same as Paulo solution …

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [March 23, 2020, 9:06pm UTC](https://discourse.vtk.org/t/get-voxel-intensity/2797/9 "2020-03-23T21:06:25Z")

</div>

I guess that **GetScalarPointer/GetScalarComponentAsDouble** is not the same thing as “probing” … but in my case, this procedure is failing, as I wrote above … I really don’t know why … anyone get through this issue before ?
