KEMBAR78
Dip CCP Report | PDF | Image Processing | Telecommunications Engineering
0% found this document useful (0 votes)
3 views15 pages

Dip CCP Report

Uploaded by

officialaneesboy
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)
3 views15 pages

Dip CCP Report

Uploaded by

officialaneesboy
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/ 15

Smart City Surveillance System: Enhancing Image Quality and Object

Recognition for Real-Time Monitoring

Maryam Asad, Abdul Ahad Iqbal, Zara, Muhammad Anees Akram Sindhu
Department of Computer Science, University of Management and Technology Lahore, 54770 Pakistan

Abstract

Smart city surveillance systems face critical challenges such as poor image quality caused by noise, motion
blur, and varying lighting conditions, which hinder reliable real-time monitoring and object recognition.
This project addresses these issues using classical digital image processing techniques without relying
on artificial intelligence, ensuring predictable and resource-efficient performance suitable for hardware-
constrained environments. The methodology incorporates several key stages: filtering, employing median
and Gaussian filters to reduce noise while preserving important image features; restoration, using Wiener
filtering and deblurring algorithms to recover images degraded by motion blur and environmental factors;
segmentation, utilizing edge detection methods like the Canny operator and region-based approaches such
as Watershed to isolate objects of interest; and object recognition, based on feature extraction of shape,
texture, and color for accurate identification. Results demonstrate significant improvements in image
clarity, noise reduction, and segmentation accuracy, enabling robust object detection under challenging
urban conditions. The optimized, lightweight algorithms balance computational demands and processing
speed, making the system viable for real-time deployment in surveillance networks. Enhanced image
quality and reliable object recognition facilitate timely and accurate situational awareness, crucial for
public safety and urban management.This approach’s practical implications include improved surveillance
efficacy, better resource utilization, and scalability in dynamic city environments, all while maintaining
transparency and avoiding ethical concerns associated with AI-based methods.
keywords: Smart City Surveillance, Digital Image Processing, Noise Reduction, Image Restoration,
Segmentation, Object Recognition, Real-Time Monitoring.

1. Introduction tems in busy, ever-changing urban environments.

Cities today are changing fast due to growing pop-


ulations and advances in technology. The idea of 2. Background: The Role of Image Process-
a smart city focuses on using modern tools and ing in Smart City Surveillance Systems
systems to make urban life safer, more efficient,
In the modern era, urban centers are rapidly evolv-
and environmentally friendly. Among these tools,
ing into smart cities—highly connected, technology-
surveillance systems are key—they help keep an
driven environments designed to enhance the qual-
eye on public areas to protect people and support
ity of life, safety, and sustainability of their inhabi-
better management of city resources.These surveil-
tants. A critical component of this transformation
lance networks produce huge amounts of video and
is the deployment of extensive surveillance systems
image data from cameras placed all over the city.
throughout public spaces such as streets, parks,
But the raw footage they capture often suffers from
transit stations, and commercial areas. These sys-
problems like poor quality, noise, or distortion,
tems aim to monitor urban activity continuously,
which makes it hard to analyze and use effectively.
assisting law enforcement, city planners, traffic man-
To overcome these issues, digital image process-
agers, and emergency responders in maintaining
ing methods are applied to improve the clarity of
order and safety.
images, identify important details, and allow for
quick, real-time monitoring. In this section, we’ll At the heart of these surveillance systems lies the
explore how digital image processing plays a vital vast amount of visual data collected by thousands
role in smart city surveillance and discuss the main of cameras. However, raw footage captured by
challenges encountered when deploying these sys- surveillance cameras is often suboptimal for direct
use due to a variety of factors, including environ- capture clear images, leading to graininess
mental noise, low image resolution, motion blur, and pixelation.
and fluctuating lighting conditions. This is where
• Weather conditions: Rain, fog, snow, and
Digital Image Processing (DIP) becomes essential.
dust particles scatter light and obscure cam-
Digital image processing refers to the set of com- era lenses, resulting in blurred or hazy im-
putational techniques used to enhance, analyze, ages.
and interpret images digitally. In the context of
• Sensor noise: Imperfections in camera sen-
smart city surveillance, DIP transforms raw cam-
sors, especially low-cost models, introduce
era data into clearer, more reliable images that fa-
noise even in optimal lighting.
cilitate the detection and recognition of objects of
interest—such as pedestrians, vehicles, or unusual Noise complicates the task of detecting and iden-
events. These enhanced images enable automated tifying objects because it can mask important fea-
or assisted decision-making processes, improving tures like edges, textures, and colors. Consequently,
response times and accuracy in critical situations. noise reduction through filtering is a critical pre-
processing step in digital image processing pipelines.
For example, image processing can reduce noise
caused by poor lighting or adverse weather, cor-
3.2. Low Resolution and Image Quality Limita-
rect blurring caused by camera movement or fast
tions
motion, and segment complex scenes into distinct
objects, making it easier to track movements or Surveillance cameras, especially in large-scale de-
identify suspicious activities. These enhancements ployments, often use low-resolution sensors to min-
are vital for the surveillance system’s ability to per- imize data storage and transmission bandwidth.
form real-time monitoring and alert relevant au- While this approach reduces costs, it significantly
thorities promptly. compromises the detail and clarity of images.

