|
1 | 1 | """Instance segmentation methods for 3D images.""" |
| 2 | + |
2 | 3 | import abc |
3 | 4 | from dataclasses import dataclass |
4 | 5 | from functools import partial |
@@ -128,14 +129,14 @@ def record_parameters(self): |
128 | 129 | """Records all the parameters of the instance segmentation method from the current values of the widgets.""" |
129 | 130 | if len(self.sliders) > 0: |
130 | 131 | for slider in self.sliders: |
131 | | - self.recorded_parameters[ |
132 | | - slider.label.text() |
133 | | - ] = slider.slider_value |
| 132 | + self.recorded_parameters[slider.label.text()] = ( |
| 133 | + slider.slider_value |
| 134 | + ) |
134 | 135 | if len(self.counters) > 0: |
135 | 136 | for counter in self.counters: |
136 | | - self.recorded_parameters[ |
137 | | - counter.label.text() |
138 | | - ] = counter.value() |
| 137 | + self.recorded_parameters[counter.label.text()] = ( |
| 138 | + counter.value() |
| 139 | + ) |
139 | 140 |
|
140 | 141 | def run_method_from_params(self, image): |
141 | 142 | """Runs the method on the image with the RECORDED parameters set in the widget. |
@@ -327,10 +328,8 @@ def binary_connected( |
327 | 328 | ) |
328 | 329 | semantic = np.squeeze(volume) |
329 | 330 | foreground = np.where(semantic > thres, volume, 0) # int(255 * thres) |
330 | | - segm = label(foreground) |
331 | | - segm = remove_small_objects(segm, thres_small) |
332 | | - |
333 | | - return segm |
| 331 | + seg = label(foreground) |
| 332 | + return remove_small_objects(seg, thres_small) |
334 | 333 |
|
335 | 334 |
|
336 | 335 | def binary_watershed( |
@@ -419,15 +418,10 @@ def clear_small_objects(image, threshold, is_file_path=False): |
419 | 418 | if is_file_path: |
420 | 419 | image = imread(image) |
421 | 420 |
|
422 | | - # print(threshold) |
423 | | - |
424 | 421 | labeled = label(image) |
425 | 422 |
|
426 | 423 | result = remove_small_objects(labeled, threshold) |
427 | 424 |
|
428 | | - # print(np.sum(labeled)) |
429 | | - # print(np.sum(result)) |
430 | | - |
431 | 425 | if np.sum(labeled) == np.sum(result): |
432 | 426 | print("Warning : no objects were removed") |
433 | 427 |
|
@@ -551,9 +545,9 @@ def __init__(self, widget_parent=None): |
551 | 545 | ) |
552 | 546 |
|
553 | 547 | self.sliders[0].label.setText("Foreground probability threshold") |
554 | | - self.sliders[ |
555 | | - 0 |
556 | | - ].tooltips = "Probability threshold for foreground object" |
| 548 | + self.sliders[0].tooltips = ( |
| 549 | + "Probability threshold for foreground object" |
| 550 | + ) |
557 | 551 | self.sliders[0].setValue(500) |
558 | 552 |
|
559 | 553 | self.sliders[1].label.setText("Seed probability threshold") |
@@ -652,9 +646,9 @@ def __init__(self, widget_parent=None): |
652 | 646 | ) |
653 | 647 |
|
654 | 648 | self.sliders[0].label.setText("Foreground probability threshold") |
655 | | - self.sliders[ |
656 | | - 0 |
657 | | - ].tooltips = "Probability threshold for foreground object" |
| 649 | + self.sliders[0].tooltips = ( |
| 650 | + "Probability threshold for foreground object" |
| 651 | + ) |
658 | 652 | self.sliders[0].setValue(800) |
659 | 653 |
|
660 | 654 | self.counters[0].label.setText("Small objects removal") |
@@ -715,18 +709,18 @@ def __init__(self, widget_parent=None): |
715 | 709 | widget_parent=widget_parent, |
716 | 710 | ) |
717 | 711 | self.counters[0].label.setText("Spot sigma") # closeness |
718 | | - self.counters[ |
719 | | - 0 |
720 | | - ].tooltips = "Determines how close detected objects can be" |
| 712 | + self.counters[0].tooltips = ( |
| 713 | + "Determines how close detected objects can be" |
| 714 | + ) |
721 | 715 | self.counters[0].setMaximum(100) |
722 | | - self.counters[0].setValue(2) |
| 716 | + self.counters[0].setValue(0.65) |
723 | 717 |
|
724 | 718 | self.counters[1].label.setText("Outline sigma") # smoothness |
725 | | - self.counters[ |
726 | | - 1 |
727 | | - ].tooltips = "Determines the smoothness of the segmentation" |
| 719 | + self.counters[1].tooltips = ( |
| 720 | + "Determines the smoothness of the segmentation" |
| 721 | + ) |
728 | 722 | self.counters[1].setMaximum(100) |
729 | | - self.counters[1].setValue(2) |
| 723 | + self.counters[1].setValue(0.65) |
730 | 724 |
|
731 | 725 | self.counters[2].label.setText("Small object removal") |
732 | 726 | self.counters[2].tooltips = ( |
|
0 commit comments