Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
assignment Programming 2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gastel, L. van (Lex, Student B-BMT)
assignment Programming 2
Commits
9150874c
Commit
9150874c
authored
6 days ago
by
LexvanGastel
Browse files
Options
Downloads
Patches
Plain Diff
vraag 24
parent
94985864
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Q2main.py
+25
-7
25 additions, 7 deletions
Q2main.py
with
25 additions
and
7 deletions
Q2main.py
+
25
−
7
View file @
9150874c
...
...
@@ -7,8 +7,9 @@ class ImageProcessor:
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
apply_median_filter
(
self
,
kernel_size
=
5
):
filtered_image
=
cv2
.
medianBlur
(
self
.
image_rgb
,
kernel_size
)
return
filtered_image
def
get_color_channels
(
self
):
red_channel
=
self
.
image_rgb
[:,
:,
0
]
...
...
@@ -73,7 +74,21 @@ class Plotter:
axes
[
2
].
set_ylabel
(
'
Frequency
'
)
#plt.show()
@staticmethod
def
plot_filtered_image
(
original
,
filtered
):
fig
,
axes
=
plt
.
subplots
(
1
,
2
,
figsize
=
(
12
,
6
))
axes
[
0
].
imshow
(
original
)
axes
[
0
].
set_title
(
"
Original Image
"
)
axes
[
0
].
axis
(
"
off
"
)
axes
[
1
].
imshow
(
filtered
)
axes
[
1
].
set_title
(
"
Filtered Image (Median Blur)
"
)
axes
[
1
].
axis
(
"
off
"
)
plt
.
show
()
image_path
=
"
traffic_light_image_1.png
"
processor
=
ImageProcessor
(
image_path
)
red
,
green
,
blue
=
processor
.
get_color_channels
()
...
...
@@ -82,10 +97,13 @@ 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
:
.
2
f
}
"
)
print
(
f
"
SNR for Green Channel
{
snr_green
:
.
2
f
}
"
)
print
(
f
"
SNR for Blue Channel
{
snr_blue
:
.
2
f
}
"
)
#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}")
filtered_image
=
processor
.
apply_median_filter
(
kernel_size
=
5
)
Plotter
.
plot_image_channels
(
processor
.
image_rgb
,
red
,
green
,
blue
)
Plotter
.
plot_histograms
(
red
,
green
,
blue
)
\ No newline at end of file
Plotter
.
plot_histograms
(
red
,
green
,
blue
)
Plotter
.
plot_filtered_image
(
processor
.
image_rgb
,
filtered_image
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment