FACULTY OF ENGINEERING
Department of Information Technology
3171614 – CV – Lab Manual
Practical: 1
Aim: Implementing various basic image processing operations in
python/matlab/open-CV: Reading image, writing image, conversion of
images, and complement of an image.
image=imread('set.jpeg');
%imshow(image);
imwrite(image,'output.jpeg');
subplot(1,3,1);
imshow(image);
title('Original');
img=rgb2gray(image);
subplot(1,3,2);
imshow(img);
title('Gray');
ic=imcomplement(img);
subplot(1,3,3);
imshow(ic);
title('incomplement');
Output:
Hemal Patel 210570116026 |1
FACULTY OF ENGINEERING
Department of Information Technology
3171614 – CV – Lab Manual
Practical: 2
Aim: Implement contrast adjustment of an image. Implement Histogram
processing and equalization.
a=imread('cameraman.tif');
subplot(2,2,1);
imshow(a);
title('Original');
b=1./(10./(double(a)+eps).^20);
subplot(2,2,2);
imshow(b);
title('contrast streching-50');
b=1./(100./(double(a)+eps).^20);
subplot(2,2,3);
imshow(b);
title('contrast streching-100');
b=1./(150./(double(a)+eps).^20);
subplot(2,2,4);
imshow(b);
title('contrast streching-150');
➢ Histogram Processing and Equilization:
a=imread('cameraman.tif');
subplot(5,2,1);
imshow(a);
title('Original');
subplot(5,2,2);
imhist(a);
title('Histogram');
I=numel(a);
subplot(5,2,3);
imshow(a./I);
title('Normalized Image');
p=imhist(a)/I;
subplot(5,2,4);
imhist(p);
title('Normalized Histogram');
J=histeq(a);
subplot(5,2,5);
imshow(J);
title('Equilized Image');
subplot(5,2,6);
imhist(J);
title('Equilized Histogram');
Hemal Patel 210570116026 |1
FACULTY OF ENGINEERING
Department of Information Technology
3171614 – CV – Lab Manual
Output:
Hemal Patel 210570116026 |1
FACULTY OF ENGINEERING
Department of Information Technology
3171614 – CV – Lab Manual
Practical: 3
Aim: Implement the various low pass and high pass filtering mechanisms.
➢ Low Pass
I = imread('set.jpeg');
I_gray = rgb2gray(I);
% Apply Gaussian filter
h = fspecial('gaussian', [5, 5], 1.0); % 5x5 kernel, sigma =
1.0
I_low_pass = imfilter(I_gray, h);
% Display the result
subplot(1, 2, 1);
imshow(I_gray);
title('Original Image');
subplot(1, 2, 2);
imshow(I_low_pass);
title('Low-Pass Filtered Image (Gaussian)');
Output:
➢ High Pass
I = imread('set.jpeg');
I_gray = rgb2gray(I);
% Apply Laplacian filter
h = fspecial('laplacian', 0.2); % alpha = 0.2
I_high_pass = imfilter(I_gray, h);
% Display the result
subplot(1, 2, 1),
imshow(I_gray),
title('Original Image');
subplot(1, 2, 2),
imshow(I_high_pass),
title('High-Pass Filtered Image (Laplacian)');
Hemal Patel 210570116026 |1
FACULTY OF ENGINEERING
Department of Information Technology
3171614 – CV – Lab Manual
Output :
Hemal Patel 210570116026 |1
FACULTY OF ENGINEERING
Department of Information Technology
3171614 – CV – Lab Manual
Practical: 4
Aim: Use of Fourier transform for filtering the image.
I = imread('set.jpeg');
I_gray = rgb2gray(I);
% Display the original image
figure;
imshow(I_gray);
title('Original Image');
% Comput e the 2D Fourier Transform
F = fft2(I_gray);
% Shift zero frequency components to the center
F_shifted = fftshift(F);
% Display the magnitude spectrum
ms = log(1 + abs(F_shifted));
figure;
imshow(ms, []);
title('Magnitude Spectrum');
Output:
Hemal Patel 210570116026 |1
FACULTY OF ENGINEERING
Department of Information Technology
3171614 – CV – Lab Manual
Practical: 5
Aim: Utilization of SIFT and HOG features for image analysis.
1. Install Required Libraries
Ensure you have the VLFeat library installed for SIFT and necessary tools for HOG features.
2. Setup VLFeat in Octave
Download VLFeat from the official website, extract it, and setup in Octave:
run('/path_to_vlfeat/toolbox/vl_setup');
3. Load and Preprocess Image
Read your image and convert it to grayscale.
I = imread('path_to_your_image.jpg');
I_gray = single(rgb2gray(I)); % for SIFT
4. SIFT Feature Detection
Detect SIFT features using the VLFeat library.
[f, d] = vl_sift(I_gray);
imshow(I);
hold on;
vl_plotframe(f);
title('SIFT Features');
hold off;
5. HOG Feature Extraction
Compute HOG features using VLFeat.
I_hog = vl_hog(I_gray, 8); % Cell size of 8
imshow(vl_hog('render', I_hog));
title('HOG Features');
6. Feature Matching (Optional)
If you have another image, you can match SIFT features between two images.
% Load second image
I2 = imread('path_to_your_second_image.jpg');
I2_gray = single(rgb2gray(I2));
% Detect SIFT features
[f2, d2] = vl_sift(I2_gray);
% Match features
[matches, scores] = vl_ubcmatch(d, d2);
% Plot matched features
figure;
showMatchedFeatures(I, I2, f(1:2, matches(1,:))', f2(1:2,
matches(2,:))', 'montage');
title('SIFT Feature Matching');
Hemal Patel 210570116026 |1
FACULTY OF ENGINEERING
Department of Information Technology
3171614 – CV – Lab Manual
Output:
Hemal Patel 210570116026 |1