0% found this document useful (0 votes)
8 views37 pages

Module 5 Cgi Revision

The document discusses various concepts in image processing, particularly focusing on gray level transformations, contrast stretching, histogram equalization, and spatial filtering. It explains the techniques and formulas used to enhance images, improve contrast, and modify pixel values using linear and non-linear filters. The content is structured to provide clear definitions, examples, and applications for each topic, despite some corruption in the text.

Uploaded by

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

Module 5 Cgi Revision

The document discusses various concepts in image processing, particularly focusing on gray level transformations, contrast stretching, histogram equalization, and spatial filtering. It explains the techniques and formulas used to enhance images, improve contrast, and modify pixel values using linear and non-linear filters. The content is structured to provide clear definitions, examples, and applications for each topic, despite some corruption in the text.

Uploaded by

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

module 5 cgi

Module 5 Computer Graphics & Ima…


PDF

analyse the note completely and answer my questions

The file you uploaded, titled "Module 5 Computer Graphics & Image Processing PPT Notes -
Kerala Notes", appears to be a PowerPoint-to-PDF conversion for Module 5 of the CST 304 course
under the KTU 2019 Scheme. The file is partially corrupted and heavily garbled in many places, but
from what’s recoverable, the document likely covers topics related to:

Image Processing Fundamentals

Image Enhancement Techniques

Morphological Image Processing

Image Segmentation

Possibly touches on Color Models and Image Compression

However, due to extensive corruption and encoding issues, much of the text is unreadable or
distorted.

To help you better, please answer:


What specific questions do you have about this note?

Do you want a summary, help preparing for an exam, or clarification on a certain topic from
Module 5?

Let me know how you’d like to proceed!

basic gray level transformation, explain in detail , include


everything in simple word

Certainly! Let’s break down Basic Gray Level Transformations in Image Processing in a simple,
clear, and complete way.

🖼️ What is Gray Level Transformation?


1/37
Gray level transformation means changing the brightness and contrast of an image by modifying
the intensity (gray level) of each pixel.

In a grayscale image:

Each pixel has a value between 0 and 255

0 = black

255 = white

Values in between = shades of gray

Transforming these values helps us:

Improve image visibility

Highlight important features

Prepare images for further processing (like edge detection, segmentation, etc.)

✨ Types of Basic Gray Level Transformations


1. Image Negative
Formula:

s=L−1−r

where:

s = new pixel value

r = original pixel value

L = total number of gray levels (usually 256)

What it does: Inverts the image colors (black becomes white and vice versa).

Use: Useful for medical images (X-rays, etc.) to highlight dark regions.

2. Logarithmic Transformation
Formula:

s = c ⋅ log(1 + r)

where:

2/37
c is a constant (to scale the result)

r is the input pixel value

What it does:

Enhances dark regions

Compresses bright regions

Use: Useful for images with large dynamic range (very bright and very dark areas).

3. Power-Law (Gamma) Transformation


Formula:

s = c ⋅ rγ

where:

γ (gamma) controls the transformation

c is a scaling constant

What it does:

γ < 1: Makes the image brighter

γ > 1: Makes the image darker

Use: Used in display systems, TVs, camera sensors (called gamma correction).

🧠 Why Use These Transformations?


Purpose Method Used

Invert the image Negative transformation

Brighten dark images Log / Gamma (γ < 1)

Darken bright images Gamma (γ > 1)

Adjust contrast All methods in different ways

Highlight certain features Combined use

3/37
📊 Visualization Example
Imagine you have a pixel with intensity 100.

In negative:

s = 255 − 100 = 155


In logarithmic (c = 1):

s = log(1 + 100) ≈ 4.615

(Usually scaled up to fit 0-255 range)

In power-law (γ = 0.5, c = 1):

s = 1000.5 = 10

Each method gives you a different transformation result depending on your purpose.

🧪 Summary Table
Transformation Formula Effect Use Case

Negative s=L-1-r Inverts image Medical, scientific images

Logarithmic s = c * log(1 + r) Brightens dark areas High dynamic range images