Unlike artificial intelligence-based approaches that Low-resolution images lack the fine-grained infor-
require large datasets and extensive computing mation necessary to distinguish closely spaced ob-
power, classical digital image processing techniques jects, identify faces, or read vehicle license plates.
employ deterministic algorithms—such as filtering, Upscaling or super-resolution techniques can par-
restoration, segmentation, and feature extraction tially mitigate this issue but often introduce ar-
that are mathematically precise and computation- tifacts or inaccuracies, especially in real-time set-
ally efficient. These methods ensure the system tings.
remains reliable, transparent, and manageable, es- Balancing the need for high-resolution images with
pecially when deployed on hardware with limited practical constraints such as bandwidth, storage
resources. capacity, and computational power is a constant
In sum, digital image processing is the backbone of challenge in smart city surveillance.
modern smart city surveillance, enabling the con-
version of imperfect raw visual data into actionable 3.3. Real-Time Processing Constraints
intelligence that keeps cities safer and better man- A defining feature of smart city surveillance is real-
aged. time monitoring—the ability to process and an-
alyze image data instantly or within a few sec-
onds. Rapid processing allows authorities to re-
3. Challenges in Digital Image Processing
spond promptly to incidents, potentially prevent-
for Smart City Surveillance
ing accidents or crimes.
Despite its importance, applying digital image pro- However, many digital image processing algorithms,
cessing in smart city surveillance faces several sig- especially those involving complex restoration or
nificant challenges that affect the accuracy, speed, segmentation tasks, are computationally intensive.
and reliability of the system. Performing these operations on high-resolution im-
ages at video frame rates requires substantial pro-
3.1. Noise and Environmental Distortions cessing power and optimized algorithms.
One of the most pervasive challenges is noise in the
Moreover, surveillance systems often rely on resource-
captured images. Noise refers to unwanted random
constrained hardware such as embedded processors
variations in pixel intensity that degrade the image
or edge devices that do not support heavy com-
quality. It can originate from various sources:
putations. This limitation forces designers to op-
• Low light conditions: During nighttime timize algorithms to maintain a balance between
or poorly lit areas, cameras often struggle to image quality and processing speed.
2
4. Conflicting Requirements: 5. Objectives

The implementation of digital image processing in The main goals of this project focus on enhancing
smart city surveillance frequently involves balanc- the effectiveness of smart city surveillance systems
ing conflicting requirements: through advanced digital image processing tech-
niques. Specifically, the objectives include:
• High image quality vs. computational
load: Enhancing image quality using advanced 1. Improving Image Quality
filters and restoration techniques improves Enhance the clarity and usability of surveil-
detection accuracy but increases processing lance images by reducing noise and correct-
time and energy consumption. ing distortions, ensuring that the footage is
reliable even under difficult conditions like
• Data fidelity vs. storage/transmission
low light and environmental interference.
efficiency: Capturing and storing high-quality
images consumes significant bandwidth and 2. Frequency Domain Filtering
storage space. Compression algorithms re- Utilize Fourier transform-based methods to
duce size but may discard important details analyze and remove periodic noise from surveil-
needed for analysis. lance footage. This involves designing and
applying frequency-domain filters such as Gaus-
• Complexity vs. transparency: Complex sian low-pass and Butterworth filters, which
image processing algorithms may yield better are critical not only for noise reduction but
results but can be harder to debug, maintain, also for improving image restoration and com-
and explain to stakeholders, especially when pression outcomes.
transparency and reliability are essential. 3. Image Restoration and Reconstruction
• Robustness vs. adaptability: Systems Apply restoration techniques like Wiener fil-
must perform consistently in varying envi- tering and deblurring algorithms to recover
ronmental conditions yet remain adaptable corrupted or degraded images. This process
to dynamic changes in lighting, weather, or addresses real-world challenges such as mo-
urban activity. tion blur and environmental degradation, en-
suring the images are suitable for further anal-
Designing a surveillance system that satisfactorily ysis.
addresses these conflicting demands requires care- 4. Image Segmentation
ful algorithm selection, hardware considerations, Evaluate and implement edge-based meth-
and system architecture design. ods (e.g., Canny edge detection) and region-
based techniques (e.g., watershed segmenta-
4.0.1. Dynamic and Complex Urban Environments tion) to isolate objects of interest within im-
Smart cities are bustling with activity—pedestrians, ages. Effective segmentation depends heav-
vehicles, animals, shadows, reflections, and other ily on prior filtering and restoration, enabling
moving objects create complex visual scenes. The accurate identification and tracking of pedes-
variability and unpredictability of these environ- trians, vehicles, and other elements.
ments pose additional difficulties: 5. Image Compression
• Changing lighting: Daylight, artificial street Analyze different compression algorithms (such
lights, shadows, and weather changes alter as JPEG and wavelet-based methods) to bal-
image brightness and contrast throughout the ance storage and transmission efficiency with
day. the preservation of image quality necessary
for accurate recognition. Compression choices
• Motion blur: Fast-moving objects or cam- directly affect how much data can be stored
era vibrations cause blurring, obscuring de- and sent, and influence the performance of
tails. downstream tasks.
• Occlusions: Objects partially blocking each 6. Accurate Object Recognition
other complicate segmentation and recogni- Although optional, this objective focuses on
tion. enabling precise detection and classification
of objects in surveillance images. Recogni-
These factors necessitate adaptive and robust im-
tion depends on the quality of previous pro-
age processing techniques that can dynamically ad-
cessing stages—filtering, restoration, and seg-
just to changing conditions while maintaining per-
mentation—to deliver reliable real-time mon-
formance.
itoring results.

