@@ -60,13 +60,13 @@ Next, we will do something with the image:
60
60
61
61
``` python
62
62
fig, ax = plt.subplots()
63
- plt .imshow(chair)
63
+ ax .imshow(chair)
64
64
```
65
65
66
66
Once 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.
70
70
71
71
Now, we will save the image in another format:
72
72
@@ -181,7 +181,7 @@ If we don't convert it before saving,
181
181
182
182
Next, write the resized image out to a new file named ` resized.jpg `
183
183
in 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
185
185
both images in your notebook.
186
186
Don't forget to use ` fig, ax = plt.subplots() ` so you don't overwrite
187
187
the first image with the second.
@@ -214,9 +214,9 @@ iio.imwrite(uri="data/resized_chair.jpg", image=resized_chair)
214
214
215
215
# display images
216
216
fig, ax = plt.subplots()
217
- plt .imshow(chair)
217
+ ax .imshow(chair)
218
218
fig, ax = plt.subplots()
219
- plt .imshow(resized_chair)
219
+ ax .imshow(resized_chair)
220
220
```
221
221
222
222
The 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)
271
271
272
272
# display original image
273
273
fig, ax = plt.subplots()
274
- plt .imshow(maize_roots)
274
+ ax .imshow(maize_roots)
275
275
```
276
276
277
277
Now we can threshold the image and display the result.
@@ -282,7 +282,7 @@ maize_roots[maize_roots < 128] = 0
282
282
283
283
# display modified image
284
284
fig, ax = plt.subplots()
285
- plt .imshow(maize_roots)
285
+ ax .imshow(maize_roots)
286
286
```
287
287
288
288
The NumPy command to ignore all low-intensity pixels is ` roots[roots < 128] = 0 ` .
@@ -331,12 +331,12 @@ chair = iio.imread(uri="data/chair.jpg")
331
331
332
332
# display original image
333
333
fig, ax = plt.subplots()
334
- plt .imshow(chair)
334
+ ax .imshow(chair)
335
335
336
336
# convert to grayscale and display
337
337
gray_chair = ski.color.rgb2gray(chair)
338
338
fig, ax = plt.subplots()
339
- plt .imshow(gray_chair, cmap = " gray" )
339
+ ax .imshow(gray_chair, cmap = " gray" )
340
340
```
341
341
342
342
We can also load colour images as grayscale directly by
@@ -350,7 +350,7 @@ gray_chair = iio.imread(uri="data/chair.jpg", mode="L")
350
350
351
351
# display grayscale image
352
352
fig, ax = plt.subplots()
353
- plt .imshow(gray_chair, cmap = " gray" )
353
+ ax .imshow(gray_chair, cmap = " gray" )
354
354
```
355
355
356
356
The first argument to ` iio.imread() ` is the filename of the image.
@@ -415,7 +415,6 @@ sudoku_gray_background[sudoku_gray_background > 192] = 192
415
415
Finally, 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.
416
416
417
417
``` python
418
- fig, ax = plt.subplots()
419
418
fig, ax = plt.subplots(ncols = 2 )
420
419
ax[0 ].imshow(sudoku, cmap = " gray" , vmin = 0 , vmax = 255 )
421
420
ax[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)
430
429
## Plotting single channel images (cmap, vmin, vmax)
431
430
432
431
Compared 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` ,
434
433
Matplotlib uses a colour map, to assign each intensity value a colour.
435
434
The default colour map is called "viridis" and maps low values to purple
436
435
and 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
438
437
` cmap="gray" ` .
439
438
[ The documentation contains an overview of pre-defined colour maps] ( https://matplotlib.org/stable/gallery/color/colormap_reference.html ) .
440
439
@@ -499,7 +498,7 @@ A script to create the subimage would start by loading the image:
499
498
board = iio.imread(uri = " data/board.jpg" )
500
499
board = np.array(board)
501
500
fig, ax = plt.subplots()
502
- plt .imshow(board)
501
+ ax .imshow(board)
503
502
```
504
503
505
504
Then we use array slicing to
@@ -509,7 +508,7 @@ create a new image with our selected area and then display the new image.
509
508
# extract, display, and save sub-image
510
509
clipped_board = board[60 :151 , 135 :481 , :]
511
510
fig, ax = plt.subplots()
512
- plt .imshow(clipped_board)
511
+ ax .imshow(clipped_board)
513
512
iio.imwrite(uri = " data/clipped_board.tif" , image = clipped_board)
514
513
```
515
514
@@ -520,7 +519,7 @@ We can also change the values in an image, as shown next.
520
519
color = board[330 , 90 ]
521
520
board[60 :151 , 135 :481 ] = color
522
521
fig, ax = plt.subplots()
523
- plt .imshow(board)
522
+ ax .imshow(board)
524
523
```
525
524
526
525
First, we sample a single pixel's colour at a particular location of the
@@ -559,12 +558,12 @@ in the image.
559
558
# load and display original image
560
559
maize_roots = iio.imread(uri = " data/maize-root-cluster.jpg" )
561
560
fig, ax = plt.subplots()
562
- plt .imshow(maize_roots)
561
+ ax .imshow(maize_roots)
563
562
564
563
# extract and display sub-image
565
564
clipped_maize = maize_roots[0 :400 , 275 :550 , :]
566
565
fig, ax = plt.subplots()
567
- plt .imshow(clipped_maize)
566
+ ax .imshow(clipped_maize)
568
567
569
568
570
569
# save sub-image
0 commit comments