-
-
Notifications
You must be signed in to change notification settings - Fork 125
changing away from image as variable name #259
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||||||
| ~~~ | ||||||||||
| {: .language-python} | ||||||||||
|
|
||||||||||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| ~~~ | ||||||||||
| {: .language-python} | ||||||||||
|
|
||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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} | ||
|
|
||
|
|
@@ -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} | ||
|
|
||
|
|
@@ -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. | ||
|
|
@@ -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 | ||
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest to use |
||
| > > fig, ax = plt.subplots() | ||
| > > plt.imshow(small) | ||
| > > ~~~ | ||
|
|
@@ -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`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest |
||
| Every pixel colour value in the whole 3-dimensional array with a value less | ||
| that 128 is set to zero. | ||
| In this case, | ||
|
|
@@ -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") | ||
| ~~~ | ||
|
|
@@ -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} | ||
|
|
||
|
|
@@ -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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| > > ~~~ | ||
| > > {: .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} | ||
|
|
@@ -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} | ||
|
|
||
|
|
@@ -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) | ||
|
|
@@ -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} | ||
|
|
||
|
|
@@ -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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
| > > 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) | ||
| > > | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.