Synthetic CT from MRI - editing MRI segments to Hounsfield Units

Hi all,

I’m trying to generate a synthetic CT from an MRI for use in an MRI-only radiotherapy treatment planning approach (with SlicerRT).

I’ve segmented out bone, air, tissue, and a mock tumour from the MRI - is there a way to convert their voxel values to Hounsfield Units? This is an exploratory approach so I only need those 4 basic features in the sCT; ideally I would like to set the HU for each segment (similar to assigning label values in the ‘Model to LabelMap’ module).

Thanks for your time.

You can use the segmentation to change voxels of a volume of the same geometry using numpy array operations, something like this:

volumeNode = getNode('MRHead')
segmentationNode = getNode('Segmentation')

segmentNames = ['bone', 'air', 'tissue', 'tumor']
voxelIntensities = [2000, -1000, 60, 150]

volumeArray = slicer.util.arrayFromVolume(volumeNode)

for segmentName, voxelIntensity in zip(segmentNames, voxelIntensities):
    # Get segment as numpy array
    segmentId = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName(segmentName)
    segmentArray = slicer.util.arrayFromSegmentBinaryLabelmap(segmentationNode, segmentId, volumeNode)
    # Update voxel of the volume
    volumeArray[ segmentArray > 0 ] = voxelIntensity

slicer.util.arrayFromVolumeModified(volumeNode)
1 Like

Thanks for the reply, Andras. I’m getting the following error:

Traceback (most recent call last):
File "<console>", line 3, in <module>
TypeError: arrayFromSegmentBinaryLabelmap() takes 2 positional arguments but 3 were given

I’ve tried limiting it to two (of those three) arguments but it errs every time. Any ideas?

There are several AI-based algorithms for converting MRI into sCT.

However, to check quality conversion, you can use this module:
https://www.slicer.org/wiki/Documentation/Nightly/Extensions/ImageCompare

Best,
Paolo

The code snippet works in recent Slicer Preview Releases. The latest Slicer Stable Release users slightly different syntax.

Thanks for the help. I’ve downloaded the most recent preview release but I’m now getting a different error - I’ve attached a screenshot in case the problem is my structuring of the nodes/segments.

The code I’m using is:

volumeNode = getNode('101')
segmentationNode = getNode('Segmentation')

segmentNames = ['bone', 'gas', 'tissue', 'mass']
voxelIntensities = [2000, -1000, 60, 150]

for segmentName, voxelIntensity in zip(segmentNames, voxelIntensities):
    segmentId = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName(segmentName)
    segmentArray = slicer.util.arrayFromSegmentBinaryLabelmap(segmentationNode, segmentId, volumeNode)
    volumeArray[ segmentArray > 0 ] = voxelIntensity

slicer.util.arrayFromVolumeModified(volumeNode)

It seems that I’ve missed a line. Call volumeArray = slicer.util.arrayFromVolume(volumeNode) after setting volumeNode.

1 Like