From 68b497a9e7b7dd8fbf29f06108bfb94091d378d9 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 1 Dec 2023 21:13:42 +0000 Subject: [PATCH] differences for PR #311 --- 02-image-basics.md | 112 ++++++++++++++++++++++++++------------------- md5sum.txt | 2 +- 2 files changed, 66 insertions(+), 48 deletions(-) diff --git a/02-image-basics.md b/02-image-basics.md index db455ed3..2629ad2f 100644 --- a/02-image-basics.md +++ b/02-image-basics.md @@ -55,48 +55,88 @@ but that each pixel can have a different colour from its neighbors. Viewed from a distance, these pixels seem to blend together to form the image we see. -## Working with Pixels - -As noted, in practice, -real world images will typically be made up of a vast number of pixels, -and each of these pixels will be one of potentially millions of colours. -While we will deal with pictures of such complexity shortly, -let's start our exploration with 15 pixels in a 5 X 3 matrix with 2 colours and -work our way up to that complexity. +Real-world images are typically made up of a vast number of pixels, +and each of these pixels is one of potentially millions of colours. +While we will deal with pictures of such complexity in this lesson, +let's start our exploration with just 15 pixels in a 5 x 3 matrix with 2 colours, +and work our way up to that complexity. ::::::::::::::::::::::::::::::::::::::::: callout ## Matrices, arrays, images and pixels -The **matrix** is mathematical concept - numbers evenly arranged in a rectangle. This can be a two dimensional rectangle, -like the shape of the screen you're looking at now. Or it could be a three dimensional equivalent, a cuboid, or have -even more dimensions, but always keeping the evenly spaced arrangement of numbers. In computing, **array** refers -to a structure in the computer's memory where data is stored in evenly-spaced **elements**. This is strongly analogous +A **matrix** is a mathematical concept - numbers evenly arranged in a rectangle. This can be a two-dimensional rectangle, +like the shape of the screen you're looking at now. Or it could be a three-dimensional equivalent, a cuboid, or have +even more dimensions, but always keeping the evenly spaced arrangement of numbers. In computing, an **array** refers +to a structure in the computer's memory where data is stored in evenly spaced **elements**. This is strongly analogous to a matrix. A NumPy array is a **type** of variable (a simpler example of a type is an integer). For our purposes, the distinction between matrices and arrays is not important, we don't really care how the computer arranges our data in its memory. The important thing is that the computer stores values describing the pixels in images, as arrays. And -the terms matrix and array can be used interchangeably. +the terms matrix and array will be used interchangeably. :::::::::::::::::::::::::::::::::::::::::::::::::: -First, the necessary imports: +## Loading images + +As noted, images we want to analyze (process) with Python are loaded into arrays. +There are multiple ways to load images. In this lesson, we use imageio, a Python +library for reading (loading) and writing (saving) image data, and more specifically +its version 3. But, really, we could use any image loader which would return a +NumPy array. ```python -"""Python libraries for learning and performing image processing.""" +"""Python library for reading and writing images.""" import imageio.v3 as iio +``` + +The `v3` module of imageio (`imageio.v3`) is imported as `iio` (see note in +the next section). +Version 3 of imageio has the benefit of supporting nD (multidimensional) image data +natively (think of volumes, movies). + +Let us load our image data from disk using +the `imread` function from the `imageio.v3` module. + +```python +eight = iio.imread(uri="data/eight.tif") +print(type(eight)) +``` + +Note that, using the same image loader or a different one, we could also read in +remotely hosted data. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Why not use `skimage.io.imread()` + +The scikit-image library has its own function to read an image, +so you might be asking why we don't use it here. +Actually, `skimage.io.imread()` uses `iio.imread()` internally when loading an image into Python. +It is certainly something you may use as you see fit in your own code. +In this lesson, we use the imageio library to read or write images, +while scikit-image is dedicated to performing operations on the images. +Using imageio gives us more flexibility, especially when it comes to +handling metadata. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Working with pixels + +First, let us add the necessary imports: + +```python +"""Python libraries for learning and performing image processing.""" + import ipympl import matplotlib.pyplot as plt import numpy as np import skimage as ski ``` -The `v3` module of imageio (`imageio.v3`) is imported as `iio`. This module -enables us to read and write images. - :::::::::::::::::::::::::::::::::::::::: callout -## Import Statements in Python +## Import statements in Python In Python, the `import` statement is used to load additional functionality into a program. @@ -117,7 +157,7 @@ import skimage as ski # form 4, load all of skimage into an object call :::::::::::::::: spoiler -## Further Explanation +## Further explanation In the example above, form 1 loads the entire scikit-image library into the program as an object. @@ -162,32 +202,10 @@ more efficiently run commands later in the session. %matplotlib widget ``` -With that taken care of, -let's load our image data from disk using -the `imread` function from the `imageio.v3` module and display it using +With that taken care of, let us display the image we have loaded, using the `imshow` function from the `matplotlib.pyplot` module. -Imageio is a Python library for reading and writing image data. -`imageio.v3` is specifying that we want to use version 3 of imageio. This -version has the benefit of supporting nD (multidimensional) image data -natively (think of volumes, movies). - -::::::::::::::::::::::::::::::::::::::::: callout - -## Why not use `skimage.io.imread()` - -The scikit-image library has its own function to read an image, -so you might be asking why we don't use it here. -Actually, `skimage.io.imread()` uses `iio.imread()` internally when loading an image into Python. -It is certainly something you may use as you see fit in your own code. -In this lesson, we use the imageio library to read or write (save) images, -while scikit-image is dedicated to performing operations on the images. -Using imageio gives us more flexibility, especially when it comes to -handling metadata. - -:::::::::::::::::::::::::::::::::::::::::::::::::: ```python -eight = iio.imread(uri="data/eight.tif") plt.imshow(eight) ``` @@ -407,7 +425,7 @@ Here we only have a single channel in the data and utilize a grayscale color map to represent the luminance, or intensity of the data and correspondingly this channel is referred to as the luminance channel. -## Even More Colours +## Even more colours This is all well and good at this scale, but what happens when we instead have a picture of a natural landscape that @@ -421,7 +439,7 @@ for individual contributions to a pixel to be adjusted independently. This ability to manipulate properties of groups of pixels separately will be key to certain techniques explored in later chapters of this lesson. To get started let's see an example of how different dimensions of information -combine to produce a set of pixels using a 4 X 4 matrix with 3 dimensions +combine to produce a set of pixels using a 4 x 4 matrix with 3 dimensions for the colours red, green, and blue. Rather than loading it from a file, we will generate this example using NumPy. @@ -524,7 +542,7 @@ When all three channels are combined though, the blue light of those squares is being diluted by the relative strength of red and green being mixed in with them. -## 24-bit RGB Colour +## 24-bit RGB colour This last colour model we used, known as the *RGB (Red, Green, Blue)* model, is the most common. @@ -846,7 +864,7 @@ JPEG images can be viewed and manipulated easily on all computing platforms. ## Examining actual image sizes (optional, not included in timing) Let us see the effects of image compression on image size with actual images. -The following script creates a square white image 5000 X 5000 pixels, +The following script creates a square white image 5000 x 5000 pixels, and then saves it as a BMP and as a JPEG image. ```python diff --git a/md5sum.txt b/md5sum.txt index a74f1518..4e968d19 100644 --- a/md5sum.txt +++ b/md5sum.txt @@ -4,7 +4,7 @@ "config.yaml" "101b3ac4b679126bb1f437306eb1b836" "site/built/config.yaml" "2023-04-25" "index.md" "6e80c662708984307918adfad711e15f" "site/built/index.md" "2023-07-26" "episodes/01-introduction.md" "9755639c515fdbf752422e2e59128f63" "site/built/01-introduction.md" "2023-07-26" -"episodes/02-image-basics.md" "37de5915c4fc80cc12af44d98c31321b" "site/built/02-image-basics.md" "2023-11-24" +"episodes/02-image-basics.md" "95bf7d147221ac877bed9b66f53f3fda" "site/built/02-image-basics.md" "2023-12-01" "episodes/03-skimage-images.md" "eb0da8ebdea3bf84510b22581b790e67" "site/built/03-skimage-images.md" "2023-10-13" "episodes/04-drawing.md" "9d78a765f5e9747ffc2aa43a4a5a414d" "site/built/04-drawing.md" "2023-09-05" "episodes/05-creating-histograms.md" "bdcf983127c242eb995605038598d09f" "site/built/05-creating-histograms.md" "2023-09-18"