segimg.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Semi-automatic-Annotation 作者: Luoyadan 项目源码 文件源码
def do_segmentation(self):
        # Apply segmentation and update the display
        """
        1) Do pre-segmentation (2 methods available)
        2) seg_index -- init with pre-segmentation result
        3) seg_disp -- each pixel is colored according to its class label
        4.1) img_arr -- on ori_img, color each pixel according to seg_disp
        4.2) img_arr -- mark boundaries of segmentations according to seg_index
        """

        ori_img = self.ref_pic.img_arr
        sp = self.seg_params

        if self.seg_method == 'slic':
            n_segments, compactness, sigma = np.int(
                sp[0]), np.int(sp[1]), sp[2]
            self.seg_index = slic(
                ori_img,
                n_segments=n_segments,
                compactness=compactness,
                sigma=sigma)

        elif self.seg_method == 'felzenszwalb':
            scale, min_size, sigma = np.int(sp[0]), np.int(sp[1]), sp[2]
            self.seg_index = felzenszwalb(
                ori_img, scale=scale, min_size=min_size, sigma=sigma)

        r, c = self.seg_arr.shape
        # color_map -- one row; color_map[2] -- color of class label_2
        # seg_disp -- 3D (r*c*3); seg_disp[r, c] -- color of pixel (r, c) on
        # img according to its label
        self.seg_disp = self.color_map[self.seg_arr.ravel()].reshape((r, c, 3))
        # img_arr -- color the ori_img with the result of pixelwise labeling
        self.img_arr = np.array(
            ori_img * (1 - self.alpha) + self.alpha * self.seg_disp, dtype=np.uint8)
        self.img_arr = np.array(
            mark_boundaries(
                self.img_arr,
                self.seg_index) * 255,
            dtype=np.uint8)
        self.update()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号