コード例 #1
0
def display_threshld_image(image, threshold_value, max_value, save_image=True):
    threshlded_image = processing.get_threshlded_image(image, threshold_value,
                                                       max_value)

    key_values, color_map_type = get_plot_configs()

    plot_title = "Image type"
    image_info = [
        {
            key_values[0]: image,
            key_values[1]: "color image",
            key_values[2]: color_map_type["color"]
        },
        {
            key_values[0]: threshlded_image,
            key_values[1]: "thresholded Image",
            key_values[2]: color_map_type["gray"]
        },
    ]

    plot_size = get_plot_size(len(image_info))
    plot_image(plot_size=plot_size,
               plot_title=plot_title,
               image_info=image_info,
               key_values=key_values)

    if save_image:
        file_name = get_full_output_path("Color_Image_thresholded.jpg")
        cv2.imwrite(file_name, threshlded_image)
コード例 #2
0
def display_resized_image(image, scale_percent, save_image=True):
    resized_image = processing.get_resized_image(image, scale_percent)

    key_values, color_map_type = get_plot_configs()

    plot_title = "resize image by " + str(scale_percent) + " of its size"
    image_info = [
        {
            key_values[0]: image,
            key_values[1]: "original image",
            key_values[2]: color_map_type["color"]
        },
        {
            key_values[0]: resized_image,
            key_values[1]: "resized image",
            key_values[2]: color_map_type["color"]
        },
    ]

    plot_size = get_plot_size(len(image_info))
    plot_image(plot_size=plot_size,
               plot_title=plot_title,
               image_info=image_info,
               key_values=key_values)

    if save_image:
        file_name = get_full_output_path("Color_Image_resized.jpg")
        cv2.imwrite(file_name, cv2.cvtColor(resized_image, cv2.COLOR_BGR2RGB))
コード例 #3
0
def display_tiled_image(image, tile_count, colors, save_image=True):
    tiled_image = processing.get_tiled_image(image, tile_count, colors)

    key_values, color_map_type = get_plot_configs()

    plot_title = "tiled image "
    image_info = [
        {
            key_values[0]: image,
            key_values[1]: "original image",
            key_values[2]: color_map_type["color"]
        },
        {
            key_values[0]: tiled_image,
            key_values[1]: "tiled image",
            key_values[2]: color_map_type["color"]
        },
    ]

    plot_size = get_plot_size(len(image_info))
    plot_image(plot_size=plot_size,
               plot_title=plot_title,
               image_info=image_info,
               key_values=key_values)

    if save_image:
        file_name = get_full_output_path("Color_Image_modified.jpg")
        cv2.imwrite(file_name, cv2.cvtColor(tiled_image, cv2.COLOR_BGR2RGB))
コード例 #4
0
    def show(self, image, **args):
        if not isinstance(args, dict):
            raise AssertionError("args should be provided as a dict")
        if len(args) != 2:
            raise AssertionError("args is invalid!")

        arg_list = list(args.keys())
        threshold_value = args[arg_list[0]]
        max_value = args[arg_list[1]]
        threshlded_image = processing.get_threshlded_image(
            image, threshold_value, max_value)

        image_info = [
            {
                self.key_values[0]: image,
                self.key_values[1]: "color image",
                self.key_values[2]: self.color_map_type["color"]
            },
            {
                self.key_values[0]: threshlded_image,
                self.key_values[1]: "thresholded Image",
                self.key_values[2]: self.color_map_type["gray"]
            },
        ]

        self.plot_image(image_info)

        if self.save_image:
            file_name = get_full_output_path("Color_Image_thresholded.jpg")
            cv2.imwrite(file_name, threshlded_image)
コード例 #5
0
def display_gray_scale_image(image, save_image=True):
    grayscale_imag = processing.get_grayscale_image(image)

    key_values, color_map_type = get_plot_configs()

    plot_title = "Image type"
    image_info = [
        {
            key_values[0]: image,
            key_values[1]: "color image",
            key_values[2]: color_map_type["color"]
        },
        {
            key_values[0]: grayscale_imag,
            key_values[1]: "gray Image",
            key_values[2]: color_map_type["gray"]
        },
    ]

    plot_size = get_plot_size(len(image_info))
    plot_image(plot_size=plot_size,
               plot_title=plot_title,
               image_info=image_info,
               key_values=key_values)

    if save_image:
        file_name = get_full_output_path("gray_Image.jpg")
        cv2.imwrite(file_name, grayscale_imag)
