0% found this document useful (0 votes)
16 views69 pages

Dip Assignment Tauqeer

The document contains an assignment report on Digital Image Processing (DIP) by MD Tauqeer, detailing various interpolation techniques, relationships between pixels, and histogram equalization methods. It discusses image enhancement techniques using PSNR and SSIM for quality assessment, and explores spatial and frequency domain filtering with low and high pass filters. The report includes MATLAB programs for implementing these techniques and evaluating their performance.

Uploaded by

mudassir16alam
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)
16 views69 pages

Dip Assignment Tauqeer

The document contains an assignment report on Digital Image Processing (DIP) by MD Tauqeer, detailing various interpolation techniques, relationships between pixels, and histogram equalization methods. It discusses image enhancement techniques using PSNR and SSIM for quality assessment, and explores spatial and frequency domain filtering with low and high pass filters. The report includes MATLAB programs for implementing these techniques and evaluating their performance.

Uploaded by

mudassir16alam
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

Assignment Report on DIP

Submitted By

MD TAUQEER 20224096

To
Prof. Basant Kumar
Assignment :- 1

Prepare List of various Interpolation Technique


Assignment :- 2

Relationship Between Pixels


Assignment:- 3

Histogram equalization techniques


1. Standard Histogram Equalization

Idea:
● The goal is to “flatten” and “stretch” the intensity distribution of the image.

● It uses the cumulative distribution function (CDF) of the image’s histogram to map
original intensities to new values so that the output histogram is approximately
uniform.
2. Adaptive Histogram Equalization (AHE)
3. Contrast Limited Adaptive Histogram Equalization
(CLAHE)
5. Histogram Matching / Specification
1.Apply Histogram Equalization to both tables

r (n) I:Pr s z (n) I:Pz v


0 20 0.2 1 0 5 0.05 0
1 5 0.25 2 1 10 0.15 1
2 25 0.5 3 2 15 0.3 2
3 10 0.6 4 3 20 0.5 4
4 15 0.75 5 4 20 0.7 5
5 5 0.8 6 5 15 0.85 6
6 10 0.9 6 6 10 0.95 7
7 JO 1.0 7 7 5 1.0 7
2. Get a map
Actual Output
v «. We get Histogram
r s v zz r z z # Pixels
s «.
0 1 v 0 0 0 1 0 0
1 2 l l 1 2 1 20
2 3 2 2 2 2 2 30
3 4 4 3 3 3 3 10
4 5 5 4 4 4 4 15
5 6 6 5 5 5 5 15
6 6 7 6 6 5 6 10
7 7 7 7 7 6 7 0
Intensity # pixels
r z
(z) Intensity # pixels z # Pixels
0 1 05 (r) 0 0
1 2 1 10 20
0 1 20
2 2 2
15 1 5 2 30
3 3 2 25
3 20 3 10
4 4 3 10
4 20 4 15
5 5 5 15 4 15
5 15
6 5 5 5
10
6 6 10
7 6 6 10
7 5 7 0
7
Total 100 10
Total 100
Assignment:- 4

Enhanced image using PSNR SSIM


Objective:

To enhance an image using any image enhancement technique and then evaluate the
enhancement quality using PSNR (Peak Signal-to-Noise Ratio) and SSIM (Structural
Similarity Index Measure).

Theory
1. Image Enhancement

Image enhancement is a process of improving the visual appearance of an image or making it


more suitable for analysis by a human or machine. Common enhancement techniques include:

● Histogram Equalization
● Contrast Stretching
● Filtering (Sharpening or Smoothing)
● Gamma Correction

2. Quality Assessment Metrics

PSNR (Peak Signal-to-Noise Ratio)

● PSNR measures the ratio between the maximum possible power of a signal and the
power of corrupting noise.
● It is commonly used to measure the quality of reconstructed or compressed images.
SSIM (Structural Similarity Index Measure)

● SSIM compares two images based on luminance, contrast, and structure.

● It returns a value between 0 and 1.


Matlab Program:-
% Enhanced Image Using PSNR and SSIM
clc;
clear;
close all;

% Step 1: Read Original Image


