-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_roi.py
More file actions
68 lines (51 loc) · 1.92 KB
/
Copy pathexample_roi.py
File metadata and controls
68 lines (51 loc) · 1.92 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
"""
Examples showing how to use the ucvtk.draw module
@author: Boris Bocquet <borisboc@free.fr>
@license: LGPL V3.0
"""
# %%
import cv2
import matplotlib.pyplot as plt
from ucvtk.roi.draw_roi_napari import draw_point, draw_rectangle
# %%
# Load an color image in grayscale using opencv
imgPath = 'sand.jpg'
img = cv2.imread(imgPath, cv2.IMREAD_COLOR)
imgHeigh, imgWidth, imgNbChannels = img.shape[:3]
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Load using matplotlib
imgMatplotlib = plt.imread(imgPath)
# %%
# Basic usage to draw a point.
point = draw_point(img)
# Returns numpy.ndarray, that are the coordinates of the point.
# The shape is (1,2)
# point[0,0] is row coordinate
# point[0,1] is column coordinate
# See documentation of draw_point
# %%
# Basic usage to draw a rectangle.
rect = draw_rectangle(img)
# Returns numpy.ndarray, that are the coordinates of the corners.
# See documentation of draw_rectangle (the ordering of the corners depends
# on the angle of the rectangle).
# %%
# Concerning the color convertion, and grayscale, the functions
# of uctk.roi are similare to uctk.print
# Indeed, by default, we expect you to work with opencv color image,
# .i.e BGR images.
# But if you load from matplotlib (or other) you can convert before printing.
# If you don't, the channels will be wrongly displayed
# So here is how to convert.
rect_again = draw_rectangle(imgMatplotlib, convert_3ch_image=False)
# %%
# Of course, grayscale / single channel is handled
rect_grayscale = draw_rectangle(imgGray)
# %%
# If you have noted in the napari, we split the channels of the color image.
# So that you can they display/hide each channel separatly.
# The drawback is that the viewer takes more time to appear,
# and it flickers a bit.
# But you can disable this splitting. See below.
rect_no_split = draw_rectangle(img, split_channels=False)