# Carpentries Instructor Training HW
Azin Karimzad, TU Delft Phd candidate
Research interests: ML, DL, Seismic imaging, Geophysics
## Image Processing with Python
### Section 1: Introducing Colour Matrices (1 minute)
```
import matplotlib.pyplot as plt
import imageio as iio
```
**1. import matplotlib.pyplot as plt:** This line imports the matplotlib.pyplot module and gives it an alias, plt. This module contains functions to help create plots and graphs.
**2. import imageio as iio:** This line imports the imageio library and names it as iio. imageio is used for reading and writing a wide range of image data, including animated images, volumetric data, and scientific formats.
```
three_colours = iio.imread(uri="data/eight.tif")
three_colours = three_colours * 128
three_colours[2, :] = 255.
```
1. **three_colours = iio.imread(uri="data/eight.tif"):** This line reads the image data from the file located at "data/eight.tif" and stores it in the three_colours variable.
1. **three_colours = three_colours * 128:** This line multiplies every pixel value in the three_colours image by 128. This could be a part of an image enhancement technique, altering the pixel intensities across the entire image.
1. **three_colours[2, :] = 255.:** This line sets all the pixels in the third row of the image to a value of 255, potentially highlighting or altering that row in the image.
### Section 2: Exploring Colour Maps (1 minute)
"Now, let’s discuss color maps. Color maps help us in visualizing data with more insight. Let’s visualize our current image with the default color map."
```
fig, ax = plt.subplots()
plt.imshow(three_colours)
print(three_colours)
```
1. **fig, ax = plt.subplots():** This line initializes a new figure and axes for the plot.
1. **plt.imshow(three_colours):** This line displays the three_colours image data using the default color map.
1. **print(three_colours):** This line prints the array representation of the three_colours image to the console, allowing you to view the numerical values of the pixels.

Noticed the colors? Now, let’s change it to grayscale. Observe how the colors change, and try to understand the reason behind it."
```
fig, ax = plt.subplots()
plt.imshow(three_colours, cmap=plt.cm.gray)
```
1. **plt.imshow(three_colours, cmap=plt.cm.gray):** This line displays the three_colours image data, but this time with a grayscale color map, where pixel intensity values are mapped to shades of gray.

### Section 3: Understanding Multidimensional Colour Representation (1 minute)
"Finally, let's venture into multidimensional matrices. These are vital in representing complex color information in images. It's a bit more advanced, but extremely useful."
"We're going to create a 4x4 checkerboard with random colors. Here, each dimension represents a different color component. Let’s create this using NumPy, a powerful library for numerical computing in Python."
```
import numpy as np
pseudorandomizer = np.random.RandomState(2021)
checkerboard = pseudorandomizer.randint(0, 255, size=(4, 4, 3))
fig, ax = plt.subplots()
plt.imshow(checkerboard)
print(checkerboard)
```
1. **import numpy as np:** This line imports the numpy library, which is a powerful tool for working with numerical data in Python, and aliases it as np.
1. **pseudorandomizer = np.random.RandomState(2021):** This initializes a random number generator with a seed value of 2021, ensuring reproducible results.
1. **checkerboard = pseudorandomizer.randint(0, 255, size=(4, 4, 3)):** This line generates a 4x4x3 array of random integers between 0 and 255 to create a checkerboard pattern with random colors.
1. **fig, ax = plt.subplots():** This line initializes a new figure and axes for the plot, similar to earlier.
1. **plt.imshow(checkerboard):** This line displays the generated checkerboard image with random colors.
1. **print(checkerboard):** This line prints the numerical representation of the checkerboard image to the console.

### Conclusion and Q&A (20 seconds)
"That was a small glimpse into the world of image processing. Remember, practice makes perfect. I encourage you to explore more and experiment with the codes we discussed today."
"Does anyone have any questions or observations they would like to share?"