-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect_edges_with_prewitt_mask.py
45 lines (34 loc) · 1.17 KB
/
detect_edges_with_prewitt_mask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from utils import (
get_grayscaled_image,
save_image
)
from skimage import img_as_int
import numpy
from scipy import ndimage
def _detect_edges_with_operator(image, operator):
prewitt_vertical = numpy.array(
operator,
dtype='float64'
)
return ndimage.convolve(
img_as_int(image), prewitt_vertical)
def detect_edges_with_vertical_operator(image):
vertical_operator = [
[-1, 0, 1],
[-1, 0, 1],
[-1, 0, 1]
]
return _detect_edges_with_operator(image, vertical_operator)
def detect_edges_with_horizontal_operator(image):
horizontal_operator = [
[-1, -1, 1],
[0, 0, 0],
[1, 1, 1]
]
return _detect_edges_with_operator(image, horizontal_operator)
if __name__ == '__main__':
image = get_grayscaled_image('images/kitten.jpg')
horizontally_transformed_image = detect_edges_with_horizontal_operator(image)
vertically_transformed_image = detect_edges_with_vertical_operator(image)
save_image(horizontally_transformed_image, 'images/horizontally_transformed_kitten.jpg')
save_image(vertically_transformed_image, 'images/vertically_transformed_image.jpg')