@@ -60,13 +60,13 @@ Next, we will do something with the image:
6060
6161``` python
6262fig, ax = plt.subplots()
63- plt .imshow(chair)
63+ ax .imshow(chair)
6464```
6565
6666Once we have the image in the program,
67- we first call ` plt.subplots() ` so that we will have
68- a fresh figure with a set of axis independent from our previous calls.
69- Next we call ` plt .imshow()` in order to display the image.
67+ we first call ` fig, ax = plt.subplots()` so that we will have
68+ a fresh figure with a set of axes independent from our previous calls.
69+ Next we call ` ax .imshow()` in order to display the image.
7070
7171Now, we will save the image in another format:
7272
@@ -181,7 +181,7 @@ If we don't convert it before saving,
181181
182182Next, write the resized image out to a new file named ` resized.jpg `
183183in your data directory.
184- Finally, use ` plt .imshow()` with each of your image variables to display
184+ Finally, use ` ax .imshow()` with each of your image variables to display
185185both images in your notebook.
186186Don't forget to use ` fig, ax = plt.subplots() ` so you don't overwrite
187187the first image with the second.
@@ -214,9 +214,9 @@ iio.imwrite(uri="data/resized_chair.jpg", image=resized_chair)
214214
215215# display images
216216fig, ax = plt.subplots()
217- plt .imshow(chair)
217+ ax .imshow(chair)
218218fig, ax = plt.subplots()
219- plt .imshow(resized_chair)
219+ ax .imshow(resized_chair)
220220```
221221
222222The script resizes the ` data/chair.jpg ` image by a factor of 10 in both dimensions,
@@ -271,7 +271,7 @@ maize_roots = np.array(maize_roots)
271271
272272# display original image
273273fig, ax = plt.subplots()
274- plt .imshow(maize_roots)
274+ ax .imshow(maize_roots)
275275```
276276
277277Now we can threshold the image and display the result.
@@ -282,7 +282,7 @@ maize_roots[maize_roots < 128] = 0
282282
283283# display modified image
284284fig, ax = plt.subplots()
285- plt .imshow(maize_roots)
285+ ax .imshow(maize_roots)
286286```
287287
288288The NumPy command to ignore all low-intensity pixels is ` roots[roots < 128] = 0 ` .
@@ -331,12 +331,12 @@ chair = iio.imread(uri="data/chair.jpg")
331331
332332# display original image
333333fig, ax = plt.subplots()
334- plt .imshow(chair)
334+ ax .imshow(chair)
335335
336336# convert to grayscale and display
337337gray_chair = ski.color.rgb2gray(chair)
338338fig, ax = plt.subplots()
339- plt .imshow(gray_chair, cmap = " gray" )
339+ ax .imshow(gray_chair, cmap = " gray" )
340340```
341341
342342We can also load colour images as grayscale directly by
@@ -350,7 +350,7 @@ gray_chair = iio.imread(uri="data/chair.jpg", mode="L")
350350
351351# display grayscale image
352352fig, ax = plt.subplots()
353- plt .imshow(gray_chair, cmap = " gray" )
353+ ax .imshow(gray_chair, cmap = " gray" )
354354```
355355
356356The first argument to ` iio.imread() ` is the filename of the image.
@@ -415,7 +415,6 @@ sudoku_gray_background[sudoku_gray_background > 192] = 192
415415Finally, display the original and modified images side by side. Note that we have to specify ` vmin=0 ` and ` vmax=255 ` as the range of the colorscale because it would otherwise automatically adjust to the new range 0-192.
416416
417417``` python
418- fig, ax = plt.subplots()
419418fig, ax = plt.subplots(ncols = 2 )
420419ax[0 ].imshow(sudoku, cmap = " gray" , vmin = 0 , vmax = 255 )
421420ax[1 ].imshow(sudoku_gray_background, cmap = " gray" , vmin = 0 , vmax = 255 )
@@ -430,11 +429,11 @@ ax[1].imshow(sudoku_gray_background, cmap="gray", vmin=0, vmax=255)
430429## Plotting single channel images (cmap, vmin, vmax)
431430
432431Compared to a colour image, a grayscale image contains only a single
433- intensity value per pixel. When we plot such an image with ` plt .imshow` ,
432+ intensity value per pixel. When we plot such an image with ` ax .imshow` ,
434433Matplotlib uses a colour map, to assign each intensity value a colour.
435434The default colour map is called "viridis" and maps low values to purple
436435and high values to yellow. We can instruct Matplotlib to map low values
437- to black and high values to white instead, by calling ` plt .imshow` with
436+ to black and high values to white instead, by calling ` ax .imshow` with
438437` cmap="gray" ` .
439438[ The documentation contains an overview of pre-defined colour maps] ( https://matplotlib.org/stable/gallery/color/colormap_reference.html ) .
440439
@@ -499,7 +498,7 @@ A script to create the subimage would start by loading the image:
499498board = iio.imread(uri = " data/board.jpg" )
500499board = np.array(board)
501500fig, ax = plt.subplots()
502- plt .imshow(board)
501+ ax .imshow(board)
503502```
504503
505504Then we use array slicing to
@@ -509,7 +508,7 @@ create a new image with our selected area and then display the new image.
509508# extract, display, and save sub-image
510509clipped_board = board[60 :151 , 135 :481 , :]
511510fig, ax = plt.subplots()
512- plt .imshow(clipped_board)
511+ ax .imshow(clipped_board)
513512iio.imwrite(uri = " data/clipped_board.tif" , image = clipped_board)
514513```
515514
@@ -520,7 +519,7 @@ We can also change the values in an image, as shown next.
520519color = board[330 , 90 ]
521520board[60 :151 , 135 :481 ] = color
522521fig, ax = plt.subplots()
523- plt .imshow(board)
522+ ax .imshow(board)
524523```
525524
526525First, we sample a single pixel's colour at a particular location of the
@@ -559,12 +558,12 @@ in the image.
559558# load and display original image
560559maize_roots = iio.imread(uri = " data/maize-root-cluster.jpg" )
561560fig, ax = plt.subplots()
562- plt .imshow(maize_roots)
561+ ax .imshow(maize_roots)
563562
564563# extract and display sub-image
565564clipped_maize = maize_roots[0 :400 , 275 :550 , :]
566565fig, ax = plt.subplots()
567- plt .imshow(clipped_maize)
566+ ax .imshow(clipped_maize)
568567
569568
570569# save sub-image
0 commit comments