-
Notifications
You must be signed in to change notification settings - Fork 0
/
canny_edge_detector.py
37 lines (33 loc) · 1.34 KB
/
canny_edge_detector.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
import numpy as np
from double_thresholding import DoubleThresholding
from gaussian_blur import GaussianBlur
from gradient_calculator import GradientCalculator
from hysteresis import Hysteresis
from nonmaximum_suppression import NonMaximumSuppression
from picture import Picture
class CannyEdgeDetector:
def __init__(
self,
url,
sigma=0.84049642,
kernel_size=9,
lower_threshold=50,
upper_threshold=125,
):
self.picture = Picture(url)
self.gaussian_blur = GaussianBlur(sigma, kernel_size)
self.intensities = self.gaussian_blur.apply(self.picture)
self.gradient_calculator = GradientCalculator(self.intensities)
magnitudes, angles = self.gradient_calculator.get_magnitudes_and_angles()
self.nonmaximum_suppression = NonMaximumSuppression(magnitudes, angles)
thinned = self.nonmaximum_suppression.apply_suppression()
self.double_thresholding = DoubleThresholding(
thinned, lower_threshold, upper_threshold
)
mapping = self.double_thresholding.apply()
self.hysteresis = Hysteresis(thinned, mapping)
self.strong_edges = self.hysteresis.apply()
def apply(self):
self.picture.show_image_from_intensities(self.strong_edges)
def save(self, url):
self.picture.save_image(url, self.strong_edges)