An image is a 2D array of pixels. Each pixel is a 3D vector of red, green, and blue (RGB) values. The RGB values are usually represented as integers between 0 and 255. The RGB values are used to represent the color of the pixel. For example, a pixel with RGB values of (255, 0, 0) is red, (0, 255, 0) is green, and (0, 0, 255) is blue. A pixel with RGB values of (0, 0, 0) is black and (255, 255, 255) is white.
In this notebook, we will learn how to read and write images, and how to manipulate them.
import numpy as npimport matplotlib.pyplot as pltimport pandas as pd plt.style.use('dark_background')# Read an image!wget https://raw.githubusercontent.com/fahadsultan/csc272/main/data/belltower.pngimg = plt.imread('belltower.png');plt.imshow(img);
# Threshold the imageimg_thresh = img_gray >0.5plt.imshow(img_thresh, cmap='gray');
## Crop the imageimg_crop = img_df.iloc[:700, :700]plt.imshow(img_crop, cmap='gray');
# Rotate the imageimg_rot = img_df.transpose()plt.imshow(img_rot, cmap='gray');
Videos
Videos are a sequence of images. Within the context of videos, each image is called a frame. Most videos are a sequence of 24-30 frames per second.
Most modern videos are encoded using a variety of different codecs. A codec is a method of encoding and decoding a video. Some common codecs are H.264, MPEG-4, and VP9.