@@ -89,7 +89,7 @@ each notebook cell.
8989+++
9090
91911 . Examine an X-ray with ` imageio `
92- 2 . Combine images with ` np.stack() ` to demonstrate progression
92+ 2 . Combine images into a multi-dimensional array to demonstrate progression
93933 . Edge detection using the Laplacian-Gaussian, Gaussian gradient, Sobel, and
9494 Canny filters
95954 . Apply masks to X-rays with ` np.where() `
@@ -140,47 +140,45 @@ plt.axis('off')
140140plt.show()
141141```
142142
143- ## Combine images with ` np.stack() ` to demonstrate progression
143+ ## Combine images into a multidimensional array to demonstrate progression
144144
145145+++
146146
147- With NumPy's ` np.stack() ` you can combine multiple X-rays to make an
148- n-dimensional array and then show the "health progress" in a sequential manner.
149-
150- In the next example, instead of 1 image you'll use 8 X-ray 1024x1024-pixel
147+ In the next example, instead of 1 image you'll use 9 X-ray 1024x1024-pixel
151148images from the ChestX-ray8 dataset that have been downloaded and extracted
152149from one of the dataset files. They are numbered from ` ...000.png ` to
153150` ...008.png ` and let's assume they belong to the same patient.
154151
155- +++
156-
157- ** 1.** Import NumPy, read in each of the X-rays, and stack them together with
158- ` np.stack() ` :
152+ ** 1.** Import NumPy, read in each of the X-rays, and create a three-dimensional
153+ array where the first dimension corresponds to image number:
159154
160155``` {code-cell} ipython3
161156import numpy as np
157+ num_imgs = 9
162158
163159combined_xray_images_1 = np.array(
164- [imageio.imread(os.path.join(DIR, f"00000011_00{i}.png")) for i in range(9 )]
160+ [imageio.imread(os.path.join(DIR, f"00000011_00{i}.png")) for i in range(num_imgs )]
165161)
166162```
167163
168- ** 2.** Check the shape of the new X-ray image array containing 8 stacked images:
164+ ** 2.** Check the shape of the new X-ray image array containing 9 stacked images:
169165
170166``` {code-cell} ipython3
171167combined_xray_images_1.shape
172168```
173169
170+ Note that the shape in the first dimension matches ` num_imgs ` , so the
171+ ` combined_xray_images_1 ` array can be interpreted as a stack of 2D images.
172+
174173** 3.** You can now display the "health progress" by plotting each of frames next
175174to each other using Matplotlib:
176175
177176``` {code-cell} ipython3
178- fig, axes = plt.subplots(nrows=1, ncols=8 , figsize=(30, 30))
177+ fig, axes = plt.subplots(nrows=1, ncols=num_imgs , figsize=(30, 30))
179178
180- for i in range(8):
181- x = combined_xray_images_1[i]
182- axes[i].imshow(x, cmap='gray')
183- axes[i].axis('off')
179+ for img, ax in zip(combined_xray_images_1, axes):
180+ ax.imshow(img, cmap='gray')
181+ ax.axis('off')
184182```
185183
186184** 4.** In addition, it can be helpful to show the progress as an animation.
0 commit comments