Skip to content

Commit

Permalink
Merge pull request #323 from bear-rsg/second-workshork-changes
Browse files Browse the repository at this point in the history
Simpler solution for wellplate exercise
  • Loading branch information
tobyhodges committed Jun 7, 2024
2 parents f78936e + 2642940 commit 877baa5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
10 changes: 5 additions & 5 deletions episodes/02-image-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Using array slicing, we can then address and assign a new value to that position

```python
zero = iio.imread(uri="data/eight.tif")
zero[2,1]= 1.0
zero[2, 1]= 1.0

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

```python
five = iio.imread(uri="data/eight.tif")
five[1,2]= 1.0
five[3,0]= 1.0
five[1, 2] = 1.0
five[3, 0] = 1.0
fig, ax = plt.subplots()
ax.imshow(five)
print(five)
Expand Down Expand Up @@ -400,7 +400,7 @@ three_colours = three_colours * 128

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

```python
fig, ax = plt.subplots()
ax.imshow(three_colours,cmap=plt.cm.gray)
ax.imshow(three_colours, cmap="gray")
```

![](fig/grayscale.png){alt='Image in greyscale'}
Expand Down
2 changes: 2 additions & 0 deletions episodes/03-skimage-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import ipympl
import matplotlib.pyplot as plt
import numpy as np
import skimage as ski

%matplotlib widget
```

## Reading, displaying, and saving images
Expand Down
26 changes: 15 additions & 11 deletions episodes/04-drawing.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,29 +462,33 @@ Your program should produce output that looks like this:

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

*Hint: You can load `data/centers.txt` using*:

```Python
# load the well coordinates as a NumPy array
centers = np.loadtxt("data/centers.txt", delimiter=" ")
```

::::::::::::::: solution

## Solution

```python
# load the well coordinates as a NumPy array
centers = np.loadtxt("data/centers.txt", delimiter=" ")

# read in original image
wellplate = iio.imread(uri="data/wellplate-01.jpg")
wellplate = np.array(wellplate)

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

# open and iterate through the centers file...
with open("data/centers.txt", "r") as center_file:
for line in center_file:
# ... getting the coordinates of each well...
coordinates = line.split()
cx = int(coordinates[0])
ry = int(coordinates[1])

# ... and drawing a circle on the mask
rr, cc = ski.draw.disk(center=(ry, cx), radius=16, shape=wellplate.shape[0:2])
mask[rr, cc] = False
# iterate through the well coordinates
for cx, ry in centers:
# draw a circle on the mask at the well center
rr, cc = ski.draw.disk(center=(ry, cx), radius=16, shape=wellplate.shape[:2])
mask[rr, cc] = False

# apply the mask
wellplate[mask] = 0
Expand Down

0 comments on commit 877baa5

Please sign in to comment.