DICOM does not allow any kind of indexing based on slice position, so no geometric conversion exists between physical coordinates to “slice index”.
The number that you see in 2D DICOM viewers when you browse the images is the Instance number, which is usually assigned to image slices based on where the image slice is located and/or when it was acquired. It is usually offset by one compared to the third voxel coordinate value (as instance numbers are typically 1-based, while voxel coordinates are 0-based) and often also inverted (as voxel coordinate increases, instance number can increase or decrease), and sometimes (e.g., when not all originally frames are available) then the offset may change throughout the series. Since a slice view is not always aligned with the original image slices (reformatted in orthogonal or oblique orientations), the instance number also often changes within a slice (different regions of the displayed image is reconstructed from different original slices).
Therefore, the only reliable way to get the instance number for a physical point position is the following:
- get the IJK coordinates of the volume at the position of interest
- get the SOP instance UID for the K-th slice in the volume - this UID is stored in the
DICOM.instanceUIDs
attribute - get the instance number from the DICOM database for that UID for the K-th slice of the volume
Implementation in Python (after the IJK coordinates are computed):
ijk = [12, 34, 56]
volumeNode = slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLVolumeNode')
instanceUID = volumeNode.GetAttribute('DICOM.instanceUIDs').split(' ')[ijk[2]]
instanceNumber = slicer.dicomDatabase.instanceValue(instanceUID, '0020,0013')
print(f"Instance Number: {instanceNumber}")
You can add this code snippet to DataProbe.py to make the instance number show up in the Data Probe in the bottom-left of the screen. If you implement it and works well for you then send a pull request, we may consider adding it to the Slicer core, as it can be useful for cross-referencing positions with slices shown in other DICOM viewers.