コード例 #6
0
    def show(self, image, **args):
        if not isinstance(args, dict):
            raise AssertionError("args should be provided as a dict")
        if len(args) != 2:
            raise AssertionError("args is invalid!")

        arg_list = list(args.keys())
        tile_count = args[arg_list[0]]
        colors = args[arg_list[1]]
        tiled_image = processing.get_tiled_image(image, tile_count, colors)

        image_info = [
            {
                self.key_values[0]: image,
                self.key_values[1]: "original image",
                self.key_values[2]: self.color_map_type["color"]
            },
            {
                self.key_values[0]: tiled_image,
                self.key_values[1]: "tiled image",
                self.key_values[2]: self.color_map_type["color"]
            },
        ]

        self.plot_image(image_info)

        if self.save_image:
            file_name = get_full_output_path("Color_Image_modified.jpg")
            cv2.imwrite(file_name, cv2.cvtColor(tiled_image,
                                                cv2.COLOR_BGR2RGB))
コード例 #7
0
    def show(self, image, **args):
        if not isinstance(args, dict):
            raise AssertionError("args should be provided as a dict")
        if len(args) != 1:
            raise AssertionError("args is invalid!")

        scale_percent = next(iter(args.values()))
        resized_image = processing.get_resized_image(image, scale_percent)

        self.plot_title = "Resized image by " + str(
            scale_percent) + " of its size"
        image_info = [
            {
                self.key_values[0]: image,
                self.key_values[1]: "original image",
                self.key_values[2]: self.color_map_type["color"]
            },
            {
                self.key_values[0]: resized_image,
                self.key_values[1]: "resized image",
                self.key_values[2]: self.color_map_type["color"]
            },
        ]

        self.plot_image(image_info)

        if self.save_image:
            file_name = get_full_output_path("Color_Image_resized.jpg")
            cv2.imwrite(file_name,
                        cv2.cvtColor(resized_image, cv2.COLOR_BGR2RGB))
コード例 #8
0
    def show(self, image, **args):
        if not isinstance(args, dict):
            raise AssertionError("args should be provided as a dict")
        if len(args) != 0:
            raise AssertionError("args is invalid!")

        grayscale_imag = processing.get_grayscale_image(image)

        image_info = [
            {
                self.key_values[0]: image,
                self.key_values[1]: "color image",
                self.key_values[2]: self.color_map_type["color"]
            },
            {
                self.key_values[0]: grayscale_imag,
                self.key_values[1]: "grayscaled image",
                self.key_values[2]: self.color_map_type["gray"]
            },
        ]

        self.plot_image(image_info)

        if self.save_image:
            file_name = get_full_output_path("gray_Image.jpg")
            cv2.imwrite(file_name, grayscale_imag)
コード例 #9
0
def display_color_channels(image, save_image=True):
    #extract red channel
    blue_channel, green_channel, red_channel = get_channels(image)

    key_values, color_map_type = get_plot_configs()

    plot_title = "color image and its channels"
    image_info = [
        {
            key_values[0]: image,
            key_values[1]: "Original image",
            key_values[2]: color_map_type["color"]
        },
        {
            key_values[0]: blue_channel,
            key_values[1]: "blue channel",
            key_values[2]: color_map_type["gray"]
        },
        {
            key_values[0]: green_channel,
            key_values[1]: "green channl",
            key_values[2]: color_map_type["gray"]
        },
        {
            key_values[0]: red_channel,
            key_values[1]: "red channl",
            key_values[2]: color_map_type["gray"]
        },
    ]

    plot_size = get_plot_size(len(image_info))
    plot_image(plot_size=plot_size,
               plot_title=plot_title,
               image_info=image_info,
               key_values=key_values)

    if save_image:
        file_name = get_full_output_path("blue_channel.jpg")
        cv2.imwrite(file_name, blue_channel)

        file_name = get_full_output_path("green_channel.jpg")
        cv2.imwrite(file_name, green_channel)

        file_name = get_full_output_path("red_channel.jpg")
        cv2.imwrite(file_name, red_channel)
