Image processing forms the foundation of computer vision, providing essential techniques for manipulating and analyzing digital images. These fundamental operations transform raw image data into formats that highlight important features and prepare images for higher-level analysis.
Image Representation and Color Spaces #
Digital Image Structure #
Digital images are represented as discrete grids of pixels (picture elements), each storing color or intensity information:
- Raster Images: Grid-based representation where each pixel has a specific value.
- Resolution: The number of pixels in an image, typically expressed as width × height.
- Bit Depth: The number of bits used to represent each pixel, determining the range of possible values.
- Channels: Separate components that together form a complete image (e.g., RGB has three channels).
Common Color Spaces #
Color spaces are different ways of representing color information in images:
- RGB (Red, Green, Blue): Additive color model used in digital displays.
- CMYK (Cyan, Magenta, Yellow, Key/Black): Subtractive color model used in printing.
- Grayscale: Single-channel representation of intensity values.
- HSV/HSL (Hue, Saturation, Value/Lightness): Represents colors in terms of their perceptual components.
- YCbCr: Separates luminance (Y) from chrominance (Cb, Cr), used in video compression.
- LAB: Designed to be perceptually uniform, with L for lightness and a, b for color dimensions.
# Example of color space conversions using OpenCV
import cv2
import numpy as np
import matplotlib.pyplot as plt
# Load an image
img = cv2.imread('sample_image.jpg')
# Convert BGR (OpenCV default) to RGB
rgb_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Convert to grayscale
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Convert to HSV
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# Display images
plt.figure(figsize=(15, 10))
plt.subplot(2, 2, 1)
plt.title('Original (BGR)')
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) # Convert for display
plt.axis('off')
plt.subplot(2, 2, 2)
plt.title('RGB')
plt.imshow(rgb_img)
plt.axis('off')
plt.subplot(2, 2, 3)
plt.title('Grayscale')
plt.imshow(gray_img, cmap='gray')
plt.axis('off')
plt.subplot(2, 2, 4)
plt.title('HSV')
plt.imshow(cv2.cvtColor(hsv_img, cv2.COLOR_HSV2RGB)) # Convert for display
plt.axis('off')
plt.tight_layout()
plt.show()
Feature Extraction #
Feature extraction identifies distinctive elements in images that are useful for analysis and recognition tasks.
Low-level Features #
Keep reading with a free Eristotle account.
Every document across our Bodies of Knowledge is free to read once you are signed in. No payment, no tier.
