Skip to content
Closed
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
8 changes: 4 additions & 4 deletions _episodes/02-image-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ natively (think of volumes, movies).
{: .callout}

~~~
image = iio.imread(uri="data/eight.tif")
plt.imshow(image)
eight_tiff = iio.imread(uri="data/eight.tif")
plt.imshow(eight_tiff)
Comment on lines +199 to +200
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
eight_tiff = iio.imread(uri="data/eight.tif")
plt.imshow(eight_tiff)
eight = iio.imread(uri="data/eight.tif")
plt.imshow(eight)

~~~
{: .language-python}

Expand Down Expand Up @@ -226,8 +226,8 @@ and see the matrix by printing our image variable to the screen.


~~~
print(image.shape)
print(image)
print(eight_tiff.shape)
print(eight_tiff)
Comment on lines +229 to +230
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
print(eight_tiff.shape)
print(eight_tiff)
print(eight.shape)
print(eight)

~~~
{: .language-python}

Expand Down
72 changes: 38 additions & 34 deletions _episodes/03-skimage-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Here are the first few lines:
import imageio.v3 as iio

# read image
image = iio.imread(uri="data/chair.jpg")
chair_jpg = iio.imread(uri="data/chair.jpg")
~~~
{: .language-python}

Expand All @@ -65,7 +65,7 @@ Next, we will do something with the image:
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
plt.imshow(image)
plt.imshow(chair_jpg)
~~~
{: .language-python}

Expand All @@ -78,11 +78,11 @@ Now, we will save the image in another format:

~~~
# save a new version in .tif format
iio.imwrite(uri="data/chair.tif", image=image)
iio.imwrite(uri="data/chair.tif", image=chair_jpg)
~~~
{: .language-python}

