@@ -27,17 +27,16 @@ based on changes in colour or shape.
27
27
## First, import the packages needed for this episode
28
28
29
29
``` python
30
- import numpy as np
31
- import matplotlib.pyplot as plt
32
- import ipympl
33
30
import imageio.v3 as iio
34
- import skimage
35
- import skimage.draw
31
+ import ipympl
32
+ import matplotlib.pyplot as plt
33
+ import numpy as np
34
+ import skimage as ski
35
+
36
36
% matplotlib widget
37
37
```
38
38
39
- Here, we import the ` draw ` submodule of ` skimage ` as well as packages familiar
40
- from earlier in the lesson.
39
+ Here, we import the same packages as earlier in the lesson.
41
40
42
41
## Drawing on images
43
42
@@ -113,7 +112,7 @@ Next, we draw a filled, rectangle on the mask:
113
112
114
113
``` python
115
114
# Draw filled rectangle on the mask image
116
- rr, cc = skimage .draw.rectangle(start = (357 , 44 ), end = (740 , 720 ))
115
+ rr, cc = ski .draw.rectangle(start = (357 , 44 ), end = (740 , 720 ))
117
116
mask[rr, cc] = False
118
117
119
118
# Display mask image
@@ -139,7 +138,7 @@ it is wise to check how the function is used, via
139
138
or other usage examples on programming-related sites such as
140
139
[ Stack Overflow] ( https://stackoverflow.com/ ) .
141
140
Basic information about scikit-image functions can be found interactively in Python,
142
- via commands like ` help(skimage ) ` or ` help(skimage .draw.rectangle) ` .
141
+ via commands like ` help(ski ) ` or ` help(ski .draw.rectangle) ` .
143
142
Take notes in your lab notebook.
144
143
And, it is always wise to run some test code to verify
145
144
that the functions your program uses are behaving in the manner you intend.
@@ -170,21 +169,21 @@ such that it is easier for other people to understand your code.
170
169
## Other drawing operations (15 min)
171
170
172
171
There are other functions for drawing on images,
173
- in addition to the ` skimage .draw.rectangle()` function.
172
+ in addition to the ` ski .draw.rectangle()` function.
174
173
We can draw circles, lines, text, and other shapes as well.
175
174
These drawing functions may be useful later on, to help annotate images
176
175
that our programs produce.
177
176
Practice some of these functions here.
178
177
179
- Circles can be drawn with the ` skimage .draw.disk()` function,
178
+ Circles can be drawn with the ` ski .draw.disk()` function,
180
179
which takes two parameters:
181
180
the (ry, cx) point of the centre of the circle,
182
181
and the radius of the circle.
183
182
There is an optional ` shape ` parameter that can be supplied to this function.
184
183
It will limit the output coordinates for cases where the circle
185
184
dimensions exceed the ones of the image.
186
185
187
- Lines can be drawn with the ` skimage .draw.line()` function,
186
+ Lines can be drawn with the ` ski .draw.line()` function,
188
187
which takes four parameters:
189
188
the (ry, cx) coordinate of one end of the line,
190
189
and the (ry, cx) coordinate of the other end of the line.
@@ -215,15 +214,15 @@ Drawing a circle:
215
214
216
215
``` python
217
216
# Draw a blue circle with centre (200, 300) in (ry, cx) coordinates, and radius 100
218
- rr, cc = skimage .draw.disk(center = (200 , 300 ), radius = 100 , shape = canvas.shape[0 :2 ])
217
+ rr, cc = ski .draw.disk(center = (200 , 300 ), radius = 100 , shape = canvas.shape[0 :2 ])
219
218
canvas[rr, cc] = (0 , 0 , 255 )
220
219
```
221
220
222
221
Drawing a line:
223
222
224
223
``` python
225
224
# Draw a green line from (400, 200) to (500, 700) in (ry, cx) coordinates
226
- rr, cc = skimage .draw.line(r0 = 400 , c0 = 200 , r1 = 500 , c1 = 700 )
225
+ rr, cc = ski .draw.line(r0 = 400 , c0 = 200 , r1 = 500 , c1 = 700 )
227
226
canvas[rr, cc] = (0 , 255 , 0 )
228
227
```
229
228
@@ -249,7 +248,7 @@ canvas = np.zeros(shape=(600, 800, 3), dtype="uint8")
249
248
250
249
# draw a blue circle at a random location 15 times
251
250
for i in range (15 ):
252
- rr, cc = skimage .draw.disk(center = (
251
+ rr, cc = ski .draw.disk(center = (
253
252
random.randrange(600 ),
254
253
random.randrange(800 )),
255
254
radius = 50 ,
@@ -278,7 +277,7 @@ for i in range(15):
278
277
x = random.random()
279
278
if x < 0.33 :
280
279
# draw a blue circle at a random location
281
- rr, cc = skimage .draw.disk(center = (
280
+ rr, cc = ski .draw.disk(center = (
282
281
random.randrange(600 ),
283
282
random.randrange(800 )),
284
283
radius = 50 ,
@@ -287,7 +286,7 @@ for i in range(15):
287
286
color = (0 , 0 , 255 )
288
287
elif x < 0.66 :
289
288
# draw a green line at a random location
290
- rr, cc = skimage .draw.line(
289
+ rr, cc = ski .draw.line(
291
290
r0 = random.randrange(600 ),
292
291
c0 = random.randrange(800 ),
293
292
r1 = random.randrange(600 ),
@@ -296,7 +295,7 @@ for i in range(15):
296
295
color = (0 , 255 , 0 )
297
296
else :
298
297
# draw a red rectangle at a random location
299
- rr, cc = skimage .draw.rectangle(
298
+ rr, cc = ski .draw.rectangle(
300
299
start = (random.randrange(600 ), random.randrange(800 )),
301
300
extent = (50 , 50 ),
302
301
shape = canvas.shape[0 :2 ],
@@ -359,7 +358,7 @@ maize_seedlings = iio.imread(uri="data/maize-seedlings.tif")
359
358
mask = np.ones(shape = maize_seedlings.shape[0 :2 ], dtype = " bool" )
360
359
361
360
# Draw a filled rectangle on the mask image
362
- rr, cc = skimage .draw.rectangle(start = (357 , 44 ), end = (740 , 720 ))
361
+ rr, cc = ski .draw.rectangle(start = (357 , 44 ), end = (740 , 720 ))
363
362
mask[rr, cc] = False
364
363
```
365
364
@@ -416,7 +415,7 @@ remote = np.array(remote)
416
415
mask = np.ones(shape = remote.shape[0 :2 ], dtype = " bool" )
417
416
418
417
# Draw a filled rectangle on the mask image
419
- rr, cc = skimage .draw.rectangle(start = (93 , 1107 ), end = (1821 , 1668 ))
418
+ rr, cc = ski .draw.rectangle(start = (93 , 1107 ), end = (1821 , 1668 ))
420
419
mask[rr, cc] = False
421
420
422
421
# Apply the mask
@@ -484,7 +483,7 @@ with open("data/centers.txt", "r") as center_file:
484
483
ry = int (coordinates[1 ])
485
484
486
485
# ... and drawing a circle on the mask
487
- rr, cc = skimage .draw.disk(center = (ry, cx), radius = 16 , shape = wellplate.shape[0 :2 ])
486
+ rr, cc = ski .draw.disk(center = (ry, cx), radius = 16 , shape = wellplate.shape[0 :2 ])
488
487
mask[rr, cc] = False
489
488
490
489
# apply the mask
@@ -554,7 +553,7 @@ for row in range(12):
554
553
for col in range (8 ):
555
554
556
555
# ... and drawing a circle on the mask
557
- rr, cc = skimage .draw.disk(center = (ry, cx), radius = 16 , shape = wellplate.shape[0 :2 ])
556
+ rr, cc = ski .draw.disk(center = (ry, cx), radius = 16 , shape = wellplate.shape[0 :2 ])
558
557
mask[rr, cc] = False
559
558
cx += deltaCX
560
559
# after one complete row, move to next row
@@ -575,7 +574,7 @@ plt.imshow(wellplate)
575
574
:::::::::::::::::::::::::::::::::::::::: keypoints
576
575
577
576
- We can use the NumPy ` zeros() ` function to create a blank, black image.
578
- - We can draw on scikit-image images with functions such as ` skimage .draw.rectangle()` , ` skimage .draw.disk()` , ` skimage .draw.line()` , and more.
577
+ - We can draw on scikit-image images with functions such as ` ski .draw.rectangle()` , ` ski .draw.disk()` , ` ski .draw.line()` , and more.
579
578
- The drawing functions return indices to pixels that can be set directly.
580
579
581
580
::::::::::::::::::::::::::::::::::::::::::::::::::
0 commit comments