3
7. Achieving Real-Time Performance ity, extract meaningful information, and support
Design the overall system to process and an- reliable object recognition in real-time environments.
alyze image data quickly and efficiently, sup-
porting immediate decision-making and re-
7. Original Images
sponse. This requires balancing computa-
tional demands with hardware limitations,
ensuring the system can operate effectively
in real-world urban environments.

6. Technology

This section outlines the core technologies used in


the image processing pipeline for smart city surveil-
lance. Each stage is carefully selected to ensure op-
timal performance in terms of image clarity, accu-
racy, and real-time responsiveness. In the spatial
filtering stage, techniques such as the mean filter,
median filter, and Laplacian filter are implemented
using tools like OpenCV and MATLAB, and their
performance is measured using SSIM and PSNR. Figure 1: Original traffic surveillance images in real
city environments.
For frequency domain filtering, methods like
Fourier transform, Gaussian low-pass filter, and
Butterworth filter are applied with MATLAB and 8. Spatial Filtering
Python’s scikit-image, evaluated through PSNR
and visual spectral analysis. filtering is a technique used in image processing to
enhance or modify images by applying a filter (or
During image restoration and reconstruction, kernel) directly on the pixels of the image. It works
Wiener filtering and motion deblurring algorithms in the spatial domain, meaning it operates on the
are used to recover corrupted images, utilizing pixels’ locations (x, y) instead of frequency values.
OpenCV and MATLAB, with results assessed via
SSIM and Mean Squared Error (MSE). 8.1. Why Spatial Filtering is Used
The image segmentation process includes • To reduce noise (unwanted variations in
Canny edge detection, watershed algorithm, thresh- brightness or color).
olding, and region growing, primarily executed us-
ing OpenCV, and evaluated using the Dice coeffi- • To smooth or blur images (remove de-
cient and Intersection over Union (IoU). tails).
For image compression, both JPEG compres- • To sharpen images (highlight edges and
sion and wavelet-based (DWT) techniques are ap- fine details).
plied using OpenCV and PyWavelets, with per- • To detect edges and features in objects
formance judged based on compression ratio and (important for tasks like object recognition
image fidelity. and segmentation).
In the object recognition stage (optional), tech-
nologies like feature extraction, YOLO (You Only • 8.2. Types of Spatial Filters
Look Once), and Support Vector Machine (SVM) 8.2.1. 1. Linear Filters
are implemented using OpenCV, TensorFlow, or These filters use a mathematical averaging or
PyTorch, and evaluated through metrics such as weighted sum.
precision, recall, and F1-score
– Mean Filter: Replaces each pixel with
the average of its neighbors. Good for
CODE IMPLEMENTATION removing Gaussian noise.
we aim to implement a complete digital image pro- – Laplacian Filter: Detects edges by
cessing pipeline for smart city surveillance by ap- calculating the second derivative. High-
plying a series of enhancement and analysis tech- lights areas where intensity changes quickly.
niques to original, real-world images. These tech-
niques are carefully selected to improve visual qual-
4
8.2.2. 2. Non-Linear Filters 9.2. Median Filter
These filters use non-linear operations like
Algorithm 2 Median Filter for Noise Removal
finding the median.
1: for each pixel (i, j) in the image do
Median Filter: Replaces each pixel with 2: Extract a 3 × 3 neighborhood around (i, j)
the median value of its neighbors. Very 3: Sort pixel values {P1 , P2 , ..., P9 }
effective for salt-and-pepper noise. 4: Compute:
Output Images
Median(i, j) = Median {P1 , P2 , ..., P9 }

5: Replace pixel (i, j) with the median value


6: end for

9.3. Laplacian Filter

Algorithm 3 Laplacian Filter for Edge Detection


1: Define kernel:
 
0 −1 0
−1 4 −1
0 −1 0

2: for each pixel (i, j) do


3: Apply convolution:
X
L(i, j) = Kernel · Neighborhood(i, j)

4: Subtract result from original:

Sharpened(i, j) = Original(i, j) − L(i, j)

5: end for

9. Algorithms and Performance Metrics 9.4. PSNR Calculation


9.1. Mean Filter Algorithm 4 Peak Signal-to-Noise Ratio (PSNR)
Algorithm 1 Mean Filter for Image Smoothing 1: Compute MSE:
1: for each pixel (i, j) in the image do m n
Extract a 3 × 3 neighborhood around (i, j) 1 XX 2
2: M SE = I(i, j) − K(i, j)
3: Compute the mean: mn i=1 j=1

N 2: Compute PSNR:
1 X
Mean(i, j) = Pk
N !
k=1 M AX 2
P SN R = 10 · log10
4: Replace pixel (i, j) with the mean value M SE
5: end for
3: Where M AX = 255 for 8-bit images

5
9.5. SSIM Calculation Laplacian Sharpening
% Apply Laplacian filter to detect edges
Algorithm 5 Structural Similarity Index (SSIM)
lap = fspecial(’laplacian’, 0.2);
1: Compute means: % Apply Laplacian filter to original
grayscale image
µx = mean(x), µy = mean(y) sharp = imfilter(gray, lap, ’replicate’);
% Subtract the Laplacian result from original
2: Compute variances and covariance:
to enhance edges (high-boost filtering)
σx2 = var(x), σy2 = var(y), σxy = cov(x, y) sharpened = imsubtract(im2double(gray),
im2double(sharp));
3: Compute SSIM: % Output: sharpened image with enhanced
edges but noise may be amplified
(2µx µy + C1 )(2σxy + C2 )
SSIM(x, y) =
(µ2x + µ2y + C1 )(σx2 + σy2 + C2 )
Trade-offs in Code Implementation

