|
4 | 4 | # Load dry bone CT of skull into the scene and run this script to automatically segment endocranium
|
5 | 5 | #slicer.util.loadVolume("C:\\Users\\jeffzeyl\\Desktop\\RD01r2_2019\\pigeon0000.tif", returnNode=True)
|
6 | 6 |
|
| 7 | +slicer.util.loadVolume(r"C:\Users\jeffz\Desktop\copyoutput\Jun5 batch\Pcrow\crowbetter0000.tif", returnNode=True) |
| 8 | +spacing = 0.021875#set resolution |
| 9 | +ID = "PCrow" |
| 10 | + |
7 | 11 | masterVolumeNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLScalarVolumeNode")
|
8 | 12 | #or can get the volume node by the name slicer.util.getNode('pigeon0000')
|
9 | 13 | #print(mastervolumeNode)
|
|
75 | 79 | Otsu_thresholdCalculator.Update()
|
76 | 80 | Otsuval = Otsu_thresholdCalculator.GetThreshold()
|
77 | 81 |
|
78 |
| -#MAX ENTROPY THRESHOLD OF COLUMELLA |
79 |
| -#OverwriteMode: OverwriteNone |
80 |
| -#SelectedSegmentID: threshcol |
81 |
| -#ActiveEffectName: "Threshold" |
82 |
| -#MaskMode: PaintAllowedInsideSingleSegment #segmentEditorNode.SetMaskMode(slicer.vtkMRMLSegmentEditorNode.PaintAllowedInsideVisibleSegments) |
83 |
| -#MaskSegmentID: paintcol |
84 |
| -threshcol = segmentationNode.GetSegmentation().AddEmptySegment(ID+" thresh col") |
85 |
| -segmentEditorWidget.setActiveEffectByName("Threshold") |
86 |
| -segmentEditorNode.SetOverwriteMode(slicer.vtkMRMLSegmentEditorNode.OverwriteNone) |
87 |
| -segmentEditorNode.SetMaskMode(slicer.vtkMRMLSegmentEditorNode.PaintAllowedInsideSingleSegment) |
88 |
| -segmentEditorNode.SetSelectedSegmentID(ID+" thresh col") |
89 |
| -segmentEditorNode.SetMaskSegmentID(ID+" paint col") |
90 |
| -effect = segmentEditorWidget.activeEffect() |
91 |
| -effect.setParameter("MinimumThreshold", str(Maxentval)) |
92 |
| -effect.setParameter("MaximumThreshold",str(volumeScalarRange[1])) |
93 |
| -effect.self().onApply()#apply separate |
94 |
| - |
95 |
| -#run keep largest island on thresholded columella |
96 |
| -segmentEditorWidget.setActiveEffectByName("Islands") |
97 |
| -effect = segmentEditorWidget.activeEffect() |
98 |
| -segmentEditorNode.SetSelectedSegmentID(ID+" thresh col") |
99 |
| -effect.setParameterDefault("Operation", "KEEP_LARGEST_ISLAND") |
100 |
| - |
101 |
| -effect.self().onApply()#apply separate |
102 |
| - |
103 |
| -#quantification table |
104 |
| -#resultsTableNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLTableNode')# create table node |
105 |
| -#import SegmentStatistics |
106 |
| -#segStatLogic = SegmentStatistics.SegmentStatisticsLogic() |
107 |
| -#segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID()) |
108 |
| -#segStatLogic.getParameterNode().SetParameter("ScalarVolume", os.listdir(folder)[0].replace('.tif',''))############change here to the named volume |
109 |
| -#segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.enabled","False") |
110 |
| -#segStatLogic.getParameterNode().SetParameter("ScalarVolumeSegmentStatisticsPlugin.voxel_count.enabled","False") |
111 |
| -#segStatLogic.computeStatistics() |
112 |
| -#segStatLogic.exportToTable(resultsTableNode) |
113 |
| -#segStatLogic.showTable(resultsTableNode) |
114 |
| - |
115 |
| -#OR STORE STATS AS DICTIONARY: |
116 |
| -import SegmentStatistics |
117 |
| -segStatLogic = SegmentStatistics.SegmentStatisticsLogic() |
118 |
| -segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID()) |
119 |
| -#segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.obb_origin_ras.enabled",str(True)) |
120 |
| -#segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.obb_diameter_mm.enabled",str(True)) |
121 |
| -#segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.obb_direction_ras_x.enabled",str(True)) |
122 |
| -#segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.obb_direction_ras_y.enabled",str(True)) |
123 |
| -#segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.obb_direction_ras_z.enabled",str(True)) |
124 |
| -segStatLogic.computeStatistics() |
125 |
| -stats = segStatLogic.getStatistics() |
126 |
| -#x = thisdict["model"] |
127 |
| -#stats['BS01-2019 thresh col'] |
128 |
| -#colvol = stats[ID+" thresh col", 'ClosedSurfaceSegmentStatisticsPlugin.volume_mm3'] |
129 |
| -colvol = stats[ID+" thresh col",'LabelmapSegmentStatisticsPlugin.volume_mm3'] |
130 |
| -'KW01 thresh col', 'LabelmapSegmentStatisticsPlugin.volume_mm3' |
131 |
| -'KW01 thresh col', 'LabelmapSegmentStatisticsPlugin.volume_mm3' |
132 |
| - |
133 |
| -#Write to text file |
134 |
| -# with is like your try .. finally block in this case |
135 |
| -with open('C:\\Users\\jeffzeyl\\Desktop\\Volumes.txt', 'r') as file: |
136 |
| - # read a list of lines into data |
137 |
| - data = file.readlines() |
138 |
| - |
139 |
| -data.append(ID+', '+str(colvol)+'\n') |
140 |
| - |
141 |
| -# and write everything back |
142 |
| -with open('C:\\Users\\jeffzeyl\\Desktop\\Volumes.txt', 'w') as file: |
143 |
| - file.writelines( data ) |
144 |
| -# |
145 |
| -# |
146 |
| - |
147 |
| - |
148 |
| -#MAX ENTROPY THRESHOLD OF ECD |
149 |
| -segmentEditorNode.SetOverwriteMode(slicer.vtkMRMLSegmentEditorNode.OverwriteNone) |
150 |
| -segmentEditorNode.SetMaskMode(slicer.vtkMRMLSegmentEditorNode.PaintAllowedInsideSingleSegment) |
151 |
| -segmentEditorNode.SetSelectedSegmentID(ID+" thresh ECD") |
152 |
| -segmentEditorNode.SetMaskSegmentID(ID+" paint ECD") |
153 |
| -segmentEditorWidget.setActiveEffectByName("Threshold") |
154 |
| -effect = segmentEditorWidget.activeEffect() |
155 |
| -#effect.setParameter("AutoThresholdMode",'SET_MIN_UPPER') |
156 |
| -#effect.setParameter("AutoThresholdMethod","MAXIMUM_ENTROPY")#maximum entropy algorithm |
157 |
| -effect.setParameter("MinimumThreshold", str(0)) |
158 |
| -effect.setParameter("MaximumThreshold",str(Maxentval)) |
159 |
| - |
160 |
| -effect.self().onApply()#apply separate |
161 |
| - |
162 |
| -#run KEEP LARGEST ISLAND on ECD tip |
163 |
| -segmentEditorWidget.setActiveEffectByName("Islands") |
164 |
| -effect = segmentEditorWidget.activeEffect() |
165 |
| -segmentEditorNode.SetSelectedSegmentID(ID+" thresh ECD") |
166 |
| -effect.setParameterDefault("Operation", "KEEP_LARGEST_ISLAND") |
167 |
| - |
168 |
| -effect.self().onApply()#apply separate |
169 |
| - |
170 |
| -#moments/ISODATA-MAXENT THRESHOLD FOR UMBO |
171 |
| -segmentEditorNode.SetOverwriteMode(slicer.vtkMRMLSegmentEditorNode.OverwriteNone) |
172 |
| -effect = segmentEditorWidget.activeEffect() |
173 |
| -segmentEditorNode.SetMaskMode(slicer.vtkMRMLSegmentEditorNode.PaintAllowedInsideSingleSegment) |
174 |
| -segmentEditorNode.SetSelectedSegmentID(ID+" thresh umbo") |
175 |
| -segmentEditorNode.SetMaskSegmentID(ID+" paint umbo") |
176 |
| -segmentEditorWidget.setActiveEffectByName("Threshold") |
177 |
| -effect.setParameter("MinimumThreshold", str(ISOval))#//str(Momentsval),str(ISOval) |
178 |
| -effect.setParameter("MaximumThreshold",str(Maxentval)) |
179 |
| - |
180 |
| -effect.self().onApply()#apply separate |
181 |
| - |
182 |
| -#remove visibility of painted segments |
183 |
| -segmentationNodedisplaynode = segmentationNode.GetDisplayNode()#make display node |
184 |
| - |
185 |
| -segmentationNodedisplaynode.SetSegmentVisibility2DFill(ID+" paint col", 0) |
186 |
| -segmentationNodedisplaynode.SetSegmentVisibility2DOutline(ID+" paint col", 0) |
187 |
| -segmentationNodedisplaynode.SetSegmentVisibility3D(ID+" paint col", 0) |
188 |
| - |
189 |
| -segmentationNodedisplaynode.SetSegmentVisibility2DFill(ID+" paint umbo", 0) |
190 |
| -segmentationNodedisplaynode.SetSegmentVisibility2DOutline(ID+" paint umbo", 0) |
191 |
| -segmentationNodedisplaynode.SetSegmentVisibility3D(ID+" paint umbo", 0) |
192 |
| - |
193 |
| -segmentationNodedisplaynode.SetSegmentVisibility2DFill(ID+" paint ECD", 0) |
194 |
| -segmentationNodedisplaynode.SetSegmentVisibility2DOutline(ID+" paint ECD", 0) |
195 |
| -segmentationNodedisplaynode.SetSegmentVisibility3D(ID+" paint ECD", 0) |
196 |
| - |
197 |
| -segmentationNodedisplaynode.SetSegmentVisibility2DFill(ID+" thresh ECD", 1) |
198 |
| - |
199 |
| -#TO DO - default settings paint for umbo. - 3d sphere |
200 |
| -#TO DO - threshold Umbo - lower iso |
201 |
| - |
202 |
| -#show segmentation in 3D |
203 |
| -segmentationNode.CreateClosedSurfaceRepresentation() |
204 |
| - |
205 |
| -#OTHER FIDUCIAL CODE< MAY BE USEFUL: |
206 |
| -# Get point positions as numpy array |
207 |
| -#import numpy as np |
208 |
| -#nOfFiduciallPoints = FIDNode5.GetNumberOfFiducials() |
209 |
| -#points = np.zeros([nOfFiduciallPoints,3]) |
210 |
| -#for i in range(0, nOfFiduciallPoints): |
211 |
| -# FIDNode5.GetNthFiducialPosition(i, points[i,:]) |
212 |
| -# |
213 |
| -#points[2][1] |
214 |
| -#points[2][1] |
215 |
| - |
216 |
| -#Change markup fiducial display properties |
217 |
| -#Display properties are stored in display node(s) associated with the fiducial node. |
218 |
| -#defaultMarkupsDisplayNode = slicer.vtkMRMLMarkupsDisplayNode() |
219 |
| -#defaultMarkupsDisplayNode.SetGlyphScale(0.3) |
220 |
| -#defaultMarkupsDisplayNode.SetTextScale(0.3) |
221 |
| -#slicer.mrmlScene.AddDefaultNode(defaultMarkupsDisplayNode) |
222 |
| -# |
223 |
| -#fiducialNode = getNode('F') |
224 |
| -#fiducialDisplayNode = fiducialNode.GetDisplayNode() |
225 |
| -#fiducialDisplayNode.SetSelectedColor(1,1,0) # Set color to yellow |
226 |
| -# |
227 |
| -#fiducialDisplayNode.SetVisibility(False) # Hide all points |
228 |
| -#fiducialDisplayNode.SetVisibility(True) # Show all points |
229 |
| -#fiducialDisplayNode.SetViewNodeIDs(["vtkMRMLSliceNodeRed", "vtkMRMLViewNode1"]) # Only show in red slice view and first 3D view |
230 |
| -##################################################################################333 |
231 |
| - |
232 |
| -##fidNode = getNode("vtkMRMLMarkupsFiducialNode1") |
233 |
| -##n = fidNode.AddFiducial(4.0, 5.5, -6.0) |
234 |
| -##fidNode.SetNthFiducialLabel(n, "new label") |
235 |
| -### each markup is given a unique id which can be accessed from the superclass level |
236 |
| -##id1 = fidNode.GetNthMarkupID(n) |
237 |
| -### manually set the position |
238 |
| -##fidNode.SetNthFiducialPosition(n, 6.0, 7.0, 8.0) |
239 |
| -### set the label |
240 |
| -##fidNode.SetNthFiducialLabel(n, "New label") |
241 |
| -### set the selected flag, only selected = 1 fiducials will be passed to CLIs |
242 |
| -##fidNode.SetNthFiducialSelected(n, 1) |
243 |
| -### set the visibility flag |
244 |
| -##fidNode.SetNthFiducialVisibility(n, 0) |
245 |
| - |
246 |
| -# Make segmentation results visible in 3D |
247 |
| -#segmentationNode.CreateClosedSurfaceRepresentation() |
0 commit comments