Exemplo n.º 1
0
    def image_segmentation(self, show=True, **kwargs):
        """Compute low-level segmentation methods like felzenswalb' efficient graph based segmentation or k-means based image segementation

        https://scikit-image.org/docs/dev/auto_examples/segmentation/plot_segmentations.html#sphx-glr-auto-examples-segmentation-plot-segmentations-py
        """
        # get settings of combobox and fields
        param_seg = self._csbox_seg.get_dict()

        # get the currently displayed image
        img = imgtools.project_and_stack(self.get_obj().get_img_from_label(
            param_seg["domain"], dtype=np.uint8, factor=255))
        # img = self.get_obj().get_img_from_label("height")
        # param_seg["reference"] = self.get_obj().get_img_from_label("height")
        param_seg["boundaries"] = "find"
        # define image list for visualization
        img_list = [img]

        mode = param_seg["mode"]
        if mode == "SLIC" or mode == "SLIC-0" or mode == "Normalized Cuts":
            param_model = self._csbox_slic.get_dict()
        elif mode == "Felzenswalb":
            param_model = self._csbox_felz.get_dict()
        elif mode == "KMeans":
            param_model = self._csbox_kmeans.get_dict()

        seg = rsvis.utils.imgseg.ImgSeg(**param_seg)
        seg.predict(img, **param_model)
        img_list.extend([
            seg.get_seg_map_color(),
            seg.get_seg_map_boundaries(img=imgtools.project_and_stack(
                self.get_obj().get_img_from_label(param_seg["reference"]),
                dtype=np.uint8,
                factor=255))
        ])

        print("Number of segments: {}".format(seg.get_num_label()))

        # open a topwindow with the segmentation results of the currently displayed image

        if show:
            self.get_obj().set_img(img_list[2], clear_mask=False)
            self.set_img()

            self._img_tw = tw.TopWindow(self,
                                        title="Segmentation",
                                        dtype="img",
                                        value=img_list)
        return img_list
Exemplo n.º 2
0
def get_label_options():

    return [{
        "require":
        "label",
        "label":
        "Image",
        "name":
        "Projection - Single Class",
        "key":
        None,
        "description":
        "Show the mask of one label in current image.",
        "command":
        lambda obj: obj.set_mask(imgtools.get_mask_image(
            obj.get_img_from_label("{label}"),
            index=obj.get_class(value=False)),
                                 invert=True)
    }, {
        "require":
        "label",
        "label":
        "Image",
        "name":
        "Projection - All Classes",
        "key":
        None,
        "description":
        "Show the mask of one label in current image.",
        "command":
        lambda obj: obj.set_img(
            imgtools.get_color_map(
                obj.get_img_from_label("{label}"), obj.get_img(), alpha=0.2))
    }, {
        "require":
        "label",
        "label":
        "Image",
        "name":
        "Distance Transform",
        "key":
        None,
        "description":
        "Compute the distance transform map of a label given by current label index.",
        "command":
        lambda obj: obj.set_img(
            imgtools.project_and_stack(imgtools.get_distance_transform(
                obj.get_img_from_label("{label}"),
                index=obj.get_class(value=False),
            ),
                                       dtype=np.uint8,
                                       factor=255))
    }]
Exemplo n.º 3
0
    def set_img(self, img, clear_mask=True):
        if not isinstance(img, np.ndarray):
            return

        self._img_size = [img.shape[1], img.shape[0]]
        self._data_img = imgtools.expand_image_dim(img)
        if not isinstance(img.dtype, np.uint8):
            img = imgtools.project_and_stack(img, dtype=np.uint8, factor=255)
        
        self._img = Image.fromarray(img)
            
        if clear_mask:
            self.set_mask(show=False)

        self.create_image()