Aspect Mean Filter Median Filter Laplacian Sharpening

Filter Type Noise Type PSNR (dB) SSIM Visual Impact


Noise Removal Works well for Gaussian Excellent for salt & pepper Does not remove noise; can
noise; smoothes uniformly noise; preserves edges amplify noise
Mean Filter Gaussian 27.42 0.78 Smooths image, but blurs
edges slightly

Edge Preservation Poor — edges are blurred Good — preserves edges by Enhances edges; edges be-
due to averaging selecting median come sharper
Median Filter Salt & Pepper 30.65 0.85 Removes noise effectively,
preserves edges

Computational Cost Low — convolution with Medium — sorting in each Low — linear filtering
small kernel window
Laplacian Filter No noise (sharpen) – – Sharpens edges, increases de-
tail

Implementation Complexity Simple with built-in convo- Slightly more complex (me- Simple convolution and
lution dian sorting) subtraction
Table 1: Performance Evaluation of Spatial Filters

Effect on Details Blurs details along with Preserves fine details Enhances details but sensi-
noise tive to noise

10. Annotated Pseudocode for Each Filter


Usage Scenario When noise is Gaussian and When impulse noise (salt & When sharpening details
Mean Filter (Average Filter) smooth output is desired pepper) is present is important, and noise is
minimal or handled sepa-
rately
% Apply mean filter to smooth image and
reduce Gaussian noise
Table 2: Discussion of Trade-offs in Code Implemen-
% Input: noisy image (noisy gauss)
tation
% Kernel: 3x3 averaging filter
mean kernel = fspecial(’average’, 3);
% Create averaging filter 11. Frequency Domain Filtering
mean filtered = imfilter(noisy gauss,
mean kernel); Frequency domain filtering involves modifying the
% Output: mean filtered image with reduced frequency components of an image rather than di-
noise but blurred edges rectly manipulating pixel values. The image is first
transformed using the Fourier Transform, filtering
is applied, and then the image is transformed back
Median Filter using the Inverse Fourier Transform.
% Apply median filter to remove salt &
pepper noise 11.1. Why Frequency Filtering is Used
% Input: noisy image (noisy sp) • To remove periodic noise from images ef-
% Window size: 3x3 fectively.
median filtered = medfilt2(noisy sp
, [3 3]); • To enhance certain patterns or textures
% Output: median filtered image with salt that repeat regularly.
& pepper noise removed, edges preserved • To implement filters like low-pass, high-
pass, and band-pass more effectively than
in spatial domain.

6
• To gain control over the frequency com- Algorithm 6 General Frequency Domain Filter-
ponents, especially when spatial filters pro- ing
duce poor results. 1: Input: Image I(x, y), Filter H(u, v)
2: Compute FFT: F (u, v) = F[I(x, y)]
11.2. Types of Frequency Domain Filters 3: Multiply: G(u, v) = H(u, v) · F (u, v)
11.2.1. 1. Low-Pass Filters 4: Inverse FFT: g(x, y) = F −1 [G(u, v)]
These filters allow low-frequency components to 5: Output: Filtered Image g(x, y)
pass and block high frequencies.
• Ideal LPF: Sharp cutoff, passes frequencies
12. Algorithms and Performance Metrics
inside a circle of radius D0 .
• Gaussian LPF: Smooth transition, suppresses 12.1. Frequency Domain Filtering
high-frequency noise gently. 12.2. PSNR and SSIM Evaluation
Same PSNR and SSIM algorithms as used in spa-
11.2.2. 2. High-Pass Filters tial filtering (refer back to Spatial Filtering sec-
These filters block low frequencies and enhance tion).
high frequencies, often used for edge detection and
sharpening. Filter Type Noise Type PSNR (dB) SSIM Visual Impact

• Ideal HPF: Sharp cutoff, enhances edges.


Gaussian LPF Gaussian Noise 28.13 0.81 Reduces high-frequency noise,
smooth appearance

Ideal HPF Noisy Edges 26.75 0.76 Enhances edges sharply, but may
• Gaussian HPF: Enhances fine details introduce ringing

smoothly. Notch Filter Periodic Noise 29.94 0.84 Removes periodic artifacts like
stripes or patterns

11.2.3. 3. Band-Pass and Band-Reject Fil- Table 3: Performance Evaluation of Frequency Filters
ters
• Band-Pass: Allows a specific range of fre-
quencies. Annotated Pseudocode for Frequency Fil-
ters
• Band-Reject (Notch): Blocks a narrow
range of frequencies (useful for removing pe- Gaussian Low-Pass Filter
riodic noise). % Apply Gaussian LPF in frequency domain
Output Image F = fft2(image);
Fshift = fftshift(F);
H = fspecial(’gaussian’, size(F), 30);
Filtered = Fshift .* H;
Result = real(ifft2(ifftshift(Filtered)));
% Output: Blurred image with
reduced high-frequency noise

Ideal High-Pass Filter


% Create Ideal HPF mask
H = ones(size(F));
center = size(F) / 2;
for i=1:size(F,1)
for j=1:size(F,2)
D = sqrt((i-center(1))^2 + (j-center(2))^2);
if D < D0, H(i,j) = 0; end
end
end
Filtered = Fshift .* H;
Result = real(ifft2(ifftshift(Filtered)));
% Output: Sharpened image
Figure 2: Frequency Domain Filtered Output

