I have been working with slicer for 5-6 months. I have managed to develop some useful modules. However, for the current task, I will be needing your help.
I have my data in NumPy array, which is kept on updating progressively. I need to plot a histogram real-time with an option that a user can interact with a histogram or make a rectangle or something to select a art of the data
something like this:
In the latest 3D Slicer 4.11.0 releases, the Threshold effect in the Segment Editor module now includes the option to specify the minimum and maximum thresholds based on the histogram of a region of interest in the slice view.
Clicking and dragging on a slice view will create a yellow border that encompasses the region of interest. Several different shapes can be used to draw the region of interest including: box, circle, freeform draw, or line.
The local histogram for this …
I cannot find the code for this, can you help me making this king of the histogram in the most efficient way?
I went through several examples, like:
Is there a way to determine the area a segment takes up in a given slice? I’m interested in generating a plot from a CT scan, anterior to posterior, of the area taken up by a segment slice-by-slice (if that makes sense).
If you were to do this on a sphere, for example, you’d wind up with a gaussian. (I think, I’d have to double-check the math on that…)
You can simply save the file in vtk or vtp file format and that will contain all the computed distances for each point.
Note that you can also access all the distance values in Python and compute statistics (histogram, etc). For example, this script shows how to compute and plot histogram:
modelNode = getNode('VTK Output File')
# Get distances from model node (stored in point data array)
I managed to make a histogram with my Table Node, However, as I update the table Node with my new data, the chart just vanishes. Here is my code for making a histogram:
self.plotChartNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotChartNode", "Histogram")
histogram = np.histogram(self.my_DATA, bins=10) # my_DATA is the numpy array containing the data
# Create new plot data series node
self.plotSeriesNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotSeriesNode", "Distance histogram")
# Add plot to chart
self.plotWidget = layoutManager.plotWidget(0)
This works fine. However as , my data gets updated, I make a new histogram and update the table node with a new histogram data as:
histogram = np.histogram(self.my_DATA, bins=20)
As soon as my Table node gets updated, I cannot see anything in the chart.
Can you help me with this? @lassoan may be. Thanks.
Thanks in advance.
The plot disappeared because you specified that the chart is built from columns “Intensity” and “Count”, but the table after calling
slicer.util.updateTableFromArray(tableNode, histogram) had default column names (Column 1, Column 2). Since numpy arrays do not store column names, you need to manage them by yourself and pass it to the the converter function yourself:
slicer.util.updateTableFromArray(tableNode, histogram, ["Count", "Intensity"])
Thank you so much for your response
@lassoan, it worked like a charm.
According to your experience, what is the most efficient way to make a real time interactive plot? Is there any better way other than this?