Skip to content

Commit 1cb5498

Browse files
authored
feat: Add threshold information in layer annotation in the Multiple Otsu ROI extraction method (#430)
1 parent f30763f commit 1cb5498

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

package/PartSeg/common_gui/napari_image_view.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,10 @@ def get_tool_tip_text(self) -> str:
733733
for el in self.components:
734734
data = image_info.roi_info.annotations.get(el, {})
735735
if data:
736-
text_list.append(_print_dict(data))
736+
try:
737+
text_list.append(_print_dict(data))
738+
except ValueError: # pragma: no cover
739+
logging.warning("Wrong value provided as layer annotation.")
737740
return " ".join(text_list)
738741

739742
def event(self, event: QEvent):

package/PartSegCore/segmentation/restartable_segmentation_algorithms.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ def calculation_run(self, report_fun):
546546
res = SimpleITK.GetArrayFromImage(res)
547547
self._sizes_array = np.bincount(res.flat)[1:]
548548
self.threshold_info = []
549+
annotations = {}
549550
for i in range(1, self.new_parameters["components"] + 1):
550551
val = cleaned_image[res == i]
551552
if val.size:
@@ -554,10 +555,15 @@ def calculation_run(self, report_fun):
554555
self.threshold_info.append(self.threshold_info[-1])
555556
else:
556557
self.threshold_info.append(0)
558+
annotations[i] = {"lower threshold": self.threshold_info[-1]}
559+
if i > 1:
560+
annotations[i - 1]["upper threshold"] = self.threshold_info[-1]
561+
annotations[self.new_parameters["components"]]["upper threshold"] = np.max(cleaned_image)
557562
return ROIExtractionResult(
558563
roi=res,
559564
parameters=self.get_segmentation_profile(),
560565
additional_layers={"denoised_image": AdditionalLayerDescription(data=cleaned_image, layer_type="image")},
566+
roi_annotation=annotations,
561567
)
562568

563569
def get_info_text(self):

0 commit comments

Comments
 (0)