@@ -55,6 +55,12 @@ but that each pixel can have a different colour from its neighbors.
55
55
Viewed from a distance,
56
56
these pixels seem to blend together to form the image we see.
57
57
58
+ Real-world images are typically made up of a vast number of pixels,
59
+ and each of these pixels is one of potentially millions of colours.
60
+ While we will deal with pictures of such complexity in this lesson,
61
+ let's start our exploration with just 15 pixels in a 5 x 3 matrix with 2 colours,
62
+ and work our way up to that complexity.
63
+
58
64
::::::::::::::::::::::::::::::::::::::::: callout
59
65
60
66
## Matrices, arrays, images and pixels
@@ -70,30 +76,64 @@ the terms matrix and array will be used interchangeably.
70
76
71
77
::::::::::::::::::::::::::::::::::::::::::::::::::
72
78
73
- ## Working with pixels
79
+ ## Loading images
74
80
75
- As noted, in practice,
76
- real-world images will typically be made up of a vast number of pixels,
77
- and each of these pixels will be one of potentially millions of colours.
78
- While we will deal with pictures of such complexity shortly,
79
- let's start our exploration with 15 pixels in a 5 x 3 matrix with 2 colours and
80
- work our way up to that complexity.
81
+ As noted, images we want to analyze (process) with Python are loaded into arrays.
82
+ There are multiple ways to load images. In this lesson, we use imageio, a Python
83
+ library for reading (loading) and writing (saving) image data, and more specifically
84
+ its version 3. But, really, we could use any image loader which would return a
85
+ NumPy array.
81
86
82
- First, the necessary imports:
87
+ ``` python
88
+ """ Python library for reading and writing images."""
89
+
90
+ import imageio.v3 as iio
91
+ ```
92
+
93
+ The ` v3 ` module of imageio (` imageio.v3 ` ) is imported as ` iio ` (see note in
94
+ the next section).
95
+ Version 3 of imageio has the benefit of supporting nD (multidimensional) image data
96
+ natively (think of volumes, movies).
97
+
98
+ Let us load our image data from disk using
99
+ the ` imread ` function from the ` imageio.v3 ` module.
100
+
101
+ ``` python
102
+ eight = iio.imread(uri = " data/eight.tif" )
103
+ print (type (eight))
104
+ ```
105
+
106
+ Note that, using the same image loader or a different one, we could also read in
107
+ remotely hosted data.
108
+
109
+ ::::::::::::::::::::::::::::::::::::::::: callout
110
+
111
+ ## Why not use ` skimage.io.imread() `
112
+
113
+ The scikit-image library has its own function to read an image,
114
+ so you might be asking why we don't use it here.
115
+ Actually, ` skimage.io.imread() ` uses ` iio.imread() ` internally when loading an image into Python.
116
+ It is certainly something you may use as you see fit in your own code.
117
+ In this lesson, we use the imageio library to read or write images,
118
+ while scikit-image is dedicated to performing operations on the images.
119
+ Using imageio gives us more flexibility, especially when it comes to
120
+ handling metadata.
121
+
122
+ ::::::::::::::::::::::::::::::::::::::::::::::::::
123
+
124
+ ## Working with pixels
125
+
126
+ First, let us add the necessary imports:
83
127
84
128
``` python
85
129
""" Python libraries for learning and performing image processing."""
86
130
87
- import imageio.v3 as iio
88
131
import ipympl
89
132
import matplotlib.pyplot as plt
90
133
import numpy as np
91
134
import skimage as ski
92
135
```
93
136
94
- The ` v3 ` module of imageio (` imageio.v3 ` ) is imported as ` iio ` . This module
95
- enables us to read and write images.
96
-
97
137
:::::::::::::::::::::::::::::::::::::::: callout
98
138
99
139
## Import statements in Python
@@ -162,32 +202,10 @@ more efficiently run commands later in the session.
162
202
% matplotlib widget
163
203
```
164
204
165
- With that taken care of,
166
- let's load our image data from disk using
167
- the ` imread ` function from the ` imageio.v3 ` module and display it using
205
+ With that taken care of, let us display the image we have loaded, using
168
206
the ` imshow ` function from the ` matplotlib.pyplot ` module.
169
- Imageio is a Python library for reading and writing image data.
170
- ` imageio.v3 ` is specifying that we want to use version 3 of imageio. This
171
- version has the benefit of supporting nD (multidimensional) image data
172
- natively (think of volumes, movies).
173
-
174
- ::::::::::::::::::::::::::::::::::::::::: callout
175
-
176
- ## Why not use ` skimage.io.imread() `
177
-
178
- The scikit-image library has its own function to read an image,
179
- so you might be asking why we don't use it here.
180
- Actually, ` skimage.io.imread() ` uses ` iio.imread() ` internally when loading an image into Python.
181
- It is certainly something you may use as you see fit in your own code.
182
- In this lesson, we use the imageio library to read or write (save) images,
183
- while scikit-image is dedicated to performing operations on the images.
184
- Using imageio gives us more flexibility, especially when it comes to
185
- handling metadata.
186
-
187
- ::::::::::::::::::::::::::::::::::::::::::::::::::
188
207
189
208
``` python
190
- eight = iio.imread(uri = " data/eight.tif" )
191
209
plt.imshow(eight)
192
210
```
193
211
0 commit comments