Example #1
0
    def do_preprocess(self, img):
        x = np.copy(img)

        if self.properties["autocrop"]["enabled"]:
            x = preprocess.autocrop(x)

        if x is None:
            return None

        x = preprocess.blur(
            x, gaussian_blur=self.properties["gaussian_blur"], median_blur=self.properties["median_blur"]
        )

        if self.properties["grey"]["enabled"]:
            x = preprocess.grey(x)

        if self.properties["resize"]["enabled"]:
            x = preprocess.resize(x, (self.properties["resize"]["width"], self.properties["resize"]["height"]))
        elif self.properties["scale_max"]["enabled"]:
            x = preprocess.scale_max(x, self.properties["scale_max"]["width"], self.properties["scale_max"]["height"])

        if self.properties["convert_to_matrix_colors"]["enabled"]:
            (matrix, cluster_centers_, labels, background_label) = improc.color.Matrix_scikit_kmeans(
                x, self.properties["convert_to_matrix_colors"]["number_of_colors"]
            )
            x = improc.color.Image_from_matrix(
                matrix,
                self.properties["convert_to_matrix_colors"]["height"],
                self.properties["convert_to_matrix_colors"]["width"],
            )

        return x
Example #2
0
    def do_preprocess(self, img):
        x = np.copy(img)
        if x is not None and self.properties["autocrop"]["enabled"]:
            x = preprocess.autocrop(x)

        if x is not None:
            x = preprocess.blur(
                x, gaussian_blur=self.properties["gaussian_blur"], median_blur=self.properties["median_blur"]
            )

        if x is not None and self.properties["grey"]["enabled"]:
            x = preprocess.grey(x)

        if x is not None and self.properties["bitwise"]["enabled"]:
            x = preprocess.bitwise(x)

        if x is not None and self.properties["canny"]["enabled"]:
            x = preprocess.canny(x, self.properties["canny"]["threshold1"], self.properties["canny"]["threshold2"])

        if x is not None and self.properties["laplacian"]["enabled"]:
            x = preprocess.laplacian(x)

        if x is not None and self.properties["thresh"]["enabled"]:
            x = preprocess.thresh(x)

        if x is not None and self.properties["closing"]["enabled"]:
            x = preprocess.closing(x, self.properties["closing"]["width"], self.properties["closing"]["height"])

        if x is not None and self.properties["dilate"]["enabled"]:
            x = preprocess.dilate(
                x,
                self.properties["dilate"]["width"],
                self.properties["dilate"]["height"],
                self.properties["dilate"]["iterations"],
            )

        if x is not None and self.properties["outline_contour"]["enabled"]:
            x = preprocess.outline_contour(x)

        if x is not None and self.properties["resize"]["enabled"]:
            x = preprocess.resize(x, (self.properties["resize"]["width"], self.properties["resize"]["height"]))
        elif x is not None and self.properties["scale_max"]["enabled"]:
            x = preprocess.scale_max(x, self.properties["scale_max"]["width"], self.properties["scale_max"]["height"])

        if x is not None and self.properties["add_border"]["enabled"]:
            x = preprocess.add_border(
                x,
                border_size=self.properties["add_border"]["border_size"],
                color_value=self.properties["add_border"]["color_value"],
                fill_dimensions=self.properties["add_border"]["fill_dimensions"],
            )

        return x
Example #3
0
    def do_preprocess(self, img):
        x = np.copy(img)

        if self.properties["autocrop"]["enabled"]:
            x = preprocess.autocrop(x)

        if x is None:
            return None

        x = preprocess.blur(
            x,
            gaussian_blur=self.properties["gaussian_blur"],
            median_blur=self.properties["median_blur"]

        )

        if self.properties["grey"]["enabled"]:
            x = preprocess.grey(x)

        if self.properties["resize"]["enabled"]:
            x = preprocess.resize(
                x,
                (
                    self.properties["resize"]["width"],
                    self.properties["resize"]["height"]
                )
            )
        elif self.properties["scale_max"]["enabled"]:
            x = preprocess.scale_max(
                x,
                self.properties["scale_max"]["width"],
                self.properties["scale_max"]["height"]
            )

        if self.properties["convert_to_matrix_colors"]["enabled"]:
            (
                matrix, cluster_centers_, labels, background_label
            ) = improc.color.Matrix_scikit_kmeans(
                x,
                self.properties["convert_to_matrix_colors"]["number_of_colors"]
            )
            x = improc.color.Image_from_matrix(
                matrix,
                self.properties["convert_to_matrix_colors"]["height"],
                self.properties["convert_to_matrix_colors"]["width"]
            )

        return x
Example #4
0
    def do_preprocess(self, img):
        x = np.copy(img)
        if x is not None and self.properties["autocrop"]["enabled"]:
            x = preprocess.autocrop(x)

        if x is not None:
            x = preprocess.blur(
                x,
                gaussian_blur=self.properties["gaussian_blur"],
                median_blur=self.properties["median_blur"]
            )

        if x is not None and self.properties["grey"]["enabled"]:
            x = preprocess.grey(x)

        if x is not None and self.properties["bitwise"]["enabled"]:
            x = preprocess.bitwise(x)

        if x is not None and self.properties["canny"]["enabled"]:
            x = preprocess.canny(
                x,
                self.properties["canny"]["threshold1"],
                self.properties["canny"]["threshold2"]
            )

        if x is not None and self.properties["laplacian"]["enabled"]:
            x = preprocess.laplacian(x)

        if x is not None and self.properties["thresh"]["enabled"]:
            x = preprocess.thresh(x)

        if x is not None and self.properties["closing"]["enabled"]:
            x = preprocess.closing(
                x,
                self.properties["closing"]["width"],
                self.properties["closing"]["height"]
            )

        if x is not None and self.properties["dilate"]["enabled"]:
            x = preprocess.dilate(
                x,
                self.properties["dilate"]["width"],
                self.properties["dilate"]["height"],
                self.properties["dilate"]["iterations"]
            )

        if x is not None and self.properties["outline_contour"]["enabled"]:
            x = preprocess.outline_contour(x)

        if x is not None and self.properties["resize"]["enabled"]:
            x = preprocess.resize(
                x,
                (
                    self.properties["resize"]["width"],
                    self.properties["resize"]["height"]
                )
            )
        elif x is not None and self.properties["scale_max"]["enabled"]:
            x = preprocess.scale_max(
                x,
                self.properties["scale_max"]["width"],
                self.properties["scale_max"]["height"]
            )

        if x is not None and self.properties["add_border"]["enabled"]:
            x = preprocess.add_border(
                x,
                border_size=self.properties["add_border"]["border_size"],
                color_value=self.properties["add_border"]["color_value"],
                fill_dimensions=self.properties["add_border"]["fill_dimensions"]
            )

        return x