dl-workshop-2022

An image is simply a matrix

  1. Upload a grayscale cat image to Google Colab

  2. Load the grayscale image into a numpy array

import cv2
import numpy as np
import matplotlib.pyplot as plt
from google.colab import files

mycolor = cv2.imread('cat-grayscale.jpg')
resized = cv2.resize(mycolor, (128, 128), interpolation = cv2.INTER_AREA)
mygray = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY)
print(mygray.shape)
  1. (Option 1) Display the numpy array’s contents
print(mygray[:15, :15])
  1. (Option 2) Display the numpy array as a heatmap
print(mygray.shape)
plt.imshow(mygray, cmap='gray')
plt.colorbar()
plt.show()
  1. (Option 3) Display the numpy array as a heatmap
np.savetxt('mycat.csv', mygray, fmt='%.1f', delimiter =',')
files.download('mycat.csv')

Questions

  1. If a black and white image is a 2D matrix, what is a color image?
  2. How many dimensions does a video have?
  3. How many dimensions will a list of videos have?