Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpler solution for wellplate exercise #323

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Contributor Author

@JeremyPike JeremyPike Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the rest of the material

```

![](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
Loading