-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathexample.py
More file actions
37 lines (28 loc) · 1.1 KB
/
example.py
File metadata and controls
37 lines (28 loc) · 1.1 KB
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
from typing import List
from swt_python3 import swt
from skimage import draw
from skimage.io import imread, imshow, imsave
def rectangle_perimeter(r0, c0, width, height, shape=None, clip=False):
rr, cc = [r0, r0 + width, r0 + width, r0], [c0, c0, c0 + height, c0 + height]
return draw.polygon_perimeter(rr, cc, shape=shape, clip=clip)
if __name__ == "__main__":
image_name = "input.jpg"
buffer = open(image_name, "rb").read()
import time
start = time.time()
swt_result: List[dict] = swt(buffer, len(buffer))
end = time.time()
image = imread(image_name)
for item in swt_result:
x, y, width, height = [item[key] for key in ("x", "y", "width", "height")]
print(x, y, width, height)
for i in range(0, 3): # just to make lines thicker
rr, cc = rectangle_perimeter(
y + i, x + i, height, width, shape=image.shape, clip=True
)
image[rr, cc] = (255, 0, 0)
imsave("result.jpg", image)
# from matplotlib import pyplot as plt
# imshow(image)
# plt.show()
print(f"SWT time: {end-start:0.4f}s")