-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path7_probabilistic_hough.py
39 lines (28 loc) · 1.11 KB
/
7_probabilistic_hough.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
import numpy as np
from skimage import data
from skimage import draw
from skimage.transform import probabilistic_hough_line
from skimage.viewer import ImageViewer
from skimage.viewer.widgets import Slider
from skimage.viewer.plugins.overlayplugin import OverlayPlugin
from skimage.viewer.plugins.canny import CannyPlugin
def line_image(shape, lines):
image = np.zeros(shape, dtype=bool)
for end_points in lines:
end_points = np.asarray(end_points)[:, ::-1]
image[draw.line(*np.ravel(end_points))] = 1
return image
def hough_lines(image, *args, **kwargs):
lines = probabilistic_hough_line(image, threshold=0.5, *args, **kwargs)
image = line_image(image.shape, lines)
return image
image = data.camera()
canny_viewer = ImageViewer(image)
canny_plugin = CannyPlugin()
canny_viewer += canny_plugin
hough_plugin = OverlayPlugin(image_filter=hough_lines)
hough_plugin += Slider('line length', 0, 100, value=100, update_on='move')
hough_plugin += Slider('line gap', 0, 20, value=0, update_on='move')
hough_viewer = ImageViewer(canny_plugin)
hough_viewer += hough_plugin
canny_viewer.show()