originalImage =
imread(['https://images.ctfassets.net/hrltx12pl8hq/28ECAQiPJZ78hxat
LTa7Ts/' ...
'
2f695d869736ae3b0de3e56ceaca3958/free-nature-images.jpg?fit=fill&w=
1200&h=630' ]); % you can replace with your own image
figure, imshow(originalImage), title( 'Original Image' );

% Step 2: Apply Histogram Equalization


enhancedImage = histeq(originalImage);
figure, imshow(enhancedImage), title( 'Enhanced Image (Histogram
Equalized)' );

% Step 3: Calculate PSNR


psnrValue = psnr(enhancedImage, originalImage);
fprintf('PSNR between Original and Enhanced Image: %.2f dB\n'
, psnrValue);
% Step 4: Calculate SSIM
ssimValue = ssim(enhancedImage, originalImage);
fprintf('SSIM between Original and Enhanced Image: %.4f\n' ,
ssimValue);

% Step 5: Display side-by-side comparison


figure;
subplot(1,2,1), imshow(originalImage), title( 'Original' );
subplot(1,2,2), imshow(enhancedImage), title( 'Enhanced' );
Matlab Output:-
Assignment:- 5

In spatial and frequency domain apply low


pass and high pass filter check using PSNR and
SSIM
Objective
To enhance and analyze images by applying low pass and high pass filters in both
spatial and frequency domains, and evaluate the quality of the filtered images using
PSNR (Peak Signal-to-Noise Ratio) and SSIM (Structural Similarity Index
Measure).

Theory
🔹 1. Spatial Domain Filtering

● Involves direct manipulation of pixel values using filter masks.


● Low Pass Filter (LPF): Smooths the image, reducing noise and detail.
○ Common example: Averaging filter (blurs the image).
● High Pass Filter (HPF): Enhances edges and fine details by subtracting low-frequency
components.
○ Common example: Laplacian filter (detects edges).

🔹 2. Frequency Domain Filtering

● Image is transformed using 2D Fast Fourier Transform (FFT) into the frequency domain.
● Filtering is done by modifying frequency components:
○ LPF retains low-frequency components (center) and attenuates high frequencies (edges).
○ HPF retains high frequencies and removes low frequencies.
● After filtering, the Inverse FFT is applied to return to the spatial domain.
🔹 3. Image Quality Metrics
● PSNR (Peak Signal-to-Noise Ratio):
○ Measures the similarity between the original and filtered images.
○ Higher PSNR indicates better quality.

● SSIM (Structural Similarity Index):


○ Measures structural similarity between images.
○ Value ranges from -1 to 1 (1 means identical).
Matlab Program:-

clc;
clear;
close all;
% Load and prepare the image
original_image =
imread('https://helpx.adobe.com/content/dam/help/en/photoshop/usin
g/convert-color-image-black-white/jcr_content/main-pars/before_and
_after/image-before/Landscape-Color.jpg');
% Convert to grayscale if needed
if size(original_image, 3) == 3
original_image = rgb2gray(original_image);
end
original_image = im2double(original_image);
figure; imshow(original_image); title('Original Image');

%% Parameters
filter_size = 15; % Size for spatial domain filters
cutoff_frequency = 30; % Cutoff frequency for frequency domain
filters
%% Spatial Domain Filtering
% 1. Low-pass filtering (Averaging filter)
h_low_spatial = fspecial( 'average', filter_size);
low_pass_spatial = imfilter(original_image, h_low_spatial,
'replicate' );
% 2. High-pass filtering (Laplacian filter)
h_high_spatial = fspecial( 'laplacian' , 0.2);
high_pass_spatial = imfilter(original_image, h_high_spatial,
'replicate' );
high_pass_spatial = mat2gray(high_pass_spatial);

%% Frequency Domain Filtering


% Compute Fourier Transform
F = fft2(original_image);
F_shifted = fftshift(F);
magnitude_spectrum = log(1 + abs(F_shifted));
[M, N] = size(original_image);
[X, Y] = meshgrid(1:N, 1:M);
center_X = floor(N/2) + 1;
center_Y = floor(M/2) + 1;
% Create frequency domain filters
D = sqrt((X - center_X).^2 + (Y - center_Y).^2);
H_low_freq = double(D <= cutoff_frequency);
H_high_freq = 1 - H_low_freq;
% Apply filters
low_pass_freq = real(ifft2(ifftshift(F_shifted .* H_low_freq)));
high_pass_freq = real(ifft2(ifftshift(F_shifted .* H_high_freq)));
high_pass_freq = mat2gray(high_pass_freq);

%% Combined Visualization
figure;
subplot(2,3,1); imshow(original_image); title( 'Original Image' );
subplot(2,3,2); imshow(low_pass_spatial); title( 'Spatial:
Low-pass');
subplot(2,3,3); imshow(high_pass_spatial); title( 'Spatial:
High-pass' );
subplot(2,3,4); imshow(magnitude_spectrum, []); title( 'Magnitude
Spectrum');
subplot(2,3,5); imshow(low_pass_freq, []); title( 'Frequency:
Low-pass');
subplot(2,3,6); imshow(high_pass_freq, []); title( 'Frequency:
High-pass' );
%% Quality Assessment
[psnr_spatial_low, ~] = psnr(low_pass_spatial, original_image);
ssim_spatial_low = ssim(low_pass_spatial, original_image);
[psnr_spatial_high, ~] = psnr(high_pass_spatial, original_image);
ssim_spatial_high = ssim(high_pass_spatial, original_image);
[psnr_freq_low, ~] = psnr(low_pass_freq, original_image);
ssim_freq_low = ssim(low_pass_freq, original_image);
[psnr_freq_high, ~] = psnr(high_pass_freq, original_image);
ssim_freq_high = ssim(high_pass_freq, original_image);

%% Display Results
filter_names = {
'Spatial Low-pass (Averaging)' ;
'Spatial High-pass (Laplacian)' ;
'Frequency Ideal Low-pass' ;
'Frequency Ideal High-pass'
};
psnr_values = [
psnr_spatial_low;
psnr_spatial_high;
psnr_freq_low;
psnr_freq_high
];
ssim_values = [
ssim_spatial_low;
ssim_spatial_high;
ssim_freq_low;
ssim_freq_high
];
results_table = table(filter_names, psnr_values, ssim_values, ...
'VariableNames' , {'Filter_Type' , 'PSNR', 'SSIM'});
disp('Quality Assessment Results:' );
disp(results_table);

%% Plot Comparison
figure;
bar([psnr_values, ssim_values]);
set(gca, 'XTickLabel' , filter_names);
xtickangle(45);
ylabel('Metric Value' );
title('Filter Performance Comparison' );
legend('PSNR', 'SSIM');
grid on;
Matlab Output:-

You might also like