From 9498586401b6a9eb01295db624e5bb42cbf26964 Mon Sep 17 00:00:00 2001
From: LexvanGastel <l.vangastel@studen.utwente.nl>
Date: Wed, 2 Apr 2025 12:16:15 +0200
Subject: [PATCH] vraag 22

---
 Q2main.py | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/Q2main.py b/Q2main.py
index 4fd2bdd..4d9250d 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
-- 
GitLab