Getting file name from a DICOM slice

I would like to get a filename/path from a particular slice of a dicom image. For example I have loaded a DICOM file with several hundred slices and I would like to get the filename/path of a particular slice.

I have went through this link:

And was able to develop a python script that allowed me to get a filename of a particular slice, but now I want to do it in C++ as well. However, many of the functionalities and modules available in python are not available in C++.

Currently, I am able to get the VTKMRMLvolume node, but was wondering where I can go from there.

Any help is appreciated!

All Slicer features are available in both C++ and Python. If you have difficulty figuring out the syntax for any particular method then let us know.

Thank you for the reply Andras!

There are two methods in particular that I would like to know:

  1. For a given DICOM file, I would like to know which particular slice I am on (the slice number), I know that we would get this information from the DataProbe, and in python we would do
    infoWidget = slicer.modules.DataProbeInstance.infoWidget
    to get the voxel coordinate, what would be the syntax to achieve this in C++?

  2. If I currently have the instanceUID, how would I get the filename from it? In python I would do:
    where k is the voxel coordinate, but what would the syntax be in C++?

Thank you in advance and I really appreciate your help!

There are many ways for getting position from a view. If you want to know the current position of the mouse pointer, you can get it from the crosshair node (see example). If you want the user to mark a position then I would recommend to make the user place a markup point. If you just want the user to select a slice then you can get slice position and orientation from the slice node.

You can get the DICOM database by calling


Thanks for the reply!

Could we also access the slice position from DataProbe?

Data Probe module has no a logic class therefore there is no clean way of getting slice position from it. But since it is so simple to get slice index and position information from MRML nodes, there is no need to use the Data Probe module for this.

Sounds good I will look into this!

I’m a bit new to slicer so I was wondering by slice node do you mean the volume node? Because I cant seem to find anything regarding a slice node. Also what would the syntax be to pull a slice index from a slice node?

There is actually a slice node (vtkMRMLSliceNode) for each slice view, which stores slice position and orientation in its SliceToRAS matrix. Slice position in RAS coordinate system is stored in the last column of the matrix.