7
Notch Filter for Periodic Noise 13.2.2. 2. Lucy-Richardson Deblurring
% Identify and suppress periodic noise An iterative deconvolution algorithm used for re-
H = ones(size(F)); moving motion blur or out-of-focus blur, based on
% Manually zero-out notch regions around a maximum likelihood estimation approach.
noise frequencies Output Images
H(center(1)+30, center(2)-20) = 0;
H(center(1)-30, center(2)+20) = 0;
Filtered = Fshift .* H;
Result = real(ifft2(ifftshift(Filtered)));
% Output: Image without periodic noise

Trade-offs in Code Implementation

Aspect Low-Pass Filter High-Pass Filter Notch Filter

Noise Removal Good for high-frequency Not suitable for random Excellent for periodic
noise noise noise

Edge Preservation Poor (edges are Good (edges enhanced) Depends on notch place-
smoothed) ment

Computational Cost Medium — requires Medium — FFT + filter- High — requires precise
FFT/IFFT ing frequency notch design

Implementation Complexity Moderate — Gaussian Slightly higher (HPF High — requires manual
masks easy to generate mask design) frequency analysis

Effect on Details Blurs fine details Enhances fine details, may Preserves details while re-
amplify noise moving specific artifacts

Usage Scenario Denoising and smoothing Edge enhancement Removing periodic arti-
facts (e.g., stripes, grids) Figure 3: image restoration using wiener
filtering,Lucy-Richardson
Table 4: Trade-offs in Frequency Domain Filters

14. Algorithms and Performance Metrics


13. Image Restoration and Reconstruction
14.1. Wiener Filtering
Image restoration aims to recover an original image
that has been degraded due to noise, motion blur, Algorithm 7 Wiener Filter for Image Restoration
or environmental distortions. It focuses on revers- 1: Input degraded image and degradation func-
ing the corruption using mathematical models and tion (PSF)
filters to reconstruct image fidelity. 2: Estimate noise-to-signal power ratio
3: Compute Wiener filter in frequency domain:
13.1. Why Image Restoration is Used
H∗
• To recover lost details from blurred or Hw =
|H|2 + K
noisy images caused by imperfect acquisition.
where H is the degradation function, H ∗ its
• To enhance visual clarity for human in- conjugate, and K noise-to-signal ratio
terpretation or automated systems. 4: Apply filter to degraded image to estimate re-
• To support subsequent stages such as stored image
segmentation and object detection with bet- 5: Output restored image
ter input data.
• To compensate for real-world distor-
tions such as camera motion, defocus, or at-
mospheric turbulence.

13.2. Types of Image Restoration Techniques


13.2.1. 1. Wiener Filtering
A statistical restoration method that minimizes
the mean square error between the estimated and
true images. It assumes knowledge of the degrada-
tion function and noise statistics.

8
14.2. Lucy-Richardson Deblurring % Apply Wiener filter to degraded image
% Output: restored image with reduced noise
Algorithm 8 Lucy-Richardson Algorithm for De- and blur
blurring
1: Initialize restored image estimate (usually uni-
form or degraded image) Lucy-Richardson Deblurring
2: for each iteration do % Input: degraded image and PSF
3: Convolve current estimate with PSF % Initialize restored image estimate
4: Compute ratio of degraded image to this % Repeat for a fixed number of iterations:
convolution - Convolve estimate with PSF
5: Convolve ratio with flipped PSF - Calculate ratio of degraded image to
6: Update estimate by multiplying previous convolution result
estimate with result of convolution - Convolve ratio with flipped PSF
7: end for - Update estimate by multiplication
8: Output restored image estimate after itera- % Output: restored image with enhanced
tions sharpness but possible noise amplification

14.3. PSNR and SSIM Calculation Trade-offs in Code Implementation


Algorithm 9 Quality Metrics for Restoration
1: Compute Mean Squared Error (MSE) between Aspect Wiener Filter Lucy-Richardson Deblur-
restored and original images ring

m n
1 XX 2
M SE = I(i, j) − R(i, j) Noise Handling Good at reducing Gaussian
noise; smooths image
Can amplify noise if iterations
are excessive
mn i=1 j=1

2: Calculate PSNR: Blur Removal Moderate removal of blur, best


for mild degradation
Strong removal of motion blur;
iterative improvement
!
M AX 2
P SN R = 10 · log10
M SE Computational Cost Low — single filtering operation
in frequency domain
Higher — multiple iterative con-
volutions

where M AX is the maximum pixel value (255


Implementation Complexity Straightforward with frequency More complex due to iterative
for 8-bit images) domain filtering updates and convergence control

3: Compute SSIM index using luminance, con-


trast, and structure comparisons
Effect on Details May smooth edges and details Enhances edges and details but
along with noise sensitive to noise

Usage Scenario Suitable when noise and blur Best for images with motion blur
statistics are known and known PSF
Method PSNR (dB) SSIM Visual Impact

Wiener Filter 28.56 0.82 Reduces noise and blur moder- Table 6: Trade-offs in Image Restoration Techniques
ately; slight smoothing effect

