Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 5
0
    plot(history.history, args.fig_dir, args.marker)

else:
    model = load_model(args.output_dir + "/" + args.marker + ".h5")
    rotate_result = []
    blur_result = []
    for angle in range(-45, 50, 5):
        new_test_x = []
        for i in range(len(test_x)):
            new_test_x.append(rotate(test_x[i], angle))
        new_test_x = np.expand_dims(np.array(new_test_x), 3) / 255.0
        result = model.evaluate(new_test_x, test_y, batch_size=1000)
        rotate_result.append([angle, result[0], result[1]])
    print(rotate_result)

    for radius in range(0, 7, 1):
        new_test_x = []
        for i in range(len(test_x)):
            new_test_x.append(blur(test_x[i], radius))
        new_test_x = np.expand_dims(np.array(new_test_x), 3) / 255.0
        result = model.evaluate(new_test_x, test_y, batch_size=1000)
        blur_result.append([radius, result[0], result[1]])
    print(blur_result)
    np.save(args.output_dir + "/" + args.marker + "_rotate.npy", rotate_result)
    np.save(args.output_dir + "/" + args.marker + "_blur.npy", blur_result)

    plot_compromised(rotate_result, "angle", args.fig_dir,
                     args.marker + "_rotate")
    plot_compromised(blur_result, "radius", args.fig_dir,
                     args.marker + "_blur")