Histogram with the Hounsfield scale of segmented

Operating system: Windows
Slicer version: 4.11.0
Expected behavior:
Actual behavior:
I have segmented. As for this manually made segmentation, I can make a histogram with the Housfield scale for each single layer. I saw an example (Get image intensity histogram of a segment) unfortunately I can’t use it in my case.

If you need histogram to find good threshold value for segmentation: In recent Slicer Preview Releases, you can go to Segment Editor, create a segment, click on Threshold effect, and then click-and-drag on the image to define a region where histogram will be computed on. To view the histogram, open “Local histogram” section.

If you need histogram of a region under a segment then the code snippet you referenced above still works perfectly. If you have any difficulty using it then tell exactly what you do, what you expect to happen, and what happens instead.

I don’t know how to change the code so that the output histogram refers to the segmentation that I did manually. in the code, the segmentation is created automatically, I want to change it to my manually made segmentation.

śr., 8 lip 2020, 15:18 użytkownik Andras Lasso via 3D Slicer Community <slicer@discoursemail.com> napisał:

To use the script on your own data: replace “Generate input data” section of the code with getNode calls (it gets MRML node from the scene by its name).

this is my code, unfortunately it doesn’t work. Could you tell me what’s wrong?

# Generate input data
################################################

# Load master volume
import SampleData
sampleDataLogic = SampleData.SampleDataLogic()
masterVolumeNode = getVolumeNode ('6: DE DE_CarotidAngio 1.0 D30f B_80kV')()

# Create segmentation
segmentationNode=getNode('Segmentation') ()
slicer.mrmlScene.AddNode(segmentationNode)
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)

# Create segment
tumorSeed = vtk.vtkSphereSource()
tumorSeed.SetCenter(-6, 30, 28)
tumorSeed.SetRadius(25)
tumorSeed.Update()
segmentationNode.AddSegmentFromClosedSurfaceRepresentation(tumorSeed.GetOutput(), "Segment A", [1.0,0.0,0.0])

# Compute histogram
################################################

labelValue = 1 # label value of first segment
# Get segmentation as labelmap volume node
labelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLabelMapVolumeNode')
slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(segmentationNode, labelmapVolumeNode, masterVolumeNode)

# Extract all voxels of the segment as numpy array
volumeArray = slicer.util.arrayFromVolume(masterVolumeNode)
labelArray = slicer.util.arrayFromVolume(labelmapVolumeNode)
segmentVoxels = volumeArray[labelArray==labelValue]

# Compute histogram
import numpy as np
histogram = np.histogram(segmentVoxels, bins=50)

# Plot histogram
################################################

slicer.util.plot(histogram, xColumnIndex = 1)

image

Replace “Generate input data” section by this:

masterVolumeNode = getNode ('6: DE*')
segmentationNode = getNode('Segmentation')

You can choose between segments by setting labelValue to 1, 2, or 3.