Lucy-Richardson 30.12 0.85 Effectively removes motion blur; 16. Image Segmentation
may amplify noise if iterations
are too many
Image segmentation is a fundamental step in com-
puter vision and image analysis. It involves par-
Table 5: Performance Evaluation of Restoration
titioning an image into meaningful regions to iso-
Techniques
late objects or features. This process enables tasks
such as object recognition, tracking, and classifica-
15. Annotated Pseudocode for Each Method tion by distinguishing distinct components in the
image.
Wiener Filtering
% Input: degraded image and estimated PSF 16.1. Why Image Segmentation is Used
% Estimate noise-to-signal power ratio • To isolate objects or regions of interest
% Compute Wiener filter in frequency domain within an image for further analysis.
9
• To assist in recognition and classifica- 17. Algorithms and Performance Metrics
tion tasks by separating meaningful struc-
tures. 17.1. Canny Edge Detection

• To enhance medical images for identify- Algorithm 10 Canny Edge Detection Algorithm
ing anatomical structures or abnormalities. 1: Apply Gaussian blur to smooth the image
• To prepare data for machine learning 2: Compute image gradient (intensity change)
models by labeling pixels based on classes. 3: Perform non-maximum suppression to thin
edges
16.2. Types of Image Segmentation 4: Apply double threshold to identify strong and
weak edges
16.2.1. 1. Edge-Based Segmentation
5: Track edge connections via hysteresis
This approach detects object boundaries by iden-
tifying abrupt changes in pixel intensity.
• Canny Edge Detector: A multi-stage al- 17.2. Otsu Thresholding
gorithm that uses gradient calculation, non-
maximum suppression, and hysteresis thresh- Algorithm 11 Otsu’s Method for Global Thresh-
olding to extract precise edges. olding
1: Compute histogram of grayscale image
16.2.2. 2. Region-Based Segmentation 2: for each possible threshold t do
This method groups pixels with similar character- 3: Compute intra-class variance for back-
istics. ground and foreground
4: end for
• Otsu Thresholding: Separates the image
5: Select threshold t∗ that minimizes intra-class
into foreground and background by maximiz-
variance
ing inter-class variance.
6: Binarize image using t∗
• Watershed Algorithm: Views the grayscale
image as a topographic surface and finds the
“watershed lines” that separate distinct re- 17.3. Watershed Segmentation
gions.
Algorithm 12 Watershed Segmentation for Re-
Output Images gion Separation
1: Binarize image using Otsu threshold
2: Compute distance transform of binary image
3: Invert distance map to simulate basins
4: Create markers via extended minima trans-
form
5: Impose minima and apply watershed algorithm

17.4. Evaluation Metrics

Algorithm 13 IoU and Dice Coefficient Calcula-


tion
1: Let GT be ground truth, P be prediction
2: Compute Intersection over Union (IoU):

Figure 4: Comparison of Segmentation Methods: |GT ∩ P |


Canny, Otsu, and Watershed IoU =
|GT ∪ P |

3: Compute Dice Coefficient:

2|GT ∩ P |
Dice =
|GT | + |P |

10
Segmentation Method Technique Type IoU Dice Remarks
Trade-offs in Code Implementation

Canny Edge Detection Edge-based 0.68 0.80 Captures sharp boundaries;


may miss region interiors Aspect Canny Edge Detection Otsu Thresholding Watershed Segmenta-
tion

Otsu Thresholding Region-based 0.73 0.84 Effective for bimodal his-


tograms; fails with poor con-
Accuracy High for edges; poor on in- Good for global threshold- Excellent for separating
trast
teriors ing connected regions

Watershed Segmentation Region-based 0.81 0.89 Best for separating connected


regions; sensitive to noise Noise Sensitivity High — edges can be frag- Moderate — affected by High — oversegmentation
mented lighting without pre-processing

Table 7: Performance Evaluation of Image Segmen- Computational Cost Low — gradient and Very low — simple his- Moderate — uses distance
tation Techniques thresholding togram analysis maps and minima imposi-
tion

Implementation Complexity Simple (built-in function) Very simple Complex (requires multiple
18. Annotated Pseudocode for Each Method steps)

Canny Edge Detection Usage Scenario Highlighting contours in Foreground-background Detailed object isolation in
structured images segmentation clustered regions

% Detect edges using Canny method


canny edges = edge(gray img, ’Canny’); Table 8: Trade-offs in Code Implementation for Seg-
% Output: Binary edge map highlighting mentation Techniques
object boundaries

19. Image Compression


Otsu Thresholding
% Compute global threshold using Image compression is a process used to reduce the
Otsu’s method size of image files while retaining as much visual
level = graythresh(gray img); information as possible. It plays a crucial role in
bw thresh = imbinarize(gray img, level); minimizing storage space and transmission time,
% Output: Binary image separating and can directly influence downstream tasks like
foreground and background image recognition.

19.1. Why Image Compression is Used


Watershed Segmentation • To reduce file size for efficient storage and
% Distance transform of thresholded image transmission.
D = -bwdist(~bw thresh);
• To speed up data transfer over networks,
mask = imextendedmin(D, 2);
especially in real-time systems.
D2 = imimposemin(D, mask);
L = watershed(D2); • To optimize memory usage in embedded
watershed seg = bw thresh; or resource-constrained systems.
watershed seg(L == 0) = 0;
• To balance between perceptual quality
% Output: Segmented image separating
and compression ratio.
regions by watershed lines
• To evaluate impact on recognition sys-
tems post-compression.

19.2. Types of Image Compression Techniques


19.2.1. 1. JPEG Compression
JPEG (Joint Photographic Experts Group) uses
Discrete Cosine Transform (DCT), quantization,
and entropy coding to compress images efficiently.
It is widely used for photographic images.
• Lossy compression: Discards some infor-
mation to reduce size.
• Quality factor: Controls the trade-off be-
tween file size and image quality.

