0% found this document useful (0 votes)
2 views20 pages

Computer Vision L2 - BSC

The document provides an overview of digital images, including their representation through pixels and matrices, and various color models such as RGB, grayscale, and HSV. It discusses image resolution, channels, pixel intensity, and the importance of color models in computer vision tasks. Additionally, it covers basic image operations using OpenCV, including reading, displaying, and converting images.

Uploaded by

Kobby Veon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views20 pages

Computer Vision L2 - BSC

The document provides an overview of digital images, including their representation through pixels and matrices, and various color models such as RGB, grayscale, and HSV. It discusses image resolution, channels, pixel intensity, and the importance of color models in computer vision tasks. Additionally, it covers basic image operations using OpenCV, including reading, displaying, and converting images.

Uploaded by

Kobby Veon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Digital Images and

Color Models
Lecture Overview
• Understand how digital images are represented using
pixels and matrices.
• Explore various color models including RGB, grayscale,
HSV.
• Perform basic image operations using OpenCV: reading,
displaying, converting images.
THEORETICAL FOUNDATIONS
What is a Digital Image?
• A digital image is a representation of a visual scene stored as a
discrete grid of pixels (picture elements), each containing a
value or set of values that represent the brightness and/or
color at that point.
• Mathematical Definition:
A digital image can be viewed as a 2D function:
ƒ (x, y)
• where x and y are spatial coordinates, and ff represents the
intensity (for grayscale) or a vector of intensities (for color
images).
• For grayscale: f(x,y)∈[0,255]
• For color: f(x,y)=[R,G,B], each ∈[0,255]
Image Resolution
• Resolution refers to the number of pixels in the image
along the width and height dimensions.
• Resolution=Width×Height
• E.g., an image with resolution 1920×1080 contains
2,073,600 pixels.
• High Resolution: More details, larger file size.
• Low Resolution: Less detail, faster processing, smaller
file.
• Aspect Ratio: Proportion of width to height (e.g., 16:9,
4:3).
Image Channels
• Color models define the way colors are represented in
digital images.

(a) RGB (Red-Green-Blue):


• Additive color model: Colors are created by combining red,
green, and blue light.
• Widely used in cameras, screens, and most image formats.
• Each color pixel is stored as a triplet: [R,G,B], where each
value ranges from 0 to 255.
(b) Grayscale:
• Single intensity value per pixel
(no color).
• Conversion from RGB uses
weighted sum (luminosity
method):
• Gray=0.299⋅R+0.587⋅G+0.114⋅B
• Used in many image processing
tasks for simplification.
(c) HSV (Hue, Saturation, Value):
• Separates color information
(Hue) from intensity
(Value) and vividness (Saturation).
• Hue: Type of color (0°–360°)
• Saturation: Color purity (0–1)
• Value: Brightness (0–1)
• Better suited for tasks like color filtering or
detection.
(d) LAB Color Space:
• Based on human perception.
• L: Lightness, A: Green–Red, B: Blue–Yellow.
• Useful for tasks where perceptual differences matter.

(e) YCrCb, CMYK, and Others:


• YCrCb: Used in video compression (Y = luma, Cr/Cb =
chroma)
• CMYK: Cyan, Magenta, Yellow, Black – used in printing.
Images Channels
Each image consists of one or more channels:
• RGB: 3 channels – Red, Green, Blue.
• Grayscale: 1 channel – Intensity only.
• HSV: 3 channels – Hue, Saturation, Value.

Think of an RGB image as three 2D matrices stacked


together.
Pixel Intensity and Depth
• Pixel intensity is the numerical value that represents
brightness (grayscale) or color (in multi-channel
images).
• Typically stored as 8-bit unsigned integers (0–255).
• Image bit depth defines the number of possible values
a pixel can take:
• 1-bit: 2 values (black or white)
• 8-bit: 256 values (0–255)
• 24-bit color: 8 bits per channel (16.7 million colors)
Image Representation in Memory
An image is stored as:
• A NumPy array (in Python/OpenCV).
• For a 512×512 RGB image:
• Shape = (512, 512, 3)
• Each of the 3 channels is a 512×512 matrix.
Image Metadata
• Digital images often include metadata such as:
• Resolution
• Color model
• Bit depth
• EXIF data (for photographs: GPS, exposure, camera
model, etc.)
Importance of Color Models in
Computer Vision
Proper choice of color space improves accuracy in
tasks like:
• Skin detection: HSV/YCrCb is better than RGB.
• Edge detection: Grayscale simplifies computation.
• Object tracking: HSV helps with illumination
invariance.
• Compression: YCrCb allows better visual quality at
lower bitrates.
OpenCV image Operations
• Install OpenCv
• pip install opencv-python
Reading and
Displaying Images
• import cv2

• # Load image (color)


• img = cv2.imread(‘’image1.jpg')

• # Display image
• cv2.imshow('Original Image', img)
• cv2.waitKey(0)
• cv2.destroyAllWindows()
Coverting to Graycale
• gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
• cv2.imshow('Grayscale Image', gray_img)
• cv2.waitKey(0)
• cv2.destroyAllWindows()
Extracting Invidul Channels
• blue, green, red = cv2.split(img)

• cv2.imshow("Blue Channel", blue)


• cv2.imshow("Green Channel", green)
• cv2.imshow("Red Channel", red)
• cv2.waitKey(0)
• cv2.destroyAllWindows()
Saving an Image
• cv2.imwrite('gray_output.jpg', gray_img)

Image Info (Dimensions and Channels)


• print("Image Shape:", img.shape) # (height, width,
channels) print("Pixel at (100, 50):", img[100, 50]) #
BGR values
Tutorial practicals
Load any image and display the three color channels
separately.
Convert the image to grayscale and compare the size of
the RGB and grayscale versions.
Display the image in HSV color space:
Assignment
Image Color Transformation

• Write a Python script that:


• Loads a color image.
• Converts it to grayscale, HSV, and LAB color models.
• Displays and saves each version.
• Plot the histogram of the grayscale image.

You might also like