diff --git a/MedSAM/MedSAMLite/MedSAMLite.py b/MedSAM/MedSAMLite/MedSAMLite.py index 40fb513..c8aecbd 100644 --- a/MedSAM/MedSAMLite/MedSAMLite.py +++ b/MedSAM/MedSAMLite/MedSAMLite.py @@ -683,10 +683,10 @@ 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: @@ -694,7 +694,14 @@ def showSegmentation(self, segmentation_mask): 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) diff --git a/server/server.py b/server/server.py index c84bb22..d97093b 100644 --- a/server/server.py +++ b/server/server.py @@ -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)): @@ -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) diff --git a/server_essentials.zip b/server_essentials.zip index bfdec3f..6cb3b8e 100644 Binary files a/server_essentials.zip and b/server_essentials.zip differ