Power-law (Gamma) s = c * r^γ Adjusts brightness/contrast Display systems, gamma correction

Would you like a diagram or visual example of these transformations?

explain in detail about contrast streching

Certainly! Let’s break down Contrast Stretching in image processing in a simple and complete
way.

🖼️ What is Contrast Stretching?


4/37
Contrast Stretching (also called Normalization) is a technique used to improve the contrast of an
image by expanding the range of gray levels.

🧠 Why?
Some images look dull or faded because their pixel values fall within a narrow range (e.g.,
100–150 instead of 0–255).

Contrast stretching spreads these values across the full range (0–255), making dark areas
darker and bright areas brighter.

📈 How Contrast Stretching Works


We apply a transformation function to the pixel values of the input image.

Basic Linear Contrast Stretching Formula:


(r − rmin )
s= × (L − 1)

(rmax − rmin )

​ ​

Where:

s = new (output) pixel value

r = original (input) pixel value

r_min = minimum gray level in the input image

r_max = maximum gray level in the input image

L = number of gray levels (usually 256)

📉 Example:
Suppose an image has pixel values between 50 and 180, and we want to stretch it to 0 to 255.

Let’s take a pixel r = 100

(100 − 50) 50
s= × 255 = × 255 ≈ 98
(180 − 50) 130
​ ​

So, the new pixel value becomes 98 in the stretched image.

5/37
📊 Types of Contrast Stretching
There are different methods based on the shape of the transformation function:

1. Linear Contrast Stretching


Applies the same formula above

Simple and effective

Best when the image has a known min and max intensity

2. Piecewise Linear Stretching


Uses different linear functions for different intensity ranges

More control over which parts of the image get enhanced

Example:

Dark pixels remain dark

Mid-range pixels get stretched

Bright pixels stay the same

Looks like an "S" shape curve.

3. Histogram Equalization (advanced version)


Also improves contrast but in a non-linear way

Based on the distribution of pixel intensities (histogram)

Useful when image contrast varies across different regions

(Note: This is more advanced than simple contrast stretching.)

🖌️ Visual Representation (Imagine This):


Before stretching:

6/37
Pixel Value Range Appearance

100–150 Dull grayish image

After stretching to 0–255:

Pixel Value Range Appearance

0–255 High contrast image

Dark areas become darker, bright areas become brighter.

✅ Uses of Contrast Stretching


Satellite imagery

Medical imaging (X-rays, MRIs)

Low-light photographs

Preparing images for edge detection or segmentation

🔁 Summary
Feature Contrast Stretching

Goal Improve image contrast

Method Stretch gray values to full range (0–255)

(r−rmin )
Formula s= ​

(rmax −rmin )
​ ​
​ × 255

Types Linear, Piecewise Linear

Output Clearer, more visually useful image

Would you like me to show you a diagram or Python code that demonstrates contrast stretching
visually?

7/37
explain more about histogram equalisation

Sure! Let’s go step by step and explain Histogram Equalization in a simple and complete way.

📸 What is Histogram Equalization?


Histogram Equalization is a technique in image processing used to enhance contrast by
redistributing the brightness values (gray levels) more evenly across the image.

🧠 Why Use It?


Some images have pixel values concentrated in a narrow range (e.g., all dark or all bright).

Histogram equalization spreads out the pixel values over the full range (0–255), making the
image look clearer and better contrasted.

📊 What is a Histogram?
A histogram shows how many pixels have each gray level.

X-axis = Gray levels (0 to 255)

Y-axis = Number of pixels

Example:
If many pixels have value 50–100, the histogram will be high in that region and flat elsewhere.

⚙️ How Does Histogram Equalization Work?


Step-by-step:

1. Calculate the Histogram:

Count how many times each gray level (0–255) occurs in the image.

2. Compute the Probability:

b f l h l l

8/37
Number of pixels with gray level rk
p(rk ) =

Total number of pixels


​ ​

3. Compute the Cumulative Distribution Function (CDF):

k
CDF(rk ) = ∑ p(rj )
​ ​ ​

