xxi
see the function of each of them. Note that such libraries can be installed easily. After
installing the native Python, we can use the pip installer to download and install a library
based on this command: “pip install <lib-name>”. Just type the name of the library. Some
installations are not straightforward and might change if the system changes. Thus,
we can’t cover the different installations. For such reasons, Anaconda is better than
installing each library individually. Let’s discuss the libraries needed.
Python supports a number of built-in data structures: list, tuple, dictionary, set, and
string. Unfortunately, no data structure provides flexibility in data science applications.
These data structures support working with different data types at the same time.
The same data structure might contain numbers, characters, objects, and more. String
is an exception, in which only characters are supported. Moreover, string and tuple are
immutable, which means it is impossible to change their values after they are created.
Dictionary adds a key to each item. Saving image pixels using a dictionary requires
adding a key to each pixel which enlarges the amount of data saved. Set is restricted to
just set operations and images are not restricted to just such operations.
Talking about images, which are the main concern of the book, list is the suitable
data structure. It is a mutable data type that is able to hold matrices. Unfortunately,
working with lists makes the process complex. We have to make sure everything is
numeric, of a certain specific type because different numeric data types can be saved
in the same list. To apply a simple operation such as adding a number to the image, we
have to write loops for visiting each element and apply such operations individually.
In data science applications, it is recommended to use the tools that make applying
the operations easier. There are some challenging tasks to conquer when building an
application, and we do not need to add another challenge in programming such tasks.
For such reasons, the NumPy (Numeric Python) library is used. Its basic role is to
support a new data structure in Python, which is array. Working with NumPy arrays is
simpler than working with lists. For example, using just the addition operator (+), we
can add a number to each element in the image after it is converted into a NumPy array.
Many other libraries have their functions accept and return a NumPy array.
Some operations are supported inside the NumPy array, but it is not meant to apply
operations. The SciPy (Scientific Python) library supports the same operations in the
NumPy arrays and more. It also supports working with the n-dimensional NumPy arrays
(e.g., images) using the scipy.ndimage submodule. For more advanced operations on
images, the scikit-image library is used. For example, image features can be extracted
using this library.
InTroduCTIon