11
19.2.2. 2. Wavelet Compression 20.3. Compression Ratio
Wavelet compression uses multi-resolution analy-
sis to represent images. It preserves better visual Algorithm 16 Compression Ratio Calculation
quality at higher compression ratios. 1: Compute:
• Transforms image using Haar or other wavelets. Original Size
Compression Ratio =
• High-frequency components (detail) can Compressed Size
be selectively discarded.
2: Higher value indicates better compression
Output Images

20.4. Recognition Accuracy (Post-Compression)

Algorithm 17 Effect on Recognition Accuracy


1: Pass original and compressed images into
recognition system
2: Measure prediction accuracy for both

Accuracy Drop = Accuracyoriginal −Accuracycompressed

Compression Type Ratio SSIM Accuracy Drop Visual Impact

Figure 5: Original, JPEG Compressed, and Wavelet


Compressed Images JPEG (Quality = 5) 12.5:1 0.65 6.2% Noticeable block artifacts and
blurring

Wavelet (Haar Level 2) 10.8:1 0.72 3.8% Smoother loss of detail, fewer
20. Algorithms and Performance Metrics artifacts

20.1. JPEG Compression Table 9: Performance Evaluation of Image Compres-


sion Techniques
Algorithm 14 JPEG Compression
1: Input image I
2: Convert to YCbCr color space (optional) 21. Annotated Pseudocode for Each Com-
3: Divide into 8 × 8 blocks pression Technique
4: for each block do
JPEG Compression
5: Apply 2D DCT
6: Quantize DCT coefficients using quantiza- % Compress image using JPEG with low quality
tion table img = Image.open(’1.jpg’);
7: Entropy encode using Huffman coding img.save(’compressed 10.jpg’, ’JPEG’, quality=5);
8: end for img jpeg = Image.open(’compressed 10.jpg’);
9: Save compressed bitstream to file % Output: JPEG-compressed image with reduced
size, some quality loss

20.2. Wavelet Compression


Wavelet Compression
Algorithm 15 Wavelet-Based Compression % Convert to grayscale and apply 2-level Haar
1: Input grayscale image I wavelet
2: Apply wavelet transform (e.g., Haar) to obtain img gray = img.convert(’L’);
coefficients img np = np.array(img gray);
3: Zero out high-frequency detail coefficients
coeffs = pywt.wavedec2(img np, ’haar’, level=2);
4: Reconstruct image using inverse wavelet trans-
coeffs compressed = [coeffs[0]] + [(np.zeros like(cH),
form np.zeros like(cV), np.zeros like(cD))
5: Clip and convert to valid pixel range
for (cH, cV, cD) in coeffs[1:]];
img wavelet = pywt.waverec2(coeffs compressed,
’haar’);
img wavelet = np.clip(img wavelet, 0, 255)

12
.astype(np.uint8); • To understand the impact of preprocess-
Image.fromarray(img wavelet) ing steps on recognition accuracy.
.save(’wavelet compressed.jpg’);
% Output: image compressed using wavelets 22.2. Types of Object Recognition Models
22.2.1. 1. Pre-trained Models
• YOLO (You Only Look Once): Real-
Trade-offs in Code Implementation time object detection model known for speed
and decent accuracy.
• Faster R-CNN: Region-based Convolutional
Aspect JPEG Compression Wavelet Compression Neural Network with high accuracy but slower
inference.
Compression Ratio High compression with ad- Moderate compression;
justable quality more scalable with levels
22.2.2. 2. Custom-Trained Models
Models trained on domain-specific datasets, opti-
mized for particular object categories or environ-
Visual Quality Can introduce blocking ar-
tifacts
Preserves smooth transi-
tions better
ments.
Output Images
Noise Robustness Sensitive to noise; blocks Better at suppressing noise
may distort in high-frequency regions

Computation Cost Low to medium; hardware- Medium to high; computa-


supported tionally intensive

Recognition Accuracy Impact Higher degradation at low Lower impact due to


quality levels smoother degradation

Best Use Case Photography, web images Medical imaging, scalable


coding

Table 10: Discussion of Trade-offs in Compression Figure 6: Object Recognition Images of vehicles
Techniques

23. Algorithms and Performance Metrics


22. Object Recognition 23.1. YOLO Object Detection Algorithm
Object recognition is a critical task in computer Algorithm 18 YOLO Object Detection
vision that involves identifying and classifying ob-
1: Load input image
jects within an image or video. It leverages ma-
2: Preprocess image for model input
chine learning and deep learning models to detect
3: Load pre-trained YOLO model
and label objects accurately. The performance of
4: Run the model to predict bounding boxes and
object recognition depends heavily on preceding
class probabilities
tasks such as filtering, image restoration, and seg-
5: Filter predictions for target object classes (e.g.,
mentation, which prepare the image for robust fea-
vehicles)
ture extraction and classification.
6: for each detected object do
7: Extract bounding box coordinates and con-
22.1. Why Object Recognition is Used
fidence score
• To identify and classify objects in images 8: Draw bounding boxes and labels on the im-
or videos automatically. age
9: end for
• To support applications like autonomous
10: Display the annotated image with detections
driving, surveillance, and robotics.
• To compare pre-trained models (such as
YOLO, Faster R-CNN) with custom-trained 23.2. Performance Metrics for Object Recognition
solutions for performance optimization. • Accuracy: Proportion of correctly identi-
fied objects.
13
• Precision: Ratio of true positives to total Trade-offs in Code Implementation
predicted positives.
• Recall: Ratio of true positives to total ac-
Aspect YOLOv5 (Pre- Faster R-CNN (Pre- Custom-Trained
tual positives. trained) trained) Model

