diff --git a/Q2main.py b/Q2main.py index af4ad412686364f56c166382bece1b33370046f3..c5b086cb7571c1acc9155a7e05297de40d67e06c 100644 --- a/Q2main.py +++ b/Q2main.py @@ -1,26 +1,54 @@ +import cv2 +import matplotlib.pyplot as plt class ImageProcessor: def __init__(self, image_path): - self.image - self.image_rgb - self.image_hsv + self.image = cv2.imread(image_path) + self.image_rgb = cv2.cvtColor(self.image, cv2.COLOR_BGR2RGB) def apply_median_filter(self, kernel_size): return filterd_image def get_color_channels(self): + red_channel = self.image_rgb[:, :, 0] + green_channel = self.image_rgb[:, :, 1] + blue_channel = self.image_rgb[:, :, 2] return red_channel, green_channel, blue_channel def convert_to_hsv(self): return hsv_image class Plotter: + @staticmethod def __init__(self): pass - def plot_image_channels(self, image): - return None - + def plot_image_channels(image, red, green, blue): + fig, axes = plt.subplots(2, 2, figsize=(12,8)) + + axes[0,0].imshow(image) + axes[0,0].set_title("Original picture") + axes[0,0].axis("off") + + axes[0,1].imshow(red,cmap = "Reds") + axes[0,1].set_title("Red channel") + axes[0,1].axis("off") + + axes[1,0].imshow(green, cmap = "Greens") + axes[1,0].set_title("Green channel") + axes[1,0].axis("off") + + axes[1,1].imshow(blue, cmap = "Blues") + axes[1,1].set_title("blue channel") + axes[1,1].axis("off") + + plt.show() def plot_histograms(self, image): return None - \ No newline at end of file + +image_path = "traffic_light_image_1.png" +processor = ImageProcessor(image_path) +red, green, blue = processor.get_color_channels() + + +Plotter.plot_image_channels(processor.image_rgb,red,green,blue) \ No newline at end of file diff --git a/traffic_light_image_1.png b/traffic_light_image_1.png new file mode 100644 index 0000000000000000000000000000000000000000..5f0337be74e3e546d0f6067530363531573c2ecd Binary files /dev/null and b/traffic_light_image_1.png differ