The final statement in the program, `iio.imwrite(uri="data/chair.tif", image=image)`,
The final statement in the program, `iio.imwrite(uri="data/chair.tif", image=chair_jpg)`,
writes the image to a file named `chair.tif` in the `data/` directory.
The `imwrite()` function automatically determines the type of the file,
based on the file extension we provide.
Expand Down Expand Up @@ -142,19 +142,19 @@ In this case, the `.tif` extension causes the image to be saved as a TIFF.
>
> Add `import skimage.transform` and `import skimage.util` to your list of imports.
> Using the `chair.jpg` image located in the data folder,
> write a Python script to read your image into a variable named `image`.
> write a Python script to read your image into a variable named `chair_jpg`.
> Then, resize the image to 10 percent of its current size using these lines of code:
>
> ~~~
> new_shape = (image.shape[0] // 10, image.shape[1] // 10, image.shape[2])
> small = skimage.transform.resize(image=image, output_shape=new_shape)
> new_shape = (chair_jpg.shape[0] // 10, chair_jpg.shape[1] // 10, chair_jpg.shape[2])
> small = skimage.transform.resize(image=chair_jpg, output_shape=new_shape)
> small = skimage.util.img_as_ubyte(small)
> ~~~
> {: .language-python}
>
> As it is used here,
> the parameters to the `skimage.transform.resize()` function are
> the image to transform, `image`,
> the image to transform, `chair_jpg`,
> the dimensions we want the new image to have, `new_shape`.
>
> > Note that the pixel values in the new image are an approximation of
Expand Down Expand Up @@ -203,19 +203,19 @@ In this case, the `.tif` extension causes the image to be saved as a TIFF.
> > import skimage.util
> >
> > # read in image
> > image = iio.imread(uri="data/chair.jpg")
> > chair_jpg = iio.imread(uri="data/chair.jpg")
> >
> > # resize the image
> > new_shape = (image.shape[0] // 10, image.shape[1] // 10, image.shape[2])
> > small = skimage.transform.resize(image=image, output_shape=new_shape)
> > new_shape = (chair_jpg.shape[0] // 10, chair_jpg.shape[1] // 10, chair_jpg.shape[2])
> > small = skimage.transform.resize(image=chair_jpg, output_shape=new_shape)
> > small = skimage.util.img_as_ubyte(small)
> >
> > # write out image
> > iio.imwrite(uri="data/resized.jpg", image=small)
> >
> > # display images
> > fig, ax = plt.subplots()
> > plt.imshow(image)
> > plt.imshow(chair_jpg)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to use chair instead of chair_jpg.

> > fig, ax = plt.subplots()
> > plt.imshow(small)
> > ~~~
Expand Down Expand Up @@ -261,28 +261,30 @@ We will start by reading the image and displaying it.
import imageio.v3 as iio

# read input image
image = iio.imread(uri="data/maize-root-cluster.jpg")
roots = iio.imread(uri="data/maize-root-cluster.jpg")

# display original image
fig, ax = plt.subplots()
plt.imshow(image)
plt.imshow(roots)
~~~
{: .language-python}


Now we can threshold the image and display the result.

~~~
# copy the image so it can be manipulated
roots = roots.copy()
# keep only high-intensity pixels
image[image < 128] = 0
roots[roots < 128] = 0

# display modified image
fig, ax = plt.subplots()
plt.imshow(image)
plt.imshow(roots)
~~~
{: .language-python}

The NumPy command to ignore all low-intensity pixels is `image[image < 128] = 0`.
The NumPy command to ignore all low-intensity pixels is `roots[roots < 128] = 0`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest maize_roots instead of roots (roots could be confused with the mathematical sense, e.g., roots of an equation).

Every pixel colour value in the whole 3-dimensional array with a value less
that 128 is set to zero.
In this case,
Expand Down Expand Up @@ -327,14 +329,14 @@ import imageio.v3 as iio
import skimage.color

# read input image
image = iio.imread(uri="data/chair.jpg")
chair_jpg = iio.imread(uri="data/chair.jpg")

# display original image
fig, ax = plt.subplots()
plt.imshow(image)
plt.imshow(chair_jpg)

# convert to grayscale and display
gray_image = skimage.color.rgb2gray(image)
gray_image = skimage.color.rgb2gray(chair_jpg)
fig, ax = plt.subplots()
plt.imshow(gray_image, cmap="gray")
~~~
Expand All @@ -352,11 +354,11 @@ import imageio.v3 as iio
import skimage.color

# read input image, based on filename parameter
image = iio.imread(uri="data/chair.jpg", mode="L")
chair_jpg_l = iio.imread(uri="data/chair.jpg", mode="L")

# display grayscale image
fig, ax = plt.subplots()
plt.imshow(image, cmap="gray")
plt.imshow(chair_jpg_l, cmap="gray")
~~~
{: .language-python}

Expand Down Expand Up @@ -396,22 +398,23 @@ determines the backend to use based on the image type.
> > ~~~
> > import imageio.v3
> >
> > image = iio.imread(uri="data/sudoku.jpg", mode="L")
> > sodoku = iio.imread(uri="data/sudoku.png")
Copy link
Contributor

Choose a reason for hiding this comment

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

This was updated in PR #253 (hence the conflict). Would you mind merging gh-pages to sync up your branch? Thanks!

> > ~~~
> > {: .language-python }
> >
> > Then, change all high intensity pixel values (> 0.75) to 0.75:
> >
> > ~~~
> > image[image > 0.75] = 0.75
> > sodoku = sodoku.copy()
> > sodoku[sodoku > 125] = 125
> > ~~~
> > {: .language-python }
> >
> > Finally, display modified image:
> >
> > ~~~
> > fig, ax = plt.subplots()
> > plt.imshow(image, cmap="gray", vmin=0, vmax=1)
> > plt.imshow(sodoku, cmap="gray", vmin=0, vmax=1)
> > ~~~
> > {: .language-python}
> {: .solution}
Expand Down Expand Up @@ -489,9 +492,9 @@ A script to create the subimage would start by loading the image:
import imageio.v3 as iio

# load and display original image
image = iio.imread(uri="data/board.jpg")
board = iio.imread(uri="data/board.jpg")
fig, ax = plt.subplots()
plt.imshow(image)
plt.imshow(board)
~~~
{: .language-python}

Expand All @@ -500,7 +503,7 @@ create a new image with our selected area and then display the new image.

~~~
# extract, display, and save sub-image
clip = image[60:151, 135:481, :]
clip = board[60:151, 135:481, :]
fig, ax = plt.subplots()
plt.imshow(clip)
iio.imwrite(uri="data/clip.tif", image=clip)
Expand All @@ -511,10 +514,11 @@ We can also change the values in an image, as shown next.

~~~
# replace clipped area with sampled color
color = image[330, 90]
image[60:151, 135:481] = color
board = board.copy()
color = board[330, 90]
board[60:151, 135:481] = color
fig, ax = plt.subplots()
plt.imshow(image)
plt.imshow(board)
~~~
{: .language-python}

Expand Down Expand Up @@ -552,13 +556,13 @@ as shown in the final image produced by the program:
> > import imageio.v3 as iio
> >
> > # load and display original image
> > image = iio.imread(uri="data/maize-root-cluster.jpg")
> > root = iio.imread(uri="data/maize-root-cluster.jpg")
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe maize_root?

> > fig, ax = plt.subplots()
> > plt.imshow(image)
> > plt.imshow(root)
> >
> > # extract, display, and save sub-image
> > # WRITE YOUR CODE TO SELECT THE SUBIMAGE NAME clip HERE:
> > clip = image[0:400, 275:550, :]
> > clip = root[0:400, 275:550, :]
> > fig, ax = plt.subplots()
> > plt.imshow(clip)
> >
Expand Down