• mAP (mean Average Precision): Av-


Speed Very fast inference; suit- Slower due to region pro- Moderate speed; depends
eraged precision across all classes and recall able for real-time use posals and complex layers on model complexity

thresholds.
Accuracy Good accuracy for many Higher accuracy, espe- Can be optimized for tar-
Model Accuracy (%) Precision Recall Remarks classes cially on small objects get dataset

YOLOv5 (Pre-trained) 85.4 0.88 0.83 Fast inference; good for real-time
applications
Complexity Lightweight, easy to de- Complex architecture, re- Requires training data
ploy quires more resources and tuning
Faster R-CNN (Pre-trained) 90.2 0.92 0.89 Higher accuracy but slower; suit-
able for offline processing

Flexibility Fixed classes from pre- Flexible for fine-tuning Fully customizable for
Custom-Trained Model 87.0 0.89 0.85 Optimized for specific dataset; trained weights new classes
balanced speed and accuracy

Table 11: Performance Comparison of Object Recog- Application Real-time detection tasks High-accuracy offline Domain-specific recogni-
tasks tion
nition Models

Table 12: Trade-offs in Object Recognition Models


24. Annotated Pseudocode for Object Recog-
nition
Summary
# Load image using OpenCV
img = cv2.imread(’2.jpg’) This project focuses on improving smart city surveil-
lance by enhancing the quality of low-resolution,
# Load pre-trained YOLOv5 model noisy, and motion-blurred images. We applied spa-
using PyTorch Hub tial filtering techniques such as mean, median, and
model = torch.hub.load(’ultralytics/ Laplacian to reduce noise, and frequency domain
yolov5’, ’yolov5s’, pretrained=True) filtering using Fourier transforms for periodic noise
# Run detection on input image removal. Image restoration methods like Wiener
results = model(img) filtering and deblurring improved clarity. Segmen-
tation techniques like Canny and Watershed iso-
# Extract detection results to dataframe lated key objects, while compression algorithms
df = results.pandas().xyxy[0] optimized data storage. Finally, object detection
# Filter for vehicles: car, bus, was implemented using deep learning models in-
motorcycle, truck cluding YOLO and Faster R-CNN. The system en-
vehicles = df[df[’name’].isin([’car’, sures real-time, accurate monitoring on low-power
’bus’,’motorcycle’, ’truck’])] devices in urban environments.
# Draw bounding boxes and confidence
scores for , row in vehicles.iterrows(): References
xmin, ymin, xmax, ymax = int(row[’xmin’]),
[1] R. C. Gonzalez and R. E. Woods, Digital Im-
int(row[’ymin’]), int(row[’xmax’]),
age Processing, 4th. Pearson, 2018.
int(row[’ymax’])
label = f"row[’name’] row[’confidence’] [2] J. Canny, “A computational approach to edge
:.2f" detection,” IEEE Transactions on Pattern Anal-
cv2.rectangle(img, (xmin, ymin), ysis and Machine Intelligence, vol. PAMI-8,
(xmax, ymax), (0, 255, 0), 2) no. 6, pp. 679–698, 1986.
cv2.putText(img, label, (xmin, ymin - 10), [3] N. Wiener, “Extrapolation, interpolation, and
cv2.FONT HERSHEY SIMPLEX, 0.7, (0, 255, 0), smoothing of stationary time series,” MIT Press,
2) Cambridge, MA, 1949.
# Display the result image with detections [4] N. Ahmed, T. Natarajan, and K. R. Rao, “Dis-
cv2.imshow(’Vehicle Detection’, img) crete cosine transform,” IEEE Transactions
cv2.waitKey(0) on Computers, vol. C-23, no. 1, pp. 90–93,
cv2.destroyAllWindows() 1974.
[1] [2] [3] [4]
14
Author Biographies

Abdul Ahad Iqbal


I am currently a 4th-semester student of BS Computer Science. I have an in-
terest in game development and the Internet of Things (IoT). I enjoy learning
how technology can be used to build useful and creative solutions. I am work-
ing on improving my skills to build a career in the tech industry and explore
opportunities in technology-based businesses or startups.

Maryam Asad
Maryam Asad 7th semester student, is a Junior IT Specialist at Eco Out-
sourcing with experience in Microsoft 365, Intune, SharePoint, Teams, and
CRM development. I am currently enhancing my skills through a focused 6-
month training plan covering security, automation, and IT service delivery.
Passionate about AI and cybersecurity, I am also working on research and
academic projects, including post-quantum cryptography and intelligent au-
tomation tools. I am aims to bridge technical solutions with real-world busi-
ness needs.

Zara
I’m a 4th-semester BS Computer Science student at the University of Man-
agement and Technology. I’m passionate about coding, digital design, and
innovation. With a strong foundation in C++ and a knack for creativity, I’m
always looking for opportunities to learn, grow, and make a difference.

Anees Akram
Motivated and enthusiastic BS Computer Science student (4th Semester) in
University of Management and Technology, with strong skills in C++ and dig-
ital design. Known for excellent communication, responsiveness, and eagerness
to learn. Seeking opportunities to grow in dynamic and challenging environ-
ments.

Overleaf link for Instructor:

https://www.overleaf.com/read/mfvjqjnqgsxg#
cc3708
15

You might also like