j=0

4. Apply the Transformation Function:

sk = (L − 1) × CDF(rk )
​ ​

s_k is the new gray level

L is the number of gray levels (usually 256)

5. Replace all pixel values:

Replace each original pixel value r_k with s_k

🖼️ Result
Original image: pixel values may be clustered → low contrast

Equalized image: pixel values spread → higher contrast

🧪 Example (simplified)
Let’s say you have a small image with 4 gray levels: 0, 1, 2, 3

Original histogram:

Gray 0: 4 pixels

Gray 1: 2 pixels

Gray 2: 2 pixels

Gray 3: 0 pixels

Step 1: Probability
Gray Level Pixels Probability

0 4 0.5

9/37
Gray Level Pixels Probability

1 2 0.25

2 2 0.25

3 0 0.0

Step 2: CDF
Gray Level CDF

0 0.5

1 0.75

2 1.0

3 1.0

Step 3: Transform

sk = (L − 1) × CDF(rk )
​ ​

L=4

Gray Level New Value (s_k)

0 1.5 ≈ 2

1 2.25 ≈ 2

2 3

3 3

So, gray levels get redistributed, boosting contrast.

✅ Advantages of Histogram Equalization


Automatic contrast enhancement

Works well for low-contrast or poorly lit images

10/37
Simple and fast

⚠️ Disadvantages
May over-enhance noise

Not suitable for color images directly (can distort color)

Can produce unnatural results for images with bimodal histograms (two peaks)

🎨 For Color Images?


Apply histogram equalization to the luminance (Y) channel only (not RGB separately)

Use CLAHE (Contrast Limited Adaptive Histogram Equalization) for better results

🧾 Summary
Feature Histogram Equalization

Purpose Improve contrast by equalizing histogram

Works on Grayscale images (or luminance channel)

Key Concept Use CDF to redistribute pixel intensities

Output Enhanced contrast image

Would you like to see a Python code demo or graphical example of how histogram equalization
works?

fundamentals of spatial filtering

Certainly! Let's break down the Fundamentals of Spatial Filtering in Image Processing in a simple
and complete way.

11/37
🧠 What is Spatial Filtering?
Spatial filtering is a technique used to process an image by modifying pixel values using a filter
mask (also called a kernel or window) based on the values of neighboring pixels.

It's called "spatial" because it works directly in the image space (x, y), not in the frequency
domain.

📦 Basic Idea
You move a small matrix (filter mask) across the image.

At each position, it performs a mathematical operation (like averaging, multiplying, or


subtracting).

The result replaces the central pixel of the region.

🧱 Key Components
1. Image:
A 2D array of intensity values (gray level pixels).

2. Filter Mask (Kernel):


A small matrix like 3×3, 5×5, etc.

Example of a 3×3 kernel:

ini

[ a b c
d e f
g h i ]

3. Operation:
Typically convolution or correlation is used:

Multiply corresponding values from the filter and the image region.

12/37
Add the results.

Replace the center pixel.

⚙️ Types of Spatial Filters


🔷 1. Linear Filters
Apply a linear operation to the pixel values.

Common types:

Smoothing (Low-pass filter):

Reduces noise

Averages nearby pixel values

Example: Mean Filter

scss

Mean filter mask (3x3):


[1 1 1
1 1 1
1 1 1] / 9

Sharpening (High-pass filter):

Enhances edges and details

Example: Laplacian Filter

css

Laplacian mask:
[ 0 -1 0
-1 4 -1
0 -1 0 ]

🔶 2. Non-Linear Filters
Operations are not based on addition/multiplication.

Useful for removing noise like salt-and-pepper.

Example:

13/37
Median Filter:

Replaces the center pixel with the median of the surrounding pixels.

Good for preserving edges while removing noise.

🔁 Convolution vs Correlation
Operation Difference

Convolution Flip the filter mask and apply it

Correlation Use the mask as-is

In practice, both give similar results unless the filter is asymmetric.

🧾 Applications of Spatial Filtering


Task Filter Used

