Skip to content

Commit 921f797

Browse files
committed
markdown source builds
Auto-generated via {sandpaper} Source : 877baa5 Branch : main Author : Toby Hodges <tobyhodges@carpentries.org> Time : 2024-06-07 06:30:08 +0000 Message : Merge pull request #323 from bear-rsg/second-workshork-changes Simpler solution for wellplate exercise
1 parent f9e226e commit 921f797

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

02-image-basics.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Using array slicing, we can then address and assign a new value to that position
287287

288288
```python
289289
zero = iio.imread(uri="data/eight.tif")
290-
zero[2,1]= 1.0
290+
zero[2, 1]= 1.0
291291

292292
# The following line of code creates a new figure for imshow to use in displaying our output.
293293
fig, ax = plt.subplots()
@@ -362,8 +362,8 @@ There are many possible solutions, but one method would be . . .
362362

363363
```python
364364
five = iio.imread(uri="data/eight.tif")
365-
five[1,2]= 1.0
366-
five[3,0]= 1.0
365+
five[1, 2] = 1.0
366+
five[3, 0] = 1.0
367367
fig, ax = plt.subplots()
368368
ax.imshow(five)
369369
print(five)
@@ -400,7 +400,7 @@ three_colours = three_colours * 128
400400

401401
# set the middle row (index 2) to the value of 255.,
402402
# so you end up with the values 0., 128., and 255.
403-
three_colours[2,:] = 255.
403+
three_colours[2, :] = 255.
404404
fig, ax = plt.subplots()
405405
ax.imshow(three_colours)
406406
print(three_colours)
@@ -436,7 +436,7 @@ a mapped continuum of intensities: greyscale.
436436

437437
```python
438438
fig, ax = plt.subplots()
439-
ax.imshow(three_colours,cmap=plt.cm.gray)
439+
ax.imshow(three_colours, cmap="gray")
440440
```
441441

442442
![](fig/grayscale.png){alt='Image in greyscale'}

03-skimage-images.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import ipympl
3131
import matplotlib.pyplot as plt
3232
import numpy as np
3333
import skimage as ski
34+
35+
%matplotlib widget
3436
```
3537

3638
## Reading, displaying, and saving images

04-drawing.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -462,29 +462,33 @@ Your program should produce output that looks like this:
462462

463463
![](fig/wellplate-01-masked.jpg){alt='Masked 96-well plate'}
464464

465+
*Hint: You can load `data/centers.txt` using*:
466+
467+
```Python
468+
# load the well coordinates as a NumPy array
469+
centers = np.loadtxt("data/centers.txt", delimiter=" ")
470+
```
471+
465472
::::::::::::::: solution
466473

467474
## Solution
468475

469476
```python
477+
# load the well coordinates as a NumPy array
478+
centers = np.loadtxt("data/centers.txt", delimiter=" ")
479+
470480
# read in original image
471481
wellplate = iio.imread(uri="data/wellplate-01.jpg")
472482
wellplate = np.array(wellplate)
473483

474484
# create the mask image
475485
mask = np.ones(shape=wellplate.shape[0:2], dtype="bool")
476486

477-
# open and iterate through the centers file...
478-
with open("data/centers.txt", "r") as center_file:
479-
for line in center_file:
480-
# ... getting the coordinates of each well...
481-
coordinates = line.split()
482-
cx = int(coordinates[0])
483-
ry = int(coordinates[1])
484-
485-
# ... and drawing a circle on the mask
486-
rr, cc = ski.draw.disk(center=(ry, cx), radius=16, shape=wellplate.shape[0:2])
487-
mask[rr, cc] = False
487+
# iterate through the well coordinates
488+
for cx, ry in centers:
489+
# draw a circle on the mask at the well center
490+
rr, cc = ski.draw.disk(center=(ry, cx), radius=16, shape=wellplate.shape[:2])
491+
mask[rr, cc] = False
488492

489493
# apply the mask
490494
wellplate[mask] = 0

md5sum.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"config.yaml" "101b3ac4b679126bb1f437306eb1b836" "site/built/config.yaml" "2023-04-25"
55
"index.md" "6e80c662708984307918adfad711e15f" "site/built/index.md" "2023-07-26"
66
"episodes/01-introduction.md" "9755639c515fdbf752422e2e59128f63" "site/built/01-introduction.md" "2023-07-26"
7-
"episodes/02-image-basics.md" "7a99d30d6ef4a11b8766fef3096fd1ab" "site/built/02-image-basics.md" "2024-03-12"
8-
"episodes/03-skimage-images.md" "9ab46078d049def7053e98f793fe426a" "site/built/03-skimage-images.md" "2024-03-12"
9-
"episodes/04-drawing.md" "d52b45e266997d93e359c63d53822e9b" "site/built/04-drawing.md" "2024-03-12"
7+
"episodes/02-image-basics.md" "d7e49ef016b308d80ae19d6a461855a8" "site/built/02-image-basics.md" "2024-06-07"
8+
"episodes/03-skimage-images.md" "d7890de460222e8cdf461c76cba37692" "site/built/03-skimage-images.md" "2024-06-07"
9+
"episodes/04-drawing.md" "48b42ee384b5b907d9f9b93ad0e98ce8" "site/built/04-drawing.md" "2024-06-07"
1010
"episodes/05-creating-histograms.md" "4abbd123ba97d63c795398be6f6b7621" "site/built/05-creating-histograms.md" "2024-03-14"
1111
"episodes/06-blurring.md" "131274433675bee650e218bd28830435" "site/built/06-blurring.md" "2024-03-12"
1212
"episodes/07-thresholding.md" "4d34b89c8cd33cb6bb54103f805a39b9" "site/built/07-thresholding.md" "2024-03-12"

0 commit comments

Comments
 (0)