diff --git a/Q2main.py b/Q2main.py index c5b086cb7571c1acc9155a7e05297de40d67e06c..4fd2bdd754587f1464e5a5aae7846e0795f2f8f4 100644 --- a/Q2main.py +++ b/Q2main.py @@ -16,13 +16,14 @@ class ImageProcessor: return red_channel, green_channel, blue_channel def convert_to_hsv(self): - return hsv_image + hsv_image =cv2.cv2.cvtColor(self.image, cv2.COLOR_BGR2HSV) class Plotter: @staticmethod def __init__(self): pass - + + @staticmethod def plot_image_channels(image, red, green, blue): fig, axes = plt.subplots(2, 2, figsize=(12,8)) @@ -43,12 +44,31 @@ class Plotter: axes[1,1].axis("off") plt.show() - def plot_histograms(self, image): - return None + @staticmethod + def plot_histograms(red, green ,blue): + fig, axes = plt.subplots(1,3, figsize =(15,5)) + + axes[0].hist(red.ravel(), bins=256, color="red", alpha= 0.7) + axes[0].set_title('Red Channel Histogram') + axes[0].set_xlabel('Pixel Intensity') + axes[0].set_ylabel('Frequency') + + axes[1].hist(green.ravel(), bins=256, color="green", alpha= 0.7) + axes[1].set_title('Green Channel Histogram') + axes[1].set_xlabel('Pixel Intensity') + axes[1].set_ylabel('Frequency') + + axes[2].hist(blue.ravel(), bins=256, color="blue", alpha= 0.7) + axes[2].set_title('Blue Channel Histogram') + axes[2].set_xlabel('Pixel Intensity') + axes[2].set_ylabel('Frequency') + + plt.show() 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 +Plotter.plot_image_channels(processor.image_rgb,red,green,blue) +Plotter.plot_histograms(red, green, blue) \ No newline at end of file