Noise reduction Mean / Median Filter

Edge detection Sobel / Prewitt / Laplacian

Image sharpening High-pass filter

Blurring (smoothing) Low-pass filter

Embossing effects Custom kernels

📌 Summary
Feature Description

Definition Modifying a pixel using its neighbors via a filter mask

Filter size Usually small (3x3, 5x5)

14/37
Feature Description

Types Linear (mean, Laplacian), Non-linear (median)

Key operations Convolution, correlation

Main uses Noise removal, edge enhancement, blurring, sharpening

Would you like visual examples or sample Python code for any of these filters?

explain in detail linear and non linear spatial filter in detial with
all included flter

Certainly! Let's explore Linear and Non-Linear Spatial Filters in Image Processing in full detail,
including the most commonly used filters, their working principles, formulas, and use cases.

📦 Spatial Filters Overview


Spatial filters are used to enhance or modify an image by applying a mask (kernel) over the pixels.
Based on the operation they perform, they are divided into:

1. Linear Filters

2. Non-Linear Filters

🔷 1. LINEAR SPATIAL FILTERS


📌 Definition:
A linear filter modifies an image by applying a mathematical (linear) combination of the
neighborhood pixel values using convolution or correlation.

a b
g(x, y) = ∑ ∑ w(s, t) ⋅ f (x + s, y + t)
​ ​

s=−a t=−b

f(x,y) : input image

g(x,y) : output image

15/37
w(s,t) : filter mask/kernel

a, b : define the size of the mask (e.g., 3×3 → a = b = 1)

📘 Common Linear Filters:

🧹 A. Smoothing Filters (Low-Pass Filters)


🟢 Purpose:
Reduce noise

Blur the image

1. Mean Filter (Averaging Filter)

Replaces each pixel with the average of its neighbors

Simple and effective for random noise

3×3 Mean Mask:

csharp

[1 1 1
1 1 1
1 1 1] / 9

2. Weighted Average Filter

Same as mean filter, but gives more weight to the central pixel.

Example:

csharp

[1 2 1
2 4 2
1 2 1] / 16

16/37
🧨 B. Sharpening Filters (High-Pass Filters)
🔴 Purpose:
Enhance edges, fine details, and boundaries

1. Laplacian Filter

Detects edges using second derivatives

Sensitive to noise

Example:

ini

[ 0 -1 0
-1 4 -1
0 -1 0 ]

Another version:

ini

[-1 -1 -1
-1 8 -1
-1 -1 -1]

2. Unsharp Masking

First blur the image (using a low-pass filter)

Subtract blurred image from original

Add difference back to original to enhance edges

g(x, y) = f (x, y) + α[f (x, y) − blurred(x, y)]

3. Gradient Filters (First Derivative Filters)

These highlight regions of rapid intensity change (edges).

➤ Sobel Operator (detects edges in horizontal/vertical direction)

Horizontal:

ini

[-1 0 1
-2 0 2

17/37
-1 0 1]

Vertical:

ini

[ 1 2 1
0 0 0
-1 -2 -1]

➤ Prewitt Operator

Similar to Sobel but with less emphasis on center pixels.

Horizontal:

ini

[-1 0 1
-1 0 1
-1 0 1]

Vertical:

ini

[ 1 1 1
0 0 0
-1 -1 -1]

➤ Roberts Cross Operator

2×2 filter for diagonal edges:

markdown

[ 1 0
0 -1] and [ 0 1
-1 0 ]

🔶 2. NON-LINEAR SPATIAL FILTERS


18/37
📌 Definition:
A non-linear filter uses non-linear operations such as median, min, max, or mode rather than
summation and multiplication.

They are especially good for noise removal without blurring edges.

📘 Common Non-Linear Filters:

💎 A. Median Filter
Replaces the central pixel with the median of the surrounding values.

Example: Given neighborhood: [5, 7, 10, 15, 100] → Median = 10

Removes salt-and-pepper noise (black and white specks)

Preserves edges better than mean filter

🌌 B. Max and Min Filters


1. Max Filter

