Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

📚 The CoCalc Library - books, templates and other resources

Views: 96178
License: OTHER
1
import numpy as np
2
3
from skimage import data
4
from skimage import draw
5
from skimage.transform import probabilistic_hough_line
6
7
from skimage.viewer import ImageViewer
8
from skimage.viewer.widgets import Slider
9
from skimage.viewer.plugins.overlayplugin import OverlayPlugin
10
from skimage.viewer.plugins.canny import CannyPlugin
11
12
13
def line_image(shape, lines):
14
image = np.zeros(shape, dtype=bool)
15
for end_points in lines:
16
end_points = np.asarray(end_points)[:, ::-1]
17
image[draw.line(*np.ravel(end_points))] = 1
18
return image
19
20
21
def hough_lines(image, *args, **kwargs):
22
lines = probabilistic_hough_line(image, threshold=0.5, *args, **kwargs)
23
image = line_image(image.shape, lines)
24
return image
25
26
27
image = data.camera()
28
canny_viewer = ImageViewer(image)
29
canny_plugin = CannyPlugin()
30
canny_viewer += canny_plugin
31
32
hough_plugin = OverlayPlugin(image_filter=hough_lines)
33
hough_plugin += Slider('line length', 0, 100, value=100, update_on='move')
34
hough_plugin += Slider('line gap', 0, 20, value=0, update_on='move')
35
36
hough_viewer = ImageViewer(canny_plugin)
37
hough_viewer += hough_plugin
38
39
canny_viewer.show()
40
41