Skip to content

Commit

Permalink
Segmentation error after closing and reopening scene is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rasakereh committed Feb 2, 2024
1 parent e7048eb commit 0b6925a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
13 changes: 10 additions & 3 deletions MedSAM/MedSAMLite/MedSAMLite.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,18 +683,25 @@ def showSegmentation(self, segmentation_mask):
seg_sitk.CopyInformation(self.img_sitk)
sitk.WriteImage(seg_sitk, segmentation_res_file) ########## Set your segmentation output here
loaded_seg_file = slicer.util.loadSegmentation(segmentation_res_file)

segment_volume = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode")
slicer.modules.segmentations.logic().ExportAllSegmentsToLabelmapNode(loaded_seg_file, segment_volume, slicer.vtkSegmentation.EXTENT_REFERENCE_GEOMETRY)

current_seg_group = self.widget.editor.segmentationNode()
if current_seg_group is None:
if self.segment_res_group is None:
self.segment_res_group = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
self.segment_res_group.SetReferenceImageGeometryParameterFromVolumeNode(self.volume_node)
current_seg_group = self.segment_res_group

slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(segment_volume, current_seg_group)
try:
check_if_node_is_removed = slicer.util.getNode(current_seg_group.GetID()) # if scene is closed and reopend, this line will raise an error
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(segment_volume, current_seg_group)
except:
self.segment_res_group = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
self.segment_res_group.SetReferenceImageGeometryParameterFromVolumeNode(self.volume_node)
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(segment_volume, self.segment_res_group)

slicer.mrmlScene.RemoveNode(segment_volume)
slicer.mrmlScene.RemoveNode(loaded_seg_file)

Expand Down
2 changes: 0 additions & 2 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def get_image(wmin: int, wmax: int):
image = arr
# H, W = arr.shape[1:] # TODO: make sure h, w not filpped #################### This line is causing problem
H, W = arr.shape[1:]
print('Line 225, H, W:', H, W, file=sys.stderr)

for slice_idx in range(image.shape[0]):
# for slice_idx in tqdm(range(4)):
Expand Down Expand Up @@ -267,7 +266,6 @@ def get_bbox1024(mask_1024, bbox_shift=3):
y_min, y_max = np.min(y_indices), np.max(y_indices)
# add perturbation to bounding box coordinates
H, W = mask_1024.shape
print('Line 269, H, W:', H, W, file=sys.stderr)
x_min = max(0, x_min - bbox_shift)
x_max = min(W, x_max + bbox_shift)
y_min = max(0, y_min - bbox_shift)
Expand Down
Binary file modified server_essentials.zip
Binary file not shown.

0 comments on commit 0b6925a

Please sign in to comment.