コード例 #10
0
    def show(self, image, **args):
        if not isinstance(args, dict):
            raise AssertionError("args should be provided as a dict")
        if len(args) != 0:
            raise AssertionError("args is invalid!")

        blue_image, green_image, red_image = ImageInfo.get_image_channels(
            image)

        image_info = [
            {
                self.key_values[0]: image,
                self.key_values[1]: "Original image",
                self.key_values[2]: self.color_map_type["color"]
            },
            {
                self.key_values[0]: blue_image,
                self.key_values[1]: "blue channel",
                self.key_values[2]: self.color_map_type["color"]
            },
            {
                self.key_values[0]: green_image,
                self.key_values[1]: "green channl",
                self.key_values[2]: self.color_map_type["color"]
            },
            {
                self.key_values[0]: red_image,
                self.key_values[1]: "red channl",
                self.key_values[2]: self.color_map_type["color"]
            },
        ]

        self.plot_image(image_info)

        if self.save_image:
            file_name = get_full_output_path("Color_Image_blue.jpg")
            cv2.imwrite(file_name, cv2.cvtColor(blue_image, cv2.COLOR_BGR2RGB))

            file_name = get_full_output_path("Color_Image_green.jpg")
            cv2.imwrite(file_name, cv2.cvtColor(green_image,
                                                cv2.COLOR_BGR2RGB))

            file_name = get_full_output_path("Color_Image_red.jpg")
            cv2.imwrite(file_name, cv2.cvtColor(red_image, cv2.COLOR_BGR2RGB))
コード例 #11
0
def display_color_image(image, save_image=True):
    blue_image, green_image, red_image = get_image_channels(image)

    key_values, color_map_type = get_plot_configs()
    plot_title = "color image and its channels"
    image_info = [
        {
            key_values[0]: image,
            key_values[1]: "Original image",
            key_values[2]: color_map_type["color"]
        },
        {
            key_values[0]: blue_image,
            key_values[1]: "blue channel",
            key_values[2]: color_map_type["color"]
        },
        {
            key_values[0]: green_image,
            key_values[1]: "green channl",
            key_values[2]: color_map_type["color"]
        },
        {
            key_values[0]: red_image,
            key_values[1]: "red channl",
            key_values[2]: color_map_type["color"]
        },
    ]

    plot_size = get_plot_size(len(image_info))
    plot_image(plot_size=plot_size,
               plot_title=plot_title,
               image_info=image_info,
               key_values=key_values)

    if save_image:
        file_name = get_full_output_path("Color_Image_blue.jpg")
        cv2.imwrite(file_name, cv2.cvtColor(blue_image, cv2.COLOR_BGR2RGB))

        file_name = get_full_output_path("Color_Image_green.jpg")
        cv2.imwrite(file_name, cv2.cvtColor(green_image, cv2.COLOR_BGR2RGB))

        file_name = get_full_output_path("Color_Image_red.jpg")
        cv2.imwrite(file_name, cv2.cvtColor(red_image, cv2.COLOR_BGR2RGB))
