Lab 1 (Image Basics)
Lab 1 (Image Basics)
ipynb - Colaboratory
An image can be thought of as a matrix where every pixel’s color is represented by a number on a scale.
/usr/local/lib/python3.10/dist-packages/skimage/io/_plugins/matplotlib_plugin.py:150:
lo, hi, cmap = _get_display_range(image)
Although our examples were picking colors on the extreme end of the spectrum, we can also access any of the colors in between.
https://colab.research.google.com/drive/1oCuBNe3Rc72sSc-Kqp5COVK1oq-EmvFY#scrollTo=qZmQg1931hVK&printMode=true 1/4
11/16/23, 10:51 PM Lab 1 (Image Basics).ipynb - Colaboratory
The below image was constructed with the use of the arange function of NumPy and created another image by getting the transpose of the first
one.
array_spectrum = np.array([np.arange(0,255,15),
np.arange(255,0,-15),
np.arange(0,255,15),
np.arange(255,0,-15)])
fig, ax = plt.subplots(1, 2, figsize=(12,4))
ax[0].imshow(array_spectrum, cmap = 'gray')
ax[0].set_title('Arange Generation')
ax[1].imshow(array_spectrum.T, cmap = 'gray')
ax[1].set_title('Transpose Generation');
# Color Matrix
array_colors = np.array([[[255, 0, 0],
[0, 255, 0],
[0, 0, 255]]])
imshow(array_colors);
doggo = imread('doggo.PNG')
imshow(doggo);
doggo.shape # height, width, channels
https://colab.research.google.com/drive/1oCuBNe3Rc72sSc-Kqp5COVK1oq-EmvFY#scrollTo=qZmQg1931hVK&printMode=true 2/4
11/16/23, 10:51 PM Lab 1 (Image Basics).ipynb - Colaboratory
(371, 369, 4)
fig, ax = plt.subplots(1, 3,
figsize=(6,4),
sharey= True)
ax[0].imshow(doggo[:, 0:130])
ax[0].set_title('First Split')
ax[1].imshow(doggo[:, 130:260])
ax[1].set_title('Second Split')
ax[2].imshow(doggo[:, 260:390])
ax[2].set_title('Third Split');
imshow(doggo[95:250, 130:275]);
https://colab.research.google.com/drive/1oCuBNe3Rc72sSc-Kqp5COVK1oq-EmvFY#scrollTo=qZmQg1931hVK&printMode=true 3/4
11/16/23, 10:51 PM Lab 1 (Image Basics).ipynb - Colaboratory
doggo_gray = rgb2gray(doggo)
fig, ax = plt.subplots(1, 5, figsize=(17,6), sharey = True)
ax[0].imshow(doggo_gray, cmap = 'gray')
ax[0].set_title('Grayscale Original')
ax[1].imshow(img_as_uint(doggo_gray > 0.25),
cmap = 'gray')
ax[1].set_title('Greater than 0.25')
ax[2].imshow(img_as_uint(doggo_gray > 0.50),
cmap = 'gray')
ax[2].set_title('Greater than 0.50');
ax[3].imshow(img_as_uint(doggo_gray > 0.75),
cmap = 'gray')
ax[3].set_title('Greater than 0.75');
ax[4].imshow(img_as_uint(doggo_gray > np.mean(doggo_gray)),
cmap = 'gray')
ax[4].set_title('Greater than Mean');
https://colab.research.google.com/drive/1oCuBNe3Rc72sSc-Kqp5COVK1oq-EmvFY#scrollTo=qZmQg1931hVK&printMode=true 4/4