Replaces pixel with maximum in neighborhood

Removes pepper noise (dark spots)

2. Min Filter

Replaces pixel with minimum in neighborhood

Removes salt noise (white spots)

🎯 C. Midpoint Filter
Averages the max and min values in the neighborhood.

1
g(x, y) = (max + min)
2

19/37
Useful for reducing uniform noise

🌀 D. Mode Filter
Replaces the pixel with the most frequent value in the neighborhood.

Good for reducing impulse noise when many pixels are repeated.

🧾 Summary Table
Filter Type Filter Name Purpose Notes

Linear Mean Filter Blur, reduce random noise Simple, but blurs edges

Weighted Average Blur with center emphasis Better than mean

Laplacian Edge enhancement Uses second derivatives

Sobel / Prewitt Edge detection Uses gradients

Unsharp Masking Sharpen image Combines original + edges

Non-Linear Median Remove salt & pepper noise Best for edge preservation

Max / Min Remove pepper/salt noise Non-linear smoothing

Midpoint General noise reduction Simple average of extremes

Mode Remove impulse noise Requires mode computation

📸 Use Cases
Medical images: Median filter to preserve edges while removing noise.

Satellite imagery: Sobel or Laplacian for boundary detection.

Photography: Unsharp masking to enhance details.

20/37
Would you like a visual diagram or example images to compare these filters?

Module 5 Computer Graphics & Ima…


PDF

gradient and laplacian explain in detail

Let’s break down Gradient and Laplacian operators in image processing in a detailed and
beginner-friendly way.

📌 1. GRADIENT OPERATOR
🔷 What is the Gradient?
The gradient measures the rate and direction of change in intensity at each pixel. It points in the
direction of the most rapid increase in intensity and its magnitude shows how strong the change
(edge) is.

🧠 Used For:
Edge detection

Detecting boundaries in images

📐 Mathematical Form:
Let f(x, y) be the image intensity at point (x, y).

The gradient is a vector:

∂f ∂f
∇f = [ , ]
∂x ∂y
​ ​

∂f
∂x
: horizontal change (edge in vertical direction)

∂f
∂y
: vertical change (edge in horizontal direction)

📏 Gradient Magnitude:
2 2
∂f ∂f
∣∇f ∣ = ( ) +( )
∂x ∂y
​ ​ ​

Approximation (faster):

∂f ∂f
∣∇f ∣ ≈ +
∂x ∂y
​ ​ ​ ​ ​ ​

21/37
🔧 Common Gradient Filters:
➤ Sobel Operator (best for noisy images)

Horizontal (Gx):

ini

[-1 0 1
-2 0 2
-1 0 1]

Vertical (Gy):

ini

[ 1 2 1
0 0 0
-1 -2 -1]

➤ Prewitt Operator (simpler version of Sobel)

Gx:

ini

[-1 0 1
-1 0 1
-1 0 1]

Gy:

ini

[ 1 1 1
0 0 0
-1 -1 -1]

➤ Roberts Cross Operator (uses 2×2 mask, detects diagonal edges)

Gx:

csharp

22/37
[1 0
0 -1]

Gy:

csharp

[0 1
-1 0]

📌 2. LAPLACIAN OPERATOR
🔷 What is Laplacian?
The Laplacian measures the second derivative of the image. It tells how intensity is changing in all
directions—used to detect edges and fine details.

🧠 Used For:
Edge enhancement

Image sharpening

Works well when combined with smoothing

📐 Mathematical Form:
∂2f ∂2f
∇2 f = +
∂x2 ∂y 2
​ ​

🔧 Common Laplacian Kernels:


➤ 4-neighbor Laplacian:

ini

[ 0 -1 0
-1 4 -1
0 -1 0 ]

23/37
➤ 8-neighbor Laplacian:

ini

[-1 -1 -1
-1 8 -1
-1 -1 -1]

🔍 Difference Between Gradient and Laplacian


Feature Gradient Laplacian

Derivative Type First Derivative Second Derivative

Output Vector (has direction) Scalar (no direction)

