示例#1
0
 def on(self, image: Image, mask: Image):
     color_mask = mask.to_color()
     color_mask[mask.to_gray() > 0, :] = self._color
     color_mask[mask.to_gray() <= 0, :] = [0, 0, 0]
     result = cv2.addWeighted(
         src1=image.to_color(), alpha=0.9,
         src2=color_mask, beta=0.1,
         gamma=0
     )
     return Image(result)
示例#2
0
    def on(self, img1: Image, img2: Image) -> Image:
        """Operate on two images"""
        if self._color == "color":
            img1 = img1.to_color()
            img2 = img2.to_color()
        elif self._color == "gray":
            img1 = img1.to_gray()
            img2 = img2.to_gray()
        elif self._color != "unchanged":
            msg = "Unrecognized color option: {}".format(self._color)
            raise ValueError(msg)

        if self._cvt_to_f32:
            img1 = img1.astype(np.float32, copy=False)
            img2 = img2.astype(np.float32, copy=False)

        result_array = self._operate(img1, img2)
        name = "{} on ({}, {})".format(
            self.__class__.__name__, img1.name, img2.name
        )
        return Image(result_array, name=name)
示例#3
0
    def on(self, img: Image) -> Image:
        """Operate on single image"""
        if self._color == "color":
            img = img.to_color()
        elif self._color == "gray":
            img = img.to_gray()
        elif self._color != "unchanged":
            msg = "Unrecognized color option: {}".format(self._color)
            raise ValueError(msg)

        if self._cvt_to_f32:
            img = img.astype(np.float32, copy=False)
        result_array = self._operate(img)
        name = "{} on ".format(self.__class__.__name__) + img.name
        return Image(result_array, name=name)