Digital Image Processing
Chapter 1 | Introduction
What is a digital image?
A digital image is a two-dimensional representation as a finite set of digital values
called pixels.
Pixel values can represent gray levels, colors, heights, opacities, etc.
Common image formats include:
o 1 sample per point (B&W or Grayscale)
o 3 samples per point (RGB)
o 4 samples per point (RGBA - with opacity)
Digitization implies the approximation of a real scene.
What is Digital Image Processing (DIP)?
Focuses on two major tasks:
o Improving pictorial information for human interpretation.
o Processing image data for storage, transmission, and representation for
autonomous machine perception.
It ranges from low-level (noise removal) to mid-level (object recognition) to high-
level processes (scene understanding).
History of Digital Image Processing
1920s: Early use in newspaper image transmission (Bartlane system).
1960s: Space race accelerated digital image processing.
o Used in enhancing moon images from the Ranger 7 probe.
1970s: Medical applications like CAT scans began.
1980s - Present: Extensive use across diverse fields like medical imaging, industrial
inspection, law enforcement, and more.
Examples of Digital Image Processing
Image Enhancement: Quality improvement and noise removal.
Hubble Telescope: Image processing corrected faulty mirror issues.
1| P a g e Year 4
Semester 8
Artistic Effects: To create visually appealing or composite images.
Medical Imaging: MRI scans for tissue differentiation.
Geographic Information Systems (GIS): Satellite imagery analysis for meteorology
and terrain classification.
Industrial Inspection: PCB inspection to detect missing components.
Law Enforcement: Number plate and fingerprint recognition.
Human-Computer Interaction (HCI): face and gesture recognition.
Key Stages in Digital Image Processing
Image Acquisition: Capturing digital images.
Image Restoration: Correcting distortions or degradations.
Morphological Processing: Analyzing structures in images.
Segmentation: Dividing an image into meaningful regions.
Representation & Description: Extracting features for further analysis.
Image Enhancement: Highlighting important features for better visualization.
Object Recognition: Identifying objects within an image.
Image Compression: Reducing image size for storage and transmission.
Color Image Processing: Handling colored images for diverse applications.
Chapter 2 | The Processing Development Environment
Introduction to Processing Development Environment (PDE)
Processing is a free, open-source tool with a development environment similar to
Arduino.
It is primarily based on the Java language, but its code can be translated to other
environments that support serial communication.
Features of the Processing Development Environment (PDE)
The PDE has a simple text editor for writing code, a message area, a text console,
tabs for managing files, a toolbar for common actions, and various menus.
The default mode is Java, but it can change depending on the environment.
In Processing, a computer program is called a sketch, and sketches are stored in a
folder named Sketchbook on your computer.
2| P a g e Year 4
Semester 8
Basic Code Examples
Line Drawing:
void setup() {
size(500, 400);
void draw() {
background(255); // White background
line(60, 50, 100, 50);
Triangle Drawing:
void draw() {
triangle(60, 10, 25, 60, 75, 65);
line(60, 30, 25, 80);
line(25, 80, 75, 85);
line(75, 85, 60, 30);
}
Ellipse, Circle and Rectangle Drawing:
void draw() {
ellipse(40, 40, 60, 60); // Circle
rect(50, 50, 30, 40); // Rectangle
}
3| P a g e Year 4
Semester 8
Quad Literal(Drawing Quadrilateral)
Void draw(){
quad(20, 20, 20, 70, 86, 90, 60, 40);
quad(20, 20, 30, -76, 110, 0, 60, 40);
}
Chapter 3 |Image Processing
1. Loading and Displaying Images in Processing
PImage is used to handle image files in Processing.
PImage img;
img = loadImage("your_image.jpg");
image(img, x, y);
The image must be inside the data folder of your sketch
You can resize images using:
img.resize(width, height);
2. Practical Example 1: Displaying an Image
PImage
PImagehog1;void
hog1;voidsetup(){
setup(){
size(700, 500);
size(700, 500);
hog1 = loadImage("hog.jpg");
hog1
}void = loadImage("hog.jpg");
draw(){
image(hog1,
}void draw(){0, 0);
fill(0, 255, 0); 0, 0);
image(hog1,
ellipse(300, 200, 10, 10);
fill(0, 255, 0);
}
ellipse(300, 200, 10, 10);
}
4| P a g e Year 4
Semester 8
Loads an image and draws a green circle over it.
3. Using Mouse Position for Drawing
You can use mouseX and mouseY for dynamic interactions.
void setup() {
size(200, 200);
}void draw() {
background(255);
rectMode(CENTER);
rect(mouseX, mouseY, 50, 50);
}
The rectangle moves with your mouse.
4. Practical Example 2: Dynamic Image Scaling
PImage images;void setup(){
size(240,240);
images = loadImage("images.jpeg");
}void draw(){
image(images, 0, 0, mouseX,
mouseY);
}
Scales the image based on mouse position (width = mouseX, height = mouseY)
5. Practical Example 3: Tinting Images
tint(r, g, b) adds a color overlay to images.
5| P a g e Year 4
Semester 8
PImage images;void setup(){
size(240,240);
images = loadImage("images.jpeg");
}
void draw(){
tint(255, 0, 0); // Apply red tint
image(images, 0, 0, mouseX,
mouseY);
}
6. Drawing a Character (Zoog)
Uses shapes like rectangles and ellipses to draw a cartoon character.
void draw() {
background(255);
ellipseMode(CENTER);
rectMode(CENTER);
rect(100, 100, 20, 100); // Body
ellipse(100, 70, 60, 60); // Head
ellipse(81, 70, 16, 32); // Left eye
ellipse(119, 70, 16, 32); // Right eye
line(90, 150, 80, 160); // Left leg
line(110, 150, 120, 160); // Right leg
}
7. Drawing Lines from Keyboard Input
Uses JOptionPane to take user input (coordinates) and draw a line.
Includes input validation using try-catch.
import javax.swing.JOptionPane;
Draws a line based on entered coordinates.
6| P a g e Year 4
Semester 8
Chapter 4 |Introduction to MATLAB and image processing
Introduction
Image processing involves manipulating images to improve quality or extract
information.
Digital image processing is widely used in medical imaging, remote sensing, and
industrial automation.
MATLAB is a powerful tool due to its built-in functions and Image Processing
Toolbox.
Digital Image Representation
Images are represented as 2D arrays of intensity values (grayscale) or 3D arrays
(color).
Each pixel in the array has a value corresponding to brightness or color.
Color images use three channels: Red, Green, and Blue (RGB).
Image Types
Binary Images: Only black and white (0 or 1).
Grayscale Images: Shades of gray (0–255 for 8-bit images).
Color Images: Composed of three 2D arrays (RGB).
MATLAB supports multiple formats: JPEG, PNG, BMP, TIFF, etc.
Reading and Displaying Images
imread() is used to read images.
imshow() displays the image.
Syntax example:
I = imread('image.jpg');
imshow(I);
Writing Images
imwrite() saves images to a file.
7| P a g e Year 4
Semester 8
Can specify format and filename.
Syntax example:
imwrite(I, 'output.png');
Image Conversion
Convert between types using:
rgb2gray() – Color to grayscale.
im2bw() – Image to binary.
im2double() – Convert to double precision.
Image Arithmetic Operations
Operations include addition, subtraction, multiplication, and division.
Useful for image enhancement or masking.
Example: Adding two images
C = A + B;
Image Logical Operations
Use logical operators: AND, OR, NOT, XOR.
Useful in segmentation and masking.
Example:
C = A & B;
Image Histogram
A histogram shows pixel intensity distribution.
imhist() displays the histogram.
Histogram equalization using histeq() improves contrast.
Image Filtering
8| P a g e Year 4
Semester 8
Filtering enhances or suppresses image features.
Types:
1. Linear Filters (mean, Gaussian)
2. Non-linear Filters (median)
3. Use imfilter() or medfilt2() in MATLAB.
Edge Detection
Detects object boundaries.
Techniques: Sobel, Prewitt, Canny.
Use edge() function:
BW = edge(I, 'canny');
Morphological Operations
Operates on binary images.
Common operations: dilation, erosion, opening, closing.
Functions: imdilate(), imerode(), imopen(), imclose().
Image Segmentation
Divides image into meaningful regions.
Techniques: thresholding, edge-based, region-based.
MATLAB functions: imbinarize(), bwlabel(), regionprops().
Digita Image Processing
Chapter 1, 2, 3, 4
END
9| P a g e Year 4
Semester 8