diff --git a/Q2main.py b/Q2main.py index 4fd2bdd754587f1464e5a5aae7846e0795f2f8f4..4d9250d95289058bdaeebc0a00ba70c768a3556e 100644 --- a/Q2main.py +++ b/Q2main.py @@ -1,5 +1,6 @@ import cv2 import matplotlib.pyplot as plt +import numpy as np class ImageProcessor: def __init__(self, image_path): @@ -17,6 +18,14 @@ class ImageProcessor: def convert_to_hsv(self): hsv_image =cv2.cv2.cvtColor(self.image, cv2.COLOR_BGR2HSV) + + def calculate_snr(self, channel): + mean = np.mean(channel) + stddev = np.std(channel) + snr = mean / stddev + return snr + + class Plotter: @staticmethod @@ -43,7 +52,7 @@ class Plotter: axes[1,1].set_title("blue channel") axes[1,1].axis("off") - plt.show() + #plt.show() @staticmethod def plot_histograms(red, green ,blue): fig, axes = plt.subplots(1,3, figsize =(15,5)) @@ -63,12 +72,20 @@ class Plotter: axes[2].set_xlabel('Pixel Intensity') axes[2].set_ylabel('Frequency') - plt.show() + #plt.show() image_path = "traffic_light_image_1.png" processor = ImageProcessor(image_path) red, green, blue = processor.get_color_channels() +snr_red = processor.calculate_snr(red) +snr_green = processor.calculate_snr(green) +snr_blue = processor.calculate_snr(blue) + +print(f"SNR for Red Channel {snr_red:.2f}") +print(f"SNR for Green Channel {snr_green:.2f}") +print(f"SNR for Blue Channel {snr_blue:.2f}") + Plotter.plot_image_channels(processor.image_rgb,red,green,blue) Plotter.plot_histograms(red, green, blue) \ No newline at end of file