~gcg/+junk/trunk

« back to all changes in this revision

Viewing changes to DVC/overlay/roipoly.py-master/example.py

  • Committer: gcg
  • Date: 2020-07-15 07:46:15 UTC
  • Revision ID: gcg-20200715074615-tr80szbt9xq5m2ae
Major Cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import logging
 
2
 
 
3
import numpy as np
 
4
from matplotlib import pyplot as plt
 
5
 
 
6
from roipoly import RoiPoly
 
7
 
 
8
logger = logging.getLogger(__name__)
 
9
 
 
10
logging.basicConfig(format='%(levelname)s ''%(processName)-10s : %(asctime)s '
 
11
                           '%(module)s.%(funcName)s:%(lineno)s %(message)s',
 
12
                    level=logging.INFO)
 
13
 
 
14
# Create image
 
15
img = np.ones((100, 100)) * range(0, 100)
 
16
 
 
17
# Show the image
 
18
fig = plt.figure()
 
19
plt.imshow(img, interpolation='nearest', cmap="Greys")
 
20
plt.colorbar()
 
21
plt.title("left click: line segment         right click: close region")
 
22
plt.show(block=False)
 
23
 
 
24
# Let user draw first ROI
 
25
roi1 = RoiPoly(color='r', fig=fig)
 
26
 
 
27
# Show the image with the first ROI
 
28
fig = plt.figure()
 
29
plt.imshow(img, interpolation='nearest', cmap="Greys")
 
30
plt.colorbar()
 
31
roi1.display_roi()
 
32
plt.title('draw second ROI')
 
33
plt.show(block=False)
 
34
 
 
35
# Let user draw second ROI
 
36
roi2 = RoiPoly(color='b', fig=fig)
 
37
 
 
38
# Show the image with both ROIs and their mean values
 
39
plt.imshow(img, interpolation='nearest', cmap="Greys")
 
40
plt.colorbar()
 
41
[x.display_roi() for x in [roi1, roi2]]
 
42
[x.display_mean(img) for x in [roi1, roi2]]
 
43
plt.title('The two ROIs')
 
44
plt.show()
 
45
 
 
46
# Show ROI masks
 
47
plt.imshow(roi1.get_mask(img) + roi2.get_mask(img),
 
48
           interpolation='nearest', cmap="Greys")
 
49
plt.title('ROI masks of the two ROIs')
 
50
plt.show()