コード例 #12
0
def display_convlution(image, save_image=True):
    laplacian = np.array(([0, 1, 0], [1, -4, 1], [0, 1, 0]), dtype="int")

    # construct the Sobel x-axis kernel
    sobelX = np.array(([-1, 0, 1], [-2, 0, 2], [-1, 0, 1]), dtype="int")

    # construct the Sobel y-axis kernel
    sobelY = np.array(([-1, -2, -1], [0, 0, 0], [1, 2, 1]), dtype="int")
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    conv_x = processing.convolve(gray, sobelX)
    post_process_conv_image(conv_x)

    conv_y = processing.convolve(gray, sobelY)
    post_process_conv_image(conv_y)

    conv_laplacian = processing.convolve(gray, laplacian)
    post_process_conv_image(conv_laplacian)

    # merger X and Y
    conv_x_y = conv_x.copy()
    conv_x_y = conv_x.__add__(conv_y)

    key_values, color_map_type = get_plot_configs()

    plot_title = "Edge extraction"
    image_info = [
        {
            key_values[0]: image,
            key_values[1]: "Original image",
            key_values[2]: color_map_type["color"]
        },
        {
            key_values[0]: gray,
            key_values[1]: "grayscale image",
            key_values[2]: color_map_type["gray"]
        },
        {
            key_values[0]: conv_x,
            key_values[1]: "sobelX image",
            key_values[2]: color_map_type["gray"]
        },
        {
            key_values[0]: conv_y,
            key_values[1]: "sobelY image",
            key_values[2]: color_map_type["gray"]
        },
        {
            key_values[0]: conv_x_y,
            key_values[1]: "sobelX_Y image",
            key_values[2]: color_map_type["gray"]
        },
        {
            key_values[0]: conv_laplacian,
            key_values[1]: "laplacian image",
            key_values[2]: color_map_type["gray"]
        },
    ]
    plot_size = get_plot_size(len(image_info))
    plot_image(plot_size=plot_size,
               plot_title=plot_title,
               image_info=image_info,
               key_values=key_values)

    if save_image:
        file_name = get_full_output_path("conv_gray_Image.jpg")
        cv2.imwrite(file_name, gray)

        file_name = get_full_output_path("conv_x.jpg")
        cv2.imwrite(file_name, conv_x)

        file_name = get_full_output_path("conv_y.jpg")
        cv2.imwrite(file_name, conv_y)

        file_name = get_full_output_path("conv_x_y.jpg")
        cv2.imwrite(file_name, conv_x_y)

        file_name = get_full_output_path("conv_laplacian.jpg")
        cv2.imwrite(file_name, conv_laplacian)
コード例 #13
0
    def show(self, image, **args):
        if not isinstance(args, dict):
            raise AssertionError("args should be provided as a dict")
        if len(args) > 0:
            raise AssertionError("args is invalid!")

        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

        conv_x = processing.convolve(gray, self.sobelX)
        self.post_process_conv_image(conv_x)

        conv_y = processing.convolve(gray, self.sobelY)
        self.post_process_conv_image(conv_y)

        conv_laplacian = processing.convolve(gray, self.laplacian)
        self.post_process_conv_image(conv_laplacian)

        # merger X and Y
        conv_x_y = conv_x.copy()
        conv_x_y = conv_x.__add__(conv_y)

        image_info = [{
            self.key_values[0]: image,
            self.key_values[1]: "Original image",
            self.key_values[2]: self.color_map_type["color"]
        }, {
            self.key_values[0]: gray,
            self.key_values[1]: "grayscale image",
            self.key_values[2]: self.color_map_type["gray"]
        }, {
            self.key_values[0]: conv_x,
            self.key_values[1]: "sobelX image",
            self.key_values[2]: self.color_map_type["gray"]
        }, {
            self.key_values[0]: conv_y,
            self.key_values[1]: "sobelY image",
            self.key_values[2]: self.color_map_type["gray"]
        }, {
            self.key_values[0]: conv_x_y,
            self.key_values[1]: "sobelX_Y image",
            self.key_values[2]: self.color_map_type["gray"]
        }, {
            self.key_values[0]: conv_laplacian,
            self.key_values[1]: "laplacian image",
            self.key_values[2]: self.color_map_type["gray"]
        }]

        self.plot_image(image_info)

        if self.save_image:
            file_name = get_full_output_path("conv_gray_Image.jpg")
            cv2.imwrite(file_name, gray)

            file_name = get_full_output_path("conv_x.jpg")
            cv2.imwrite(file_name, conv_x)

            file_name = get_full_output_path("conv_y.jpg")
            cv2.imwrite(file_name, conv_y)

            file_name = get_full_output_path("conv_x_y.jpg")
            cv2.imwrite(file_name, conv_x_y)

            file_name = get_full_output_path("conv_laplacian.jpg")
            cv2.imwrite(file_name, conv_laplacian)