@@ -135,9 +135,9 @@ print(xray_image.dtype)
135135``` {code-cell}
136136import matplotlib.pyplot as plt
137137
138- plt.imshow(xray_image, cmap="gray" )
139- plt.axis("off ")
140- plt.show ()
138+ fig, ax = plt.subplots( )
139+ ax.imshow(xray_image, cmap="gray ")
140+ ax.set_axis_off ()
141141```
142142
143143## Combine images into a multidimensional array to demonstrate progression
@@ -240,7 +240,6 @@ axes[1].set_title("Laplacian-Gaussian (edges)")
240240axes[1].imshow(xray_image_laplace_gaussian, cmap="gray")
241241for i in axes:
242242 i.axis("off")
243- plt.show()
244243```
245244
246245### The Gaussian gradient magnitude method
@@ -273,7 +272,6 @@ axes[1].set_title("Gaussian gradient (edges)")
273272axes[1].imshow(x_ray_image_gaussian_gradient, cmap="gray")
274273for i in axes:
275274 i.axis("off")
276- plt.show()
277275```
278276
279277### The Sobel-Feldman operator (the Sobel filter)
@@ -338,7 +336,6 @@ axes[2].set_title("Sobel (edges) - CMRmap")
338336axes[2].imshow(xray_image_sobel, cmap="CMRmap")
339337for i in axes:
340338 i.axis("off")
341- plt.show()
342339```
343340
344341### The Canny filter
@@ -399,7 +396,6 @@ axes[3].set_title("Canny (edges) - terrain")
399396axes[3].imshow(xray_image_canny, cmap="terrain")
400397for i in axes:
401398 i.axis("off")
402- plt.show()
403399```
404400
405401## Apply masks to X-rays with ` np.where() `
@@ -438,9 +434,9 @@ pixel_intensity_distribution = ndimage.histogram(
438434 xray_image, min=np.min(xray_image), max=np.max(xray_image), bins=256
439435)
440436
441- plt.plot(pixel_intensity_distribution )
442- plt.title("Pixel intensity distribution" )
443- plt.show( )
437+ fig, ax = plt.subplots( )
438+ ax.plot(pixel_intensity_distribution )
439+ ax.set_title("Pixel intensity distribution" )
444440```
445441
446442As the pixel intensity distribution suggests, there are many low (between around
@@ -455,19 +451,19 @@ a certain threshold:
455451# Return the original image if true, `0` otherwise
456452xray_image_mask_noisy = np.where(xray_image > 150, xray_image, 0)
457453
458- plt.imshow(xray_image_mask_noisy, cmap="gray" )
459- plt.axis("off ")
460- plt.show ()
454+ fig, ax = plt.subplots( )
455+ ax.imshow(xray_image_mask_noisy, cmap="gray ")
456+ ax.set_axis_off ()
461457```
462458
463459``` {code-cell}
464460# The threshold is "greater than 150"
465461# Return `1` if true, `0` otherwise
466462xray_image_mask_less_noisy = np.where(xray_image > 150, 1, 0)
467463
468- plt.imshow(xray_image_mask_less_noisy, cmap="gray" )
469- plt.axis("off ")
470- plt.show ()
464+ fig, ax = plt.subplots( )
465+ ax.imshow(xray_image_mask_less_noisy, cmap="gray ")
466+ ax.set_axis_off ()
471467```
472468
473469## Compare the results
@@ -500,7 +496,6 @@ axes[8].set_title("Mask (> 150, less noisy)")
500496axes[8].imshow(xray_image_mask_less_noisy, cmap="gray")
501497for i in axes:
502498 i.axis("off")
503- plt.show()
504499```
505500
506501## Next steps
0 commit comments