Skip to content
Snippets Groups Projects
Commit 94985864 authored by LexvanGastel's avatar LexvanGastel
Browse files

vraag 22

parent d54bcaf3
No related branches found
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment