@@ -160,56 +160,11 @@ from one of the dataset files. They are numbered from `...000.png` to
160160``` {code-cell} ipython3
161161import numpy as np
162162
163- file1 = imageio.imread(os.path.join(DIR, '00000011_000.png'))
164- file2 = imageio.imread(os.path.join(DIR, '00000011_001.png'))
165- file3 = imageio.imread(os.path.join(DIR, '00000011_003.png'))
166- file4 = imageio.imread(os.path.join(DIR, '00000011_004.png'))
167- file5 = imageio.imread(os.path.join(DIR, '00000011_005.png'))
168- file6 = imageio.imread(os.path.join(DIR, '00000011_006.png'))
169- file7 = imageio.imread(os.path.join(DIR, '00000011_007.png'))
170- file8 = imageio.imread(os.path.join(DIR, '00000011_008.png'))
171-
172- combined_xray_images_1 = np.stack([file1, file2, file3, file4, file5, file6, file7, file8])
163+ combined_xray_images_1 = np.array(
164+ [imageio.imread(os.path.join(DIR, f"00000011_00{i}.png")) for i in range(9)]
165+ )
173166```
174167
175- Alternatively, you can ` append ` the image arrays as follows:
176-
177- ``` {code-cell} ipython3
178- combined_xray_images_2 = []
179-
180- for i in range(8):
181- single_xray_image = imageio.imread(os.path.join(DIR, '00000011_00'+str(i)+'.png'))
182- combined_xray_images_2.append(single_xray_image)
183- ```
184-
185- _ Note on performance:_
186-
187- - ` append ` ing the images may no be faster. If you care about performance, you
188- should probably use ` np.stack() ` , as evidenced when you try to time the code
189- with Python's ` timeit ` :
190-
191- ``` python
192- % timeit combined_xray_images_1 = np.stack([file1, file2, file3, file4, file5, file6, file7, file8])
193- ```
194-
195- Example output:
196-
197- ```
198- 1.52 ms ± 49.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
199- ```
200-
201- ```python
202- % timeit C = [combined_xray_images_2.append(imageio.imread(os.path.join(DIR , ' 00000011_00' + str (i)+ ' .png' ))) for i in range (8 )]
203- ```
204-
205- Example output:
206-
207- ```
208- 159 ms ± 2.69 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
209- ```
210-
211- ++ +
212-
213168** 2.** Check the shape of the new X-ray image array containing 8 stacked images:
214169
215170``` {code-cell} ipython3
0 commit comments