Use Case Detecting edges and boundaries Enhancing edges and corners

Common Filters Sobel, Prewitt, Roberts Laplacian mask

📸 Visual Effect:
Gradient: Produces thin, strong edge lines, good for outlining objects.

Laplacian: Highlights regions where edges change rapidly—useful for sharpening.

Would you like a visual diagram comparing the effect of these filters on a sample image?

three operator used in edge detection


robert
sobel
prewitt
explain in detail

Certainly! Let's go over the three main edge detection operators—Roberts, Sobel, and Prewitt—
in complete detail, with clear explanations of how they work, their kernels, and when to use each.

24/37
🧠 What is Edge Detection?
Edge detection identifies the boundaries of objects in an image. These boundaries are typically
areas where there is a sudden change in intensity (brightness). Edge detectors help highlight
such transitions.

🟦 1. Roberts Cross Operator


📌 Overview:
One of the earliest and simplest edge detectors.

Uses a 2×2 mask.

Detects edges along the diagonals.

Works by calculating the gradient of the image at a pixel.

📐 Masks (Kernels):
Gx Gy

[1 0] [0 1]

[0 -1] [-1 0]

💡 Formula:
Let I(x, y) be the intensity at pixel (x, y):

Gx = I(x, y) − I(x + 1, y + 1)

Gy = I(x + 1, y) − I(x, y + 1)

Gradient magnitude:

∣G∣ = G2x + G2y


​ ​ ​

✅ Pros:
Fast and simple

Good for real-time applications

❌ Cons:
25/37
Very sensitive to noise

Detects only diagonal edges

Not suitable for noisy or blurry images

🟩 2. Sobel Operator
📌 Overview:
Most commonly used edge detector

Uses a 3×3 mask

Detects edges in horizontal and vertical directions

Places more emphasis on center pixels, reducing noise sensitivity

📐 Masks (Kernels):
Horizontal (Gx):

ini

[-1 0 1
-2 0 2
-1 0 1]

Vertical (Gy):

ini

[ 1 2 1
0 0 0
-1 -2 -1]

💡 Formula:
∣G∣ = G2x + G2y
​ ​ ​

or approximate:

∣G∣ ≈ ∣Gx ∣ + ∣Gy ∣​

✅ Pros:
26/37
Good for detecting both horizontal and vertical edges

More noise-resistant than Roberts

Emphasizes edges better due to weighted center

❌ Cons:
Slightly more computationally expensive than Roberts

🟨 3. Prewitt Operator
📌 Overview:
Similar to Sobel, but simpler

Also uses a 3×3 mask

Less emphasis on the center pixel compared to Sobel

📐 Masks (Kernels):
Horizontal (Gx):

ini

[-1 0 1
-1 0 1
-1 0 1]

Vertical (Gy):

ini

[ 1 1 1
0 0 0
-1 -1 -1]

✅ Pros:
Easy to implement

Works well for basic edge detection

❌ Cons:
27/37
Less accurate than Sobel

Not as good at suppressing noise

📊 Comparison Table
Feature Roberts Sobel Prewitt

Mask Size 2×2 3×3 3×3

Directions Diagonal Horizontal & Vertical Horizontal & Vertical

Noise Handling Poor Good Fair

Edge Quality Sharp but noisy Smooth and clean Moderate

Use Case Real-time, simple General purpose Simpler alternative to Sobel

🎯 When to Use Which?


Roberts → Fastest, for simple and low-noise environments.

Sobel → Best overall performance for general edge detection.

Prewitt → Good balance of speed and performance, suitable for teaching and lightweight
systems.

Would you like a visual side-by-side comparison on an image to see how each operator performs?

fundamental of image segmentation,tresholding,basic of


intensity tresholding,global tresholding,region based
approach,region growing, region splitting and merging explian
all in very detail

Sure! Let's go through Image Segmentation and all its related techniques like Thresholding,
Region-based methods, Region Growing, and Region Splitting & Merging in very detailed yet
simple language.

