Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
labo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
visnum
labo
Commits
f5c272cb
Verified
Commit
f5c272cb
authored
1 year ago
by
iliya.saroukha
Browse files
Options
Downloads
Patches
Plain Diff
feat: sobel fully done lab4
parent
2c7849db
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
labo4.py
+36
-11
36 additions, 11 deletions
labo4.py
with
36 additions
and
11 deletions
labo4.py
+
36
−
11
View file @
f5c272cb
...
@@ -8,6 +8,17 @@ from enum import Enum
...
@@ -8,6 +8,17 @@ from enum import Enum
Img
=
npt
.
NDArray
[
np
.
uint8
]
Img
=
npt
.
NDArray
[
np
.
uint8
]
class
Isotropy
(
Enum
):
ISO_90
=
1
ISO_45
=
2
class
Orientation
(
Enum
):
HORIZONTAL
=
1
VERTICAL
=
2
X_Y
=
3
def
load_img
(
path
:
str
)
->
Img
:
def
load_img
(
path
:
str
)
->
Img
:
img
=
np
.
array
(
Image
.
open
(
path
))
img
=
np
.
array
(
Image
.
open
(
path
))
...
@@ -79,11 +90,6 @@ def rgb_to_gray(img: Img) -> Img:
...
@@ -79,11 +90,6 @@ def rgb_to_gray(img: Img) -> Img:
return
new_image
return
new_image
class
Isotropy
(
Enum
):
ISO_90
=
1
ISO_45
=
2
def
laplace
(
img
:
Img
,
isotropy
:
Isotropy
)
->
Img
:
def
laplace
(
img
:
Img
,
isotropy
:
Isotropy
)
->
Img
:
match
(
isotropy
):
match
(
isotropy
):
case
isotropy
.
ISO_90
:
case
isotropy
.
ISO_90
:
...
@@ -118,10 +124,26 @@ def gauss_kernel(length: int = 3, sigma: float = 1.0) -> Img:
...
@@ -118,10 +124,26 @@ def gauss_kernel(length: int = 3, sigma: float = 1.0) -> Img:
return
kernel
/
np
.
sum
(
kernel
)
return
kernel
/
np
.
sum
(
kernel
)
def
sobel_filter
(
img
:
Img
,
orientation
:
Orientation
)
->
Img
:
kernel
=
np
.
array
([[
1
,
2
,
1
],
[
0
,
0
,
0
],
[
-
1
,
-
2
,
-
1
]])
match
(
orientation
):
case
orientation
.
VERTICAL
:
return
xcorr
(
img
,
kernel
)
case
orientation
.
HORIZONTAL
:
return
xcorr
(
img
,
kernel
.
T
)
case
orientation
.
X_Y
:
return
xcorr
(
img
,
kernel
+
kernel
.
T
)
case
_
:
print
(
"
Invalid orientation value
"
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
img
=
load_img
(
"
resources/noisy_hotel.png
"
)
img
=
load_img
(
"
resources/noisy_hotel.png
"
)
gray
=
rgb_to_gray
(
img
)
gray
=
rgb_to_gray
(
img
)
# show_image(sobel_filter(gray, Orientation.HORIZONTAL))
laplacian
=
laplace
(
xcorr
(
gray
,
gauss_kernel
()),
Isotropy
.
ISO_45
)
laplacian
=
laplace
(
xcorr
(
gray
,
gauss_kernel
()),
Isotropy
.
ISO_45
)
thresholded
=
thresholding
(
laplacian
,
50
)
thresholded
=
thresholding
(
laplacian
,
50
)
...
@@ -130,14 +152,17 @@ if __name__ == "__main__":
...
@@ -130,14 +152,17 @@ if __name__ == "__main__":
fig
,
axs
=
plt
.
subplots
(
nrows
=
1
,
ncols
=
3
,
figsize
=
(
12
,
6
))
fig
,
axs
=
plt
.
subplots
(
nrows
=
1
,
ncols
=
3
,
figsize
=
(
12
,
6
))
axs
[
0
].
imshow
(
gray
,
cmap
=
"
gray
"
,
vmin
=
0
,
vmax
=
255
)
axs
[
0
].
imshow
(
sobel_filter
(
gray
,
Orientation
.
VERTICAL
),
axs
[
0
].
set_title
(
'
Original image
'
)
cmap
=
"
gray
"
,
vmin
=
0
,
vmax
=
255
)
axs
[
0
].
set_title
(
'
Vertical Sobel filter
'
)
axs
[
1
].
imshow
(
sharp_iso_90
,
cmap
=
"
gray
"
,
vmin
=
0
,
vmax
=
255
)
axs
[
1
].
imshow
(
sobel_filter
(
gray
,
Orientation
.
HORIZONTAL
),
axs
[
1
].
set_title
(
'
Sharpened (Laplacian filter, isotropy 90)
'
)
cmap
=
"
gray
"
,
vmin
=
0
,
vmax
=
255
)
axs
[
1
].
set_title
(
'
Horizontal Sobel filter
'
)
axs
[
2
].
imshow
(
sharp_iso_45
,
cmap
=
"
gray
"
,
vmin
=
0
,
vmax
=
255
)
axs
[
2
].
imshow
(
sobel_filter
(
gray
,
Orientation
.
X_Y
),
axs
[
2
].
set_title
(
'
Sharpened (Laplacian filter, isotropy 45)
'
)
cmap
=
"
gray
"
,
vmin
=
0
,
vmax
=
255
)
axs
[
2
].
set_title
(
'
Sobel filter (both axis)
'
)
plt
.
tight_layout
()
plt
.
tight_layout
()
plt
.
show
()
plt
.
show
()
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