28/37
📌 What is Image Segmentation?
Image Segmentation is the process of dividing an image into meaningful regions—such as
separating an object from its background.

Imagine drawing boundaries around objects in an image. The goal is to group pixels that have
similar properties (like color, intensity, or texture).

🧠 Why is it important?
Helps in object detection and recognition

Used in medical imaging, robotics, video surveillance, etc.

🧱 Fundamental Techniques of Image Segmentation


There are two main categories:

1. Discontinuity-based: Focuses on sudden changes (edges)

2. Similarity-based: Groups similar pixels together

Let’s focus on Thresholding and Region-based methods, which are similarity-based.

🔹 Thresholding (Basic Intensity Thresholding)


📌 What is Thresholding?
Thresholding converts a grayscale image into a binary image (black and white) by separating
pixels based on intensity.

🎯 Formula:
For a given threshold value T :

g(x, y) = {
1 if f (x, y) ≥ T
0 if f (x, y) < T
​ ​

f(x, y) is the input image pixel value

g(x, y) is the output (binary) image

29/37
1 = white (object), 0 = black (background)

🟦 1. Global Thresholding
A single threshold value (T) is applied to the entire image.

Works well if the image has high contrast between object and background.

🔧 How to choose T?

Use the histogram of the image

If the histogram is bimodal (two peaks), you can choose T between the peaks

✅ Pros:
Simple and fast

❌ Cons:
Doesn’t work well with uneven lighting or low contrast images

🟩 2. Local (Adaptive) Thresholding


Threshold value changes for different parts of the image

Each region or pixel gets its own threshold, based on local properties (mean or median)

✅ Pros:
Works well in non-uniform illumination

❌ Cons:
More complex to compute

🔶 Region-Based Segmentation
Instead of setting a threshold, these methods group connected pixels with similar properties (like
intensity, texture).

30/37
🟧 1. Region Growing
📌 What is it?
Start with a seed point (a pixel known to be part of the object).

Compare neighboring pixels.

If a neighbor is similar enough, it gets added to the region.

Continue until no more pixels meet the condition.

🎯 Similarity condition:
Difference in intensity less than a threshold

Example: |I(x,y) - I(seed)| < T

✅ Pros:
Produces connected regions

Very accurate if the seed and criteria are good

❌ Cons:
Sensitive to noise

Choosing good seed points is tricky

🟨 2. Region Splitting and Merging


📌 What is it?
Instead of growing regions, this method:

1. Splits the image into small square regions (usually quadtree-based)

2. Checks if each region is homogeneous (all pixels similar)

3. If not, it splits the region further

4. Merges adjacent regions that are similar

🔧 Homogeneity Criteria:
All pixel values in a region have similar intensity

The variance is below a threshold

✅ Pros:
Works well for complex images

31/37
No need to define seed points

❌ Cons:
More computationally expensive

May create blocky boundaries

🧾 Summary Table
Technique Type Key Idea Pros Cons

Global Thresholding Intensity One value separates object Fast, simple Fails under poo
& background lighting

Local Thresholding Intensity Threshold varies locally Better with uneven Slower, more co
lighting

Region Growing Region- Start from seed, grow Accurate with good Seed selection,
based similar pixels seeds sensitive to nois

Region Splitting & Region- Divide & combine based on No seed needed, Slow, blocky res
Merging based similarity handles complexity sometimes

📸 Real-Life Examples
Medical imaging: Segmenting tumors from MRI scans

Object detection: Isolating cars, pedestrians, etc.

OCR (Optical Character Recognition): Separating text from background

Would you like Python code examples or diagrams to help you visualize these techniques better?

spatial filter
linear ,non linear
general classification
smoothing spatial filter
linear

32/37
mean filter
average filter and weighted avg fitering
order statics
minimum,maximum,median
sharpening spatial filters

explain all in detail in simple words to make it easily


understandable

Absolutely! Let’s go step-by-step and explain Spatial Filters and their types (Linear, Non-linear,
Smoothing, Sharpening, Mean, Median, Min, Max, etc.) in very simple and clear language.

🧠 What is Spatial Filtering?


Spatial Filtering is a technique in image processing where we apply a small matrix (filter mask or
kernel) over an image to change or enhance its appearance.

It processes the image based on the values of neighboring pixels.

The kernel moves over the image, and for each pixel, it computes a new value using the
surrounding pixels.

🧱 General Classification of Spatial Filters


Spatial filters are generally classified into:

1. Linear Filters

2. Non-Linear Filters

Each can be further used for:

Smoothing (Blurring / Noise Reduction)

Sharpening (Edge Enhancement)

🔷 1. LINEAR SPATIAL FILTERS


📌 What is a Linear Filter?
33/37
A filter is linear when the output pixel value is a weighted sum of its neighbors.

The most common linear filters are:

Mean Filter

Averaging Filter

Weighted Averaging Filter

➕ Smoothing Spatial Filters (Linear)


🧹 Purpose:
To blur the image

To remove noise

Makes the image look smoother

🔹 Mean Filter (Averaging Filter)


Replaces each pixel with the average of its surrounding pixels

Useful for reducing random noise, but it also blurs edges

Example: 3×3 mean filter:

csharp

[1 1 1
1 1 1
1 1 1] / 9

Each pixel is replaced with the average of its 8 neighbors and itself.

🔸 Weighted Averaging Filter


Like the mean filter, but gives more importance to the center pixel and less to the surrounding
ones.

Example:

34/37
csharp

[1 2 1
2 4 2
1 2 1] / 16

Better than the simple average because it preserves the image structure slightly better.

🔶 2. NON-LINEAR SPATIAL FILTERS


📌 What is a Non-Linear Filter?
A non-linear filter does not use a weighted sum. Instead, it uses sorting, ranking, or decision
rules.

They are good at removing specific types of noise like salt-and-pepper noise without blurring the
edges.

📘 Order-Statistic Filters (Non-linear)


These filters work by ordering (sorting) the pixel values in the neighborhood.

🔹 Median Filter
Replaces the center pixel with the median value of the neighborhood.

Very effective for removing salt-and-pepper noise (black and white dots).

Preserves edges better than mean filter.

Example: Values = [12, 14, 255, 13, 10, 11, 13, 14, 15] → Sorted = [10, 11, 12, 13, 13, 14, 14, 15, 255]
→ Median = 13

🔸 Minimum Filter
35/37
Replaces the pixel with the minimum value in the neighborhood.

Removes bright noise (like white spots).

🔸 Maximum Filter
Replaces the pixel with the maximum value in the neighborhood.

Removes dark noise (like black spots).

⚡ Sharpening Spatial Filters


📌 Purpose:
Highlight edges, lines, corners, and fine details

Opposite of smoothing

Used to make blurry images crisper

🔹 High-Pass Filtering
Passes high-frequency content (edges) and blocks low-frequency (smooth regions)

🔹 Laplacian Filter (Linear Sharpening Filter)


Uses the second derivative to detect areas where intensity changes quickly

Example Laplacian Kernel:

ini

[ 0 -1 0
-1 4 -1
0 -1 0 ]

It detects edges in all directions.

36/37
🔹 Unsharp Masking
A blurred version of the image is subtracted from the original to sharpen it.

Sharpened Image = Original Image − Blurred Image

Then sometimes this difference is added back:

Final = Original + α(Original − Blurred)

🧾 Summary Table
Type Filter Name Purpose Effect

Linear Mean / Average Noise reduction Blurs edges

Weighted Average Better smoothing Less blurring

Non-Linear Median Filter Remove salt & pepper noise Preserves edges

Min / Max Filter Remove light/dark noise Distorts image if overused

Sharpening Laplacian Edge detection Enhances edges

Unsharp Masking Detail enhancement Sharpens without edge loss

🧠 Real-life Uses
Mean filter: General smoothing

Median filter: Medical images, CCTV noise removal

Laplacian: Object edge detection

Unsharp masking: Photo editing apps

Would you like visual diagrams or Python code examples to see how each filter works practically?

37/37

You might also like