You are on page 1of 117

Fundamentals of Image and Video

Processing Processing(2181102)
Practical List – 2023-240

Subject Teachers: Prof. Chirag N. Paunwala, Prof. Ketki C. Pathak

Sr.
List Date Sign
No
1 a) To read color image and convert it into gray scale.
(b) To read gray scale image and convert it into binary image.
(c) Convert binary image into negative image.
(d) Apply spatial resolution on original image by sampling
1/2, 1/4, 1/16 & 1/32 .Resize the output image again into the
orginal image with the same sampling level & comment the
result.
Apply different interpolation (Nearest Neighbourhood,
Bilinear & Bicubic) and comment on result.
2 Read an 8 bit image and then apply different image
enhancement techniques:
(a) Brightness improvement
(b) Brightness reduction
(c) Thresholding
(d) Negative of an image
(e) Log transformation
(f) Power Law transformation
3. a) Implement Gray level slicing (intensity level slicing) in
MATLAB to read cameraman image,
(b) To read an 8 bit image and to see the effect of each bit on
the image.
(c) To read an image and to extract 8 different planes i.e. ‘bit
plane slicing’.
4 To read an image, plot its histogram then do histogram
equalization and histogram specification. Comment in the
result. (With and Without using inbuilt functions)
5 To Implement Smoothing spatial filter.
Read an image and then corrupt it by ‘Salt and Pepper’,
‘Gaussian’, ‘Speckle’ noise then apply
(a) AVERAGING filter with 3x3 mask and 5x5 mask.
(b) MEDIAN filter with 3x3 and 5x5 mask.
(c) Max, Min, Midpoint filter with 3x3.
Comment on the results.
6 To read an image and apply (1) Gaussian 3x3 mask for burring
(2) High pass filter mask with different masks (3) Laplacian
operator with centre value positive and negative (4) High
boost filtering.
7 Implement various noise models and their
Histogram
Noise models are
i)Gaussian ii)Rayleigh iii)Erlang
iv) Salt and Pepper v)Exponential vi)Uniform
8 Write a MATLAB program for erosion and dilation and
opening & closing using inbuilt and without inbuilt function.
9 Analyse Effect of Different Mask (Sobel, Prewitt and Roberts,
Canny and Log ) on Edges of square with diagonals, as shown
in figure (plot it using MATLAB commands) Also apply
gaussian noise and then apply various edge operators and
comment on result

10 Write an algorithm to count number of object in image. Also


check efficiency of your algorithm by varying different
dependent parameters.
11 To read an image and apply Arithmetic mean filter, Geometric
mean filter, Harmonic mean filter and contraharmonic mean
filter.
12 Perform Image compression using
a)Huffman coding b)Arithmetic coding
Mini project/ALA
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

Aim: Implement and study of image processing toolbox (Various functions


including data classes)

Theory:
1. Cropping:
Cropping involves selecting a specific region of interest within an image,
eliminating unwanted portions. This operation is fundamental for focusing on
particular details or resizing images.
2. Arithmetic Operations:
Arithmetic operations like addition and subtraction are applied to images for
various purposes, such as adjusting brightness or contrast. Multiplication and
division can be used for scaling or normalization.
3. Rotation:
Rotating an image involves transforming its orientation. This operation is
employed for correcting alignment issues, achieving a desired perspective, or
facilitating further analysis.
4. RGB to Gray Conversion:
Converting an RGB (Red, Green, Blue) image to grayscale simplifies its
representation to a single intensity channel, useful for certain analyses where color
information is unnecessary or counterproductive.
5. Linspace Resizing:
Linspace resizing involves resizing an image by interpolating pixel values along
specified lines. This method is useful for achieving smooth transitions during size
adjustments, preserving image quality.
These operations collectively contribute to the manipulation and enhancement of
images, supporting a wide range of applications from computer vision to medical
imaging. The choice and combination of these operations depend on the specific
requirements of the task at hand.

Page | 1
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

Questions:
1. Importance of Double precision, uint8 and im2double.

Double Precision:
Importance: Double precision uses 64 bits to represent a number, providing a wide
range and high precision. In image processing, where accuracy is crucial, double
precision can help avoid rounding errors and loss of information during
calculations.
Use Cases: Double precision is often used in algorithms that require high accuracy,
such as scientific computations or processing images with high dynamic range.

uint8:
Importance: uint8 is an 8-bit unsigned integer data type commonly used to
represent pixel values in digital images. It has a range from 0 to 255, making it
suitable for storing grayscale or color images with 8 bits per channel.
Use Cases: uint8 is widely used in image processing for storage and basic
operations like addition, subtraction, and multiplication. It is memory-efficient
and sufficient for many applications where high precision is not necessary.

im2double:
Importance: im2double is a function in MATLAB (and some other image
processing libraries) used to convert images from other data types (such as uint8)
to double precision.
Use Cases: When performing image processing operations that require double
precision accuracy, it is common to convert images from their original data types
(like uint8) to double precision using im2double before processing. This ensures
that calculations are performed with the desired precision.

Page | 2
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

2. Why 8-bit image is used in general image processing?


Storage Efficiency: 8-bit images require less storage space compared to higher bit-
depth images, making them more efficient for storing and transmitting images,
especially in applications where storage capacity or bandwidth is limited.
Computational Efficiency: Processing 8-bit images is generally faster than
processing higher bit-depth images because operations on 8-bit values require
fewer computational resources. This can be advantageous in real-time or resource-
constrained applications.
Compatibility: Many image processing algorithms and software are optimized for
8-bit images, making them widely compatible with existing tools and libraries.
This can simplify the development and deployment of image processing
applications.

3. What is the reason to choose grayschale images for various image


processing practicals.
Grayscale images are often chosen for image processing practicals because they
are simpler to work with, require less memory and storage, focus on intensity
processing (which is fundamental to many algorithms), and have historical
precedence in the field of image processing. Additionally, many classic image
processing techniques were developed and tested using grayscale images, making
them a natural choice for educational and practical purposes.

PART: A

Algorithm:

Step-1: Read the image file using the function imread().


Step-2: Crop the image using the function imcrop(). Use function imshow() to
display image.

Page | 3
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

Step-3: Convert any coloured image into gray image using function rgb2gray().
Step-4: Perform different arithmetic operations on image.
Step-5: Rotate the image using the function imroate().

Code:

 Reading an image.
P1 = imread('C:\Users\Priyanshi\Desktop\mountain.jpg');
P1 = imresize(P1,[256 256]);
[X,map]=imread('C:\Users\Priyanshi\Desktop\mountain.jpg');

 Cropping image.
P2 = imcrop(P1,[89 35 190 200]);
subplot(1,2,1);
imshow(P1);
title('Not croped');
subplot(1,2,2);
imshow(P2);
title('croped');
figure;

 RGB to Gray.
P3 = rgb2gray(P1);
imshow(P3);
title('RGB2Gray');
figure;
 Arithmetic operations.
P4 = imread('C:\Users\Priyanshi\Desktop\butterfly.jpeg');
P4 = imresize(P4,[256 256]);
P5 = imadd(P1,P4);

subplot(2,2,1);
imshow(P5);
title('addition');

Page | 4
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

P6 = immultiply(P1,P4);
subplot(2,2,2);
imshow(P6);
title('Multiplication');

P7 = imsubtract(P1,P4);
subplot(2,2,3);
imshow(P7);
title('Subtraction');

P8 = imdivide(P1,P4);
subplot(2,2,4);
imshow(P8);
title('Division');
figure;

 Rotate.
P9 = imrotate(P1,270);
imshow(P9);
title('Rotation');

Page | 5
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

Output:
 Reading an image

Function used: to read the image, imread

To resize the image, imresize

 Cropping image

Page | 6
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

Function used: imcrop

 RGB to Gray

Function used: rgb2gray

 Arithmetic operations

Function used: for addition, imadd

Page | 7
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

For subtraction, imsubtract

For multiplication, immultiply

For division, imdivide

 Rotate

Function used: imrotate

Page | 8
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

PART: B
Algorithm:

Step-1: Read the image file using the function imread().


Step-2: Convert uint8 data type to double data type of image.
Step-3: Plot the images of different data types.
Step-4: Convert doule data type to uint8 data type of image.
Step-5: Plot the images of different data types.
Step-6: Use the linspace command for reshaping of an image.

Code:
clc;
close all;
clear all;

 %% Reading image
i = imread('C:\Users\Priyanshi\Desktop\tree.jpg');
imshow(i);

 %% Conversion of uint8 to double.


i1 = double(i);
i2 = im2double(i);
i3 = im2double(i1);

 %% Ploting the images.


subplot(2,2,1);
imshow(i);
title('uint8 image');

subplot(2,2,2);
imshow(i1);

Page | 9
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

title('double image');

subplot(2,2,3);
imshow(i2);
title('im2double for uint8 image');

subplot(2,2,4);
imshow(i3);
title('im2double for double image');
figure;

 %% Conversion of double to uint8 and plotting image.


subplot(1,3,1);
imshow(i);
title('Original');

i5 = uint8(i1);
subplot(1,3,2);
imshow(i5);
title('double to uint8 of i1');

i6 = uint8(i3);
subplot(1,3,3);
imshow(i6);
title('double to uint8 of i2');
figure;

 %% Mathemetical operation.
i7 = imadd(i,30);
subplot(1,2,1);
imshow(i7);
title('imadd(i,30)');

i8 = imsubtract(i,30);
subplot(1,2,2);
imshow(i8);
title('imsubtract(i,30)');
figure;
Page | 10
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

 %% Reshaping using linspace.


i9 = reshape(uint8(linspace(1,255,25)),[5,5]);
i10 = im2double(i9);
imshow(i10);

 %% reading the image.


I=imread('tire.tif');
J=imread('tire.tif');

 %% Image multiplication.
K=immultiply(I,2);
figure,imshow(K);

 %% Plotting histograms.
K1=histeq(K);
figure,imhist(K1);

I1=histeq(I);
figure,imhist(I1);

J1=histeq(J);
figure,imhist(J1);

Page | 11
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

Output:

 %% Reading image

 %% Conversion of uint8 to double.

Page | 12
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

Function used:
i1 = double(i);
i2 = im2double(i);
i3 = im2double(i1);
 %% Conversion of double to uint8 and plotting image.

Function used:

i5 = uint8(i1);

 %% Mathematical operation.

Page | 13
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

Function used: for addition, imadd

For subtraction, imsubtract

 %% Reshaping using linspace.

i9 = reshape(uint8(linspace(1,255,25)),[5,5]);
i10 = im2double(i9);

 %% apply thresholding to image

Function used: level=graythresh(i);


bw=im2bw(i,level);

Page | 14
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 04-01-2024 Experiment:01

 %% Plotting histograms.

Function used: imhist

Conclusion:
Here we have observed the different operations on the image. Every operation
changes the Matrix value of the image and due to change in the value of different
pixels we can visualize our image in many different ways. We can crop, rotate, make
Black and white of any image. We can also plot the histograms for the images. Also
we can make images bright or dark also.

Page | 15
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 18-01-2024 Experiment:02

Aim: Apply inbuilt function for image resize for the different scale 1/2/, 1/4/, 1/8
and 1/16. Similarly reconstruct the image with the scale 2,3,8,16. Apply Nearest
neighborhood, Bicubic and Bilinear methods. Compare the perceptual quality by
calculating MSE and PSNR.

Theory:
Image resizing is the process of changing the dimensions of an image. This can be
done by either increasing or decreasing the number of pixels in the image. When
an image is resized, the pixel information is manipulated to create a new image
that is the desired size.
There are two main types of image resizing:
 Down sampling: This is the process of reducing the number of pixels in an
image. When an image is down sampled, some of the pixel information is
lost. This can result in a loss of image quality, especially if the image is
down sampled by a large amount.

Down sampling image


 Up sampling: This is the process of increasing the number of pixels in an
image. When an image is up sampled, new pixels are created by
interpolating the values of existing pixels. This can result in a loss of image
sharpness, as the new pixels are not based on real image data.

Page | 1
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 18-01-2024 Experiment:02

Up sampling image
There are a number of different algorithms that can be used to resize images. The
best algorithm to use will depend on the specific requirements of the application.
Some of the most common image resizing algorithms include:
 Nearest neighbor interpolation: This is a simple algorithm that replaces each
pixel in the resized image with the nearest pixel in the original image. This
algorithm is fast and efficient, but it can result in a blocky appearance in the
resized image.

Nearest neighbor interpolation image


 Bilinear interpolation: This algorithm takes the average of the values of the
four nearest pixels in the original image to determine the value of each pixel
in the resized image. This algorithm produces a smoother image than
nearest neighbor interpolation, but it can still result in some blurring.

Page | 2
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 18-01-2024 Experiment:02

Bilinear interpolation image


 Bicubic interpolation: This algorithm takes the average of the values of the
16 nearest pixels in the original image to determine the value of each pixel
in the resized image. This algorithm produces the highest quality images of
the three algorithms discussed here, but it is also the slowest.

Bicubic interpolation image


When choosing an image resizing algorithm, it is important to consider the
following factors:
 The quality of the original image: If the original image is of high quality,
then you will want to use an algorithm that produces high-quality resized

Page | 3
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 18-01-2024 Experiment:02

images, such as bicubic interpolation. However, if the original image is of


low quality, then you may be able to get away with using a simpler
algorithm, such as nearest neighbor interpolation.
 The amount of resizing: If you are only resizing the image by a small
amount, then you may be able to use a simpler algorithm. However, if you
are resizing the image by a large amount, then you will need to use a more
complex algorithm to avoid losing too much image quality.
 The computational cost: Some image resizing algorithms are more
computationally expensive than others. If you are working with a large
number of images, then you may need to choose an algorithm that is fast
and efficient, even if it does not produce the highest quality images.
Algorithm:
1. Initialize: Clear the command window and close all figures.
2. Load Image: Read an image file (in this case, ‘cameraman.tif’) into the workspace.
3. Create Copies: Create a copy of the image for processing.
4. Upscale and Downscale: Perform image resizing operations using three different
interpolation methods: ‘nearest’, ‘bilinear’, and ‘bicubic’. For each method:
 Upscale: Increase the size of the image by factors of 2, 4, 8, and 16.
 Downscale: Decrease the size of the image by factors of 1/2, 1/4, 1/8,
and 1/16.
5. Display Results: For each resizing operation, display the resulting image in a
subplot and label it with the interpolation method and the scaling factor.

Code:
clc;
clear all;
close all;

%% Reading an image.
i = imread('tire.tif');
i = imresize(i,[256 256]);

Page | 4
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 18-01-2024 Experiment:02

%% Zooming an image using Interpolation of nearest neighbour.


subplot(3,3,1);
imshow(i);
title('Original Image');

i1 = imresize(i,2,'nearest');
subplot(3,3,2);
imshow(i1);
title('2x Zooming using NN');

I1 = imresize(i,1/2,'nearest');
subplot(3,3,3);
imshow(I1);
title('2x shrinking using NN');

subplot(3,3,4);
imshow(i);
title('Original Image');

i2 = imresize(i,4,'nearest');
subplot(3,3,5);
imshow(i2);
title('4x Zooming using NN');

I2 = imresize(i,1/4,'nearest');
subplot(3,3,6);
imshow(I2);
title('4x Shrinking using NN');

subplot(3,3,7);
imshow(i);
title('Original Image');

i3 = imresize(i,8,'nearest');
subplot(3,3,8);

Page | 5
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 18-01-2024 Experiment:02

imshow(i3);
title('8x Zooming using NN');

I3 = imresize(i,1/8,'nearest');
subplot(3,3,9);
imshow(I3);
title('8x Shrinking using NN');
figure;

%% Zooming an image using Interpolation of nearest bilinear.\


subplot(3,3,1);
imshow(i);
title('Original Image');

i4 = imresize(i,2,'bilinear');
subplot(3,3,2);
imshow(i4);
title('2x Zooming using bilinear');

I4 = imresize(i,1/2,'bilinear');
subplot(3,3,3);
imshow(I4);
title('2x shrinking using bilinear');

subplot(3,3,4);
imshow(i);
title('Original Image');

i5 = imresize(i,4,'bilinear');
subplot(3,3,5);
imshow(i5);
title('4x Zooming using bilinear');

I5 = imresize(i,1/4,'bilinear');
subplot(3,3,6);

Page | 6
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 18-01-2024 Experiment:02

imshow(I5);
title('4x Shrinking using bilinear');

subplot(3,3,7);
imshow(i);
title('Original Image');

i6 = imresize(i,8,'bilinear');
subplot(3,3,8);
imshow(i6);
title('8x Zooming using bilinear');

I6 = imresize(i,1/8,'bilinear');
subplot(3,3,9);
imshow(I6);
title('8x Shrinking using bilinear');
figure;

%% Zooming an image using Interpolation of nearest bicubic.


subplot(3,3,1);
imshow(i);
title('Original Image');

i7 = imresize(i,2,'bicubic');
subplot(3,3,2);
imshow(i7);
title('2x Zooming using bicubic');

I7 = imresize(i,1/2,'bicubic');
subplot(3,3,3);
imshow(I7);
title('2x shrinking using bicubic');

subplot(3,3,4);
imshow(i);

Page | 7
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 18-01-2024 Experiment:02

title('Original Image');

i8 = imresize(i,4,'bicubic');
subplot(3,3,5);
imshow(i8);
title('4x Zooming using bicubic');

I9 = imresize(i,1/4,'bicubic');
subplot(3,3,6);
imshow(I9);
title('4x Shrinking using bicubic');

subplot(3,3,7);
imshow(i);
title('Original Image');

i10 = imresize(i,8,'bicubic');
subplot(3,3,8);
imshow(i10);
title('8x Zooming using bicubic');

I10 = imresize(i,1/8,'bicubic');
subplot(3,3,9);
imshow(I10);
title('8x Shrinking using bicubic');

%% Calculating MSE for images.


i = imresize(i,[64 64]);
squared_diff = (i - I2).^2;
mse_n = mean(squared_diff(:))
R = 10;
psnrValue_n = 10 * log10((R^2) / mse_n)

i = imresize(i,[64 64]);
squared_diff = (i - I5).^2;

Page | 8
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 18-01-2024 Experiment:02

mse_bl = mean(squared_diff(:))
R = 10;
psnrValue_bl = 10 * log10((R^2) / mse_bl)

i = imresize(i,[64 64]);
squared_diff = (i - I9).^2;
mse_bc = mean(squared_diff(:))
R = 10;
psnrValue_bc = 10 * log10((R^2) / mse_bc

Output:

Page | 9
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 18-01-2024 Experiment:02

Page | 10
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 18-01-2024 Experiment:02

mse_n = 30.8198
psnrValue_n = 5.1117

mse_bl = 3.8554
psnrValue_bl = 14.1393

mse_bc = 0
psnrValue_bc = Inf

Conclusion:
We have applied image zooming and shrinking using resizing of an image. Here we
verified 2 times, 4 times and 8 times zooming and 2 times, 4 times and 8 times
shrinking also. All these different operations on the image are observable in the
above images. The MSE and PSNR values show that for this image that the bicubic
methods of the interpolation is the best for this image.

Page | 11
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 25-01-2024 Experiment:03

Aim: Read an 8-bit image and then apply different image enhancement techniques:
(a) Negative of an image
(b) Log transformation
(c) Power Law transformation

Theory:
Image enhancement techniques are used to improve the quality and clarity of images.
They involve altering the visual representation of an image to provide a better
depiction but maintaining important details.

Negative of an Image
The negative of an image is achieved by inverting the colors. Dark areas become
light and vice versa. This technique can be used to enhance contrast and bring out
hidden details in the original image.

Log Transformation
Log transformation is a method used to expand the range of dark intensities in an
image, making them more distinguishable. It's particularly effective for images
with low contrast or non-uniform lighting.
1. Contrast Adjustment
Log transformation helps to enhance the contrast in images to make
them visually more appealing.
2. No Loss of Information
It allows for the enhancement of dark pixels without losing important
image details.

Power Law Transformation


Power law transformation is a technique that adjusts pixel intensities using a
power-law function. It is particularly effective in improving the visibility of dark
areas in images.
Enhances Dark Regions: Adjusts pixel intensities to bring out details in
shadowed regions.
Improves Image Contrast: Enhances the contrast of the image, making dark
areas more distinguishable.

Page | 1
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 25-01-2024 Experiment:03

Benefits of Using Negative Image Enhancement


1. Improved Contrast
Enhances the contrast in dull or low-contrast images, making details
more visible.
2. Reveals Hidden Details
Brings out obscured details and textures, especially in underexposed
photos.

Benefits of Using Log Transformation


1. Enhanced Visibility
Brings out details in dark areas, improves the visual appeal, and
enhances the overall contrast.

Benefits of Using Power Law Transformation


1. Visible Shadow Details
Highlights intricate details in shadowed regions, improving image
clarity.
2. Enhanced Image Depth
Brings out subtle variations in intensity, adding depth and visual
interest to the image.

PART: A
Algorithm:
1. Read the image you want to perform enhancement on using imaread().
2. Convert image into grayscale if it is colored image.
3. Apply negative transformation by subtracting the original image from 255.
4. Apply log transformation according to formula log(1-r).
5. Apply gamma transformation according to the formula c(image)^gamma.
6. Show all images using imshow() function.
7. Plot the original image Vs enhanced image.

Page | 2
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 25-01-2024 Experiment:03

Code:
clc;
clear all;
close all;

%% Read the 8-bit image


original_image = imread('tire.tif');

%% Convert to grayscale if the image is in color


if size(original_image, 3) == 3
original_image = rgb2gray(original_image);
end

%% (a) Negative of an image


negative_image = 255 - original_image;

%% (b) Log transformation


log_transformed_image = log(1 +
double(original_image));

%% Inverse log transformation


inverse_log_transformed_image =
exp(log_transformed_image) - 1;

%% (c) Power Law transformation


gamma = 1.7;
c = 1;
power_law_transformed_image =
c*uint8((double(original_image) / 255.0).^gamma * 255);

%% Display the results


figure;

imshow(original_image);
figure;
title('Original Image');

Page | 3
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 25-01-2024 Experiment:03

subplot(2, 2, 1);
imshow(negative_image);
title('Negative Image');

subplot(2, 2, 2);
imshow(log_transformed_image, []);
title('Log Transformation');

subplot(2, 2, 3);
imshow(inverse_log_transformed_image);
title('Inverse log Transformation');

subplot(2, 2, 4);
imshow(power_law_transformed_image);
title('Power Law Transformation');

%% plot original vs enhanced

figure;
plot(original_image, negative_image);
hold on
plot(original_image, log_transformed_image);
hold on
plot(original_image, inverse_log_transformed_image);
hold on
plot(original_image, power_law_transformed_image);
hold off

Page | 4
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 25-01-2024 Experiment:03

Output:

Page | 5
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 25-01-2024 Experiment:03

PART: B
Algorithm:
1. Read the image using imread() function.
2. convert the image into double precision.
3. Ask for the choice of the user.
4. According to the 3 choices , if choice= 1 then use gamma image enhancement
technique.
5. If choice=2 then use negetive image enhancement technique.
6. If choice= 3 then use log image enhancement technique.
Code:
clc;
clear all;
close all;
I2=imread('tire.tif');
I=im2double(I2);
fprintf('for gamma press 1 \n for neg press 2 \n for
log press 3');

Page | 6
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 25-01-2024 Experiment:03

choice=input(':');
if choice == 1
c=input('enter value of C :');
gamma=input('enter gamma :');
gammaim=c*I^gamma;
imshow(gammaim)
end
if choice == 2
neg=256-1-I2
imshow(neg)
end
if choice == 3
c=input('enter value of C');
logim=c*log(I+1);
imshow(logim)
end

Output:

Page | 7
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 25-01-2024 Experiment:03

Conclusion:
These techniques are commonly used for basic image enhancement tasks and can be
applied to grayscale as well as color images. Each technique has its own
characteristics and applications, and they can be combined with other enhancement
techniques for more complex image processing tasks.

Page | 8
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 01-02-2024 Experiment:04

Aim: To read an image, plot its histogram then do histogram equalization. Comment
in the result. (With and Without using inbuilt functions)

Theory:
Histogram:
A histogram is a graphical representation of the distribution of numerical
data. It consists of a series of adjacent rectangles, or bins, that represent the
frequency or probability of occurrences of values within specified ranges in the
data. The x-axis of the histogram represents the range of values in the dataset,
while the y-axis represents the frequency or probability of those values occurring.
Histogram Equalization:
Histogram equalization is a technique used to adjust the contrast of an image
by redistributing the intensity values in the image's histogram. The goal is to obtain
a more uniform distribution of intensity values, which can improve the visual
appearance of the image. This technique is particularly useful for images with low
contrast or uneven lighting conditions.

Histogram equalization can significantly improve the contrast of an image, but it


may also amplify noise in the image. There are variations of histogram
equalization, such as adaptive histogram equalization, which adaptively applies
the transformation to smaller regions of the image to avoid over-enhancement of
noise.

Page | 1
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 01-02-2024 Experiment:04

PART: A
Algorithm:
1. Read the image using imaread().
2. Convert into grayscale if it is in RGB format.
3. Define the number of levels.
4. Create an empty vector name histogram which only have zeroes.
5. Go to each and every pixel using for loops and count occurrence of the pixel value.
6. Plot the histogram using bar plot.

Code:
clc;
clear all;
close all;

%% Function to plot histogram for any image without using imhist


img = imread('Downloads/spinal cord.jpg');

%% Convert the image to grayscale if it's a color image


if size(img, 3) == 3
img = rgb2gray(img);
end

%% Get the number of intensity levels (assuming 8-bit image)


numLevels = 256;

%% Initialize histogram
histogram = zeros(1, numLevels);

%% Calculate histogram
[rows, cols] = size(img);
for i = 1:rows
for j = 1:cols
pixel_value = img(i, j);
histogram(pixel_value + 1) = histogram(pixel_value + 1)
+ 1;
end
end

%% Plot the histogram

Page | 2
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 01-02-2024 Experiment:04

figure;
subplot(2,1,1);
bar(0:(numLevels-1), histogram, 'BarWidth', 1.0);
title('Image Histogram (user made)');
xlabel('Pixel Value');
ylabel('Frequency');
grid on;

%% Using inbuilt function


subplot(2,1,2);
imhist(img);
title('Image Histogram (inbuilt)');
xlabel('Pixel Value');
ylabel('Frequency');
grid on;

Output:

Page | 3
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 01-02-2024 Experiment:04

PART: B
Algorithm:
1. Read the image using imread().
2. Calculate the histogram equalization using histeq() function.
3. Plot the new images using imshow().
4. Plot the histograms using imhist().

Code:
clc;
clear all;
close all;

%% Apply histogram eqlization on image.


%% Read an image
i = imread('Downloads/spinal cord.jpg');

%% convert it into gray levels if it is RGB.


if size(i, 3) == 3
i = rgb2gray(i);
end

%% apply histogram equalization.


j = histeq(i);

%% plot the both histogram images.


subplot(1,2,1);
imshow(i);
title('Original image');

subplot(1,2,2);
imshow(j);
title('Equalized image');

%% plot histograms.
figure;
subplot(2,1,1);
imhist(i)
title('Histogram of original image');

subplot(2,1,2);

Page | 4
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 01-02-2024 Experiment:04

imhist(j);
title('Histogram of equalized image');

Output:

Page | 5
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 01-02-2024 Experiment:04

PART: C
Algorithm:
1. Read the image using imaread().
2. Convert into grayscale if it is in RGB format.
3. Define the number of levels.
4. Create an empty vector name histogram which only have zeroes.
5. Go to each and every pixel using for loops and count occurrence of the pixel value.
6. Calculate CDF and create the equalized image by redefining the value using CDF.
7. Plot the image and histogram for equalized and normal images.

Code:
clc;
clear all;
close all;

%% Read the image


img = imread('Downloads/spinal cord.jpg');

%% Convert the image to grayscale if it's a color image


if size(img, 3) == 3
img = rgb2gray(img);
end

%% Get the number of intensity levels (assuming 8-bit image)


numLevels = 256;

%% Calculate histogram
[rows, cols] = size(img);
histogram = zeros(1, numLevels);
for i = 1:rows
for j = 1:cols
pixel_value = img(i, j);
histogram(pixel_value + 1) = histogram(pixel_value + 1)
+ 1;
end
end

%% Normalize histogram

Page | 6
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 01-02-2024 Experiment:04

normalizedHistogram = histogram / (rows * cols);

%% Calculate cumulative distribution function (CDF)


cdf = cumsum(normalizedHistogram);

%% Perform histogram equalization


equalizedImage = uint8(255 * cdf(img + 1));

%% Plot original and equalized images


figure;
subplot(1, 2, 1);
imshow(img);

title('Original Image');
subplot(1, 2, 2);
imshow(equalizedImage);
title('Equalized Image');

%% Plot histograms.
figure;
subplot(2,1,1);
imhist(img)
title('Histogram of original image');

subplot(2,1,2);
imhist(equalizedImage);
title('Histogram of equalized image');

Output:

Page | 7
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 01-02-2024 Experiment:04

Conclusion:
Using inbuilt functions for reading an image, plotting its histogram, and performing histogram
equalization is more convenient and efficient, especially for tasks that require these operations
frequently or in real-time applications.

Page | 8
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 08-02-2024 Experiment:05

Aim: (a) Implement Gray level slicing (intensity level slicing)


(b) To read an 8-bit image and to see the effect of each bit on the image.
(c) To read an image and to extract 8 different planes i.e. bit plane slicing

Theory:

1. Theory of Gray Level Slicing (Intensity Level Slicing)


Gray level slicing, also known as intensity level slicing, is a technique used to
segment and isolate specific regions of interest in an image based on their pixel
intensity values. Here's the theory behind it:
Concept:
 In a grayscale image, each pixel has a value between 0 (black) and 255
(white), representing its intensity level.
 Gray level slicing defines a threshold or range of intensity values.
 Pixels falling within this range are "selected" (assigned a new value), while
those outside are left unchanged or assigned a different value.
Approaches:
 Thresholding: A single threshold value is defined. Pixels above the
threshold are set to one value (e.g., white), and those below are set to
another (e.g., black). This creates a binary image highlighting the object of
interest exceeding the threshold.
 Multiple thresholds: Several thresholds are defined, creating multiple
intensity regions with different assigned values. This allows for segmenting
multiple objects or features with different intensity ranges.
Applications:
 Object detection and segmentation: Isolating specific objects from the
background based on their intensity characteristics.
 Feature extraction: Highlighting specific image features with distinct
intensity signatures.

Page | 1
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 08-02-2024 Experiment:05

 Medical imaging: Extracting regions of interest like bones or tissues with


unique intensity ranges.
 Satellite imagery: Analyzing land cover based on pixel intensity
representing vegetation, water, etc.
Implementation:
 Programming languages offer image processing libraries with built-in
slicing functions.
 Manual implementation involves iterating through each pixel and
comparing its intensity value to the defined threshold(s).
Important points:
 Choosing the appropriate threshold(s) is crucial for accurate segmentation.
 Noise and uneven illumination can affect slicing results.
 Advanced techniques like adaptive thresholding can address uneven
lighting issues.
Further Exploration:
 Explore different thresholding algorithms like Otsu's method for automatic
threshold selection.
 Experiment with multiple thresholds and compare segmentation results.
 Consider combining slicing with other image processing techniques for
more sophisticated analysis.
2.Reading an 8-bit image involves understanding its representation and
interpreting the information stored in each bit. Here's a breakdown:
Representation:
 Each pixel in an 8-bit image is represented by a single byte (8 bits).
 This byte can represent either:

Page | 2
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 08-02-2024 Experiment:05

o Grayscale intensity: If it's a grayscale image, each bit signifies a


level of brightness, with 0 being black and 255 being white, resulting
in 256 possible shades (2 raised to the power of 8).
o Color information: If it's a color image, the byte is typically divided
among Red, Green, and Blue channels (e.g., 3-3-2 format with 3 bits
for red and green, 2 for blue), allowing for 256 shades for each color,
resulting in a palette of 256 * 256 * 256 = 16,777,216 colors.
Reading the image:
 Programming languages provide libraries or functions to read image files.
They access the file contents and interpret the bytes according to the image
format (e.g., PNG, JPEG).
 Each byte representing a pixel is then converted to its appropriate
interpretation (grayscale value or individual color component values).
Seeing the effect of each bit:
 Experimenting with manipulating individual bits can showcase their impact
on the image:
o Grayscale images:
 Set specific bits to 0 to see how they influence brightness
levels. For example, setting the least significant bit (LSB) to 0
will darken the pixel slightly, while setting all bits to 0 will
make it black.
 Incrementally change bit values to observe the smooth
gradation of brightness.
o Color images:
 Modify bits within specific channels (e.g., red, green, blue) to
see how they affect the overall color. Setting a channel's bits to
0 will remove that color component, resulting in different hues.
 Flip bits (0 to 1 and vice versa) to introduce color noise or
distortions.

Page | 3
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 08-02-2024 Experiment:05

Important notes:
 Modifying bits directly can be complex and might require specific image
processing tools.
 Changing certain bits might have unintended consequences due to
interactions with other bits and image formats.

3. Bit-Plane Slicing Theory: Extracting 8 Layers from an Image


Bit-plane slicing is a technique used to analyze and manipulate digital images by
isolating and examining individual bits within each pixel. Here's the theory behind
it:
Concept:
 In an 8-bit grayscale image, each pixel value ranges from 0 to 255,
represented by 8 binary bits (0s and 1s).
 Bit-plane slicing decomposes this single byte into 8 separate "bit planes,"
each containing only the information from a specific bit position (MSB to
LSB).
 Each bit plane becomes a binary image, where 0 represents the absence of
that specific bit's contribution and 1 represents its presence.
Visualizing the Effect:
 The Most Significant Bit (MSB) plane contributes the most to the overall
image intensity. Removing it leads to a significant darkening.
 Each subsequent plane contributes less detail and increasingly finer shades
of difference.
 Lower-order bit planes (especially LSB) can contain noise or compression
artifacts.
Applications:
 Image analysis: Studying specific features or details related to individual
bit planes.

Page | 4
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 08-02-2024 Experiment:05

 Image compression: Discarding less significant planes for data reduction


while maintaining essential information.
 Steganography: Hiding information within specific bit planes for secret
communication.
 Cryptography: Using bit planes for encryption and decryption processes.
Implementation:
 Programming languages offer libraries for image processing that typically
include bit-plane slicing functions.
 DIY implementations involve bitwise operations to isolate and extract
specific bit positions from each pixel.
Important points:
 Modifying bit planes directly can affect the image quality and introduce
artifacts.
 Understanding the context and application is crucial before manipulating bit
planes.
 Bit-plane slicing is a valuable tool for both image analysis and
manipulation, but careful consideration is necessary to avoid unintended
consequences.
Further Exploration:
 Explore image processing libraries/tools in your chosen programming
language.
 Look for tutorials and examples demonstrating bit-plane slicing
applications.
 Consider the ethical implications of using bit-plane slicing for
steganography.

Page | 5
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 08-02-2024 Experiment:05

PART: A
Code:
clc;
clear all;
close all;
I=imread('trees.tif');
imshow(I),figure();
title('Original image')
[x,y]=size(I);
histarr=zeros(1,256)
for i=1:x
for z=1:y
if I(i,z)>=70 && I(i,z)<=200;
I(i,z)=255;
end
end
end
imshow(I);

Output:

Page | 6
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 08-02-2024 Experiment:05

PART: B
Code:
clc;
clear all;
close all;
I=imread('trees.tif');
imshow(I);figure();
[x,y]=size(I);
B=bitget(I,1);subplot(3,3,1);
imshow(logical(B));
B1=bitget(I,2);subplot(3,3,2);
imshow(logical(B1));
B2=bitget(I,3);subplot(3,3,3);
imshow(logical(B2));
B3=bitget(I,4);subplot(3,3,4);
imshow(logical(B3));
B4=bitget(I,5);subplot(3,3,5);
imshow(logical(B4));
B5=bitget(I,6);subplot(3,3,6);
imshow(logical(B5));
B6=bitget(I,7);subplot(3,3,7);
imshow(logical(B6));

Page | 7
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 08-02-2024 Experiment:05

B7=bitget(I,8);subplot(3,3,8);
imshow(logical(B7));
out7=immultiply(B,1);
out6=immultiply(B1,2);
out5=immultiply(B2,4);
out4=immultiply(B3,8);
out3=immultiply(B4,16);
out2=immultiply(B5,32);
out1=immultiply(B6,64);
out=immultiply(B7,128);

finout1=imadd(out1,out);
finout2=imadd(finout1,out2);
finout3=imadd(finout2,out3);
finout4=imadd(finout3,out4);
finout5=imadd(finout4,out5);
finout6=imadd(finout5,out6);
finout7=imadd(finout6,out7);

subplot(3,3,9);
imshow(finout7);
Output:

Page | 8
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 08-02-2024 Experiment:05

PART: C
Code:
clc;
clear all;
close all;
I=imread('trees.tif');

[x,y]=size(I);
B=bitget(I,1);
B1=bitget(I,2);
B2=bitget(I,3);
B3=bitget(I,4);
B4=bitget(I,5)
B5=bitget(I,6);
B6=bitget(I,7);
B7=bitget(I,8);

Page | 9
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 08-02-2024 Experiment:05

out7=immultiply(B,1);
out6=immultiply(B1,2);
out5=immultiply(B2,4);
out4=immultiply(B3,8);
out3=immultiply(B4,16);
out2=immultiply(B5,32);
out1=immultiply(B6,64);
out=immultiply(B7,128);

finout1=imadd(out1,out);
finout1=imadd(finout1,out2);
finout1=imadd(finout1,out3);
finout1=imadd(finout1,out4);
finout1=imadd(finout1,out5);
finout1=imadd(finout1,out6);
finout1=imadd(finout1,out7);
subplot(3,3,1);
imshow(finout1);

finout1=imadd(out1,out);
finout1=imadd(finout1,out2);
finout1=imadd(finout1,out3);
finout1=imadd(finout1,out4);
finout1=imadd(finout1,out5);
finout1=imadd(finout1,out6);
subplot(3,3,2);
imshow(finout1);

finout1=imadd(out1,out);
finout1=imadd(finout1,out2);
finout1=imadd(finout1,out3);
finout1=imadd(finout1,out4);
finout1=imadd(finout1,out5);
finout1=imadd(finout1,out7);
subplot(3,3,3);
imshow(finout1);

finout1=imadd(out1,out);
finout1=imadd(finout1,out2);
finout1=imadd(finout1,out3);
finout1=imadd(finout1,out4);
finout1=imadd(finout1,out6);
finout1=imadd(finout1,out7);

Page | 10
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 08-02-2024 Experiment:05

subplot(3,3,4);
imshow(finout1);

finout1=imadd(out1,out);
finout1=imadd(finout1,out2);
finout1=imadd(finout1,out3);
finout1=imadd(finout1,out5);
finout1=imadd(finout1,out6);
finout1=imadd(finout1,out7);
subplot(3,3,5);
imshow(finout1);

finout1=imadd(out1,out);
finout1=imadd(finout1,out2);
finout1=imadd(finout1,out4);
finout1=imadd(finout1,out5);
finout1=imadd(finout1,out6);
finout1=imadd(finout1,out7);
subplot(3,3,6);
imshow(finout1);

finout1=imadd(out1,out);
finout1=imadd(finout1,out3);
finout1=imadd(finout1,out4);
finout1=imadd(finout1,out5);
finout1=imadd(finout1,out6);
finout1=imadd(finout1,out7);
subplot(3,3,7);
imshow(finout1);

finout1=out1;
finout1=imadd(finout1,out2);
finout1=imadd(finout1,out3);
finout1=imadd(finout1,out4);
finout1=imadd(finout1,out5);
finout1=imadd(finout1,out6);
finout1=imadd(finout1,out7);
subplot(3,3,8);
imshow(finout1);

finout1=out;
finout1=imadd(finout1,out2);
finout1=imadd(finout1,out3);
finout1=imadd(finout1,out4);
finout1=imadd(finout1,out5);

Page | 11
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 08-02-2024 Experiment:05

finout1=imadd(finout1,out6);
finout1=imadd(finout1,out7);
subplot(3,3,9);
imshow(finout1);

Output:

Conclusion:
Gray level slicing is a technique in image processing where specific ranges of pixel
intensities are selected and highlighted in the output image. By using gray level
slicing, we can effectively highlight regions of interest based on their intensity
levels. In an 8-bit image, each pixel is represented by 8 bits, allowing for 256
different intensity levels (0 to 255). we can see how changing individual bits alters
the pixel intensity and, consequently, the appearance of the image. Bit plane slicing
is a technique used to extract specific bit planes from the binary representation of
pixel intensities in an image.

Page | 12
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 26-03-2024 Experiment:07

Aim: To read an image and apply blurring effect and then apply
(1) Laplacian operator with center value positive and negative
(2) Composite Laplacian operator with center value positive and negative
(3) High boost filtering
Theory:

The Laplacian operator is a second-order differential operator commonly used in


image processing for edge detection and image sharpening. It is defined as the
sum of the second derivatives of a function with respect to its variables. In the
context of a 2D image, the Laplacian operator is applied to the image intensity
function to highlight areas of rapid intensity change, which often correspond to
edges.

A Laplacian operator with a positive center value and negative surrounding


values is designed to detect edges by emphasizing intensity changes. The
positive center value ensures that the operator responds to both positive and
negative changes in intensity, making it sensitive to edges in both directions. The
negative surrounding values help to suppress noise and enhance the edges
further.

Mathematically, a 3x3 kernel for a 2D Laplacian operator with a positive center


value and negative surrounding values can be represented as:

When this kernel is convolved with an image, it enhances edges by highlighting


regions with significant intensity changes. This makes it a useful tool in image
processing for tasks such as edge detection and image sharpening.

A composite Laplacian operator is a combination of multiple Laplacian operators


applied to a function. It is used to enhance specific features in an image or signal
by emphasizing certain spatial characteristics.

Page | 1
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 26-03-2024 Experiment:07

When the center value of a composite Laplacian operator is positive and the
surrounding values are negative, it indicates a focus on enhancing edges and
features that exhibit rapid intensity changes. This operator can be particularly
useful in edge detection and image sharpening tasks, as it highlights regions with
significant intensity gradients.

Mathematically, a composite Laplacian operator with a positive center value and


negative surrounding values can be represented as a sum of multiple Laplacian
operators, each with different weights assigned to them. This allows for a more
flexible and customizable approach to image enhancement, as different
combinations of Laplacian operators can be used to achieve specific effects.

High boost filtering is a technique used in image processing to enhance the


sharpness of an image. It works by emphasizing high-frequency components
(which correspond to edges and fine details) while suppressing low-frequency
components (which correspond to smooth areas).

The high boost filter is typically implemented by adding a fraction of the


Laplacian of the image to the original image.

The Laplacian operator is used to highlight the high-frequency components in


the image, which correspond to edges and fine details. By adding a scaled
version of the Laplacian back to the original image, the edges are enhanced,
resulting in a sharper appearance.

High boost filtering is commonly used in image processing applications where


sharpness enhancement is desired, such as in medical imaging, satellite imaging,
and digital photography. However, care must be taken to avoid amplifying noise,
as high boost filtering can also enhance noise along with the edges.

Algorithm:
 Step1: Read an image using imread command.
 Step2: Convert to grayscale if needed using rgb2gray().
 Step3: Create an empty blurred image using command ones(), and apply averaging
mask blur the image.
 Step4: Define the Laplacian mask for center value of 4 and 8.

Page | 2
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 26-03-2024 Experiment:07

 Step5: Apply this Laplacian filter using convolution.


 Step6: Display the results of Laplacian filter using imshow() function.
 Step7: Define the Composite Laplacian mask for center value of 4 and 8.
 Step8: Apply this Composite Laplacian filter using convolution.
 Step9: Display the results of Laplacian filter using imshow() function.
 Step10: Create a high-boost filtered image by adding A times the difference between
the
 Original image and its average filter version.
 Step11: Display original and high-boost filtered images for different A values.
Code:
clc;
clear all;
close all;

%% Read the image


img = imread('trees.tif');

%% Blur masking
blurKernel = 1/9 * ones(3, 3);

%% image dimensions
[rows, cols, ~] = size(img);
blurredImage = uint8(zeros(rows, cols, 3));

%% Blurring image
for i = 2:rows-1
for j = 2:cols-1
for k = 1:3
blurredImage(i,j,k) = sum(sum(double(img(i-1:i+1,j-1:j+1)) .*
blurKernel));
end
end
end

%% Display the blurred image


subplot(2,1,1);
imshow(img);
title('Orginal Image');

subplot(2,1,2);
imshow(rgb2gray(blurredImage));
title('Blurred Image');

%% Apply Laplacian filter


grayImage = rgb2gray(blurredImage);
laplacian_Positive = [0 -1 0; -1 4 -1; 0 -1 0];

Page | 3
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 26-03-2024 Experiment:07

laplacian_Negative = [0 1 0; 1 -4 1; 0 1 0];
laplacianImagePositive = conv2(double(grayImage), laplacian_Positive);
laplacianImageNegative = conv2(double(grayImage), laplacian_Negative);

figure;
subplot(2, 3, 1);
imshow(grayImage);
title('Original Image');

subplot(2, 3, 2);
imshow(uint8(abs(laplacianImagePositive)));
title('Laplacian Filter (Positive Center)(ceneter=4)');

subplot(2, 3, 3);
imshow(uint8(abs(laplacianImageNegative)));
title('Laplacian Filter (Negative Center)(center=4)');

laplacian_Positive = [-1 -1 -1; -1 8 -1; -1 -1 -1];


laplacian_Negative = [1 1 1; 1 -8 1; 1 1 1];
laplacianImagePositive = conv2(double(grayImage), laplacian_Positive);
laplacianImageNegative = conv2(double(grayImage), laplacian_Negative);

subplot(2, 3, 4);
imshow(grayImage);
title('Original Image');

subplot(2, 3, 5);
imshow(uint8(abs(laplacianImagePositive)));
title('Laplacian Filter (Positive Center)(center=8)');

subplot(2, 3, 6);
imshow(uint8(abs(laplacianImageNegative)));
title('Laplacian Filter (Negative Center)(center=8)');

%% Apply Composite lap;acian Filter


grayImage = rgb2gray(blurredImage);
com_lap_Positive = [-1 -1 -1; -1 9 -1; -1 -1 -1];
com_lap_Negative = [1 1 1; 1 -9 1; 1 1 1];
cl_pos_img = conv2(double(grayImage), com_lap_Positive);
cl_neg_img = conv2(double(grayImage), com_lap_Negative);

figure;
subplot(2, 3, 1);
imshow(grayImage);
title('Original Image');

subplot(2, 3, 2);
imshow(uint8(abs(cl_pos_img)));
title('Composite Laplacian Filter (Positive Center)(center=9)');

subplot(2, 3, 3);

Page | 4
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 26-03-2024 Experiment:07

imshow(uint8(abs(cl_neg_img)));
title('Composite Laplacian Filter (Negative Center)(center=9)');

com_lap_Positive = [0 -1 0; -1 5 -1; 0 -1 0];


com_lap_Negative = [0 1 0; 1 -5 1; 0 1 0];
cl_pos_img = conv2(double(grayImage), com_lap_Positive);
cl_neg_img = conv2(double(grayImage), com_lap_Negative);

subplot(2, 3, 4);
imshow(grayImage);
title('Original Image');

subplot(2, 3, 5);
imshow(uint8(abs(cl_pos_img)));
title('Composite Laplacian Filter (Positive Center)(center=5)');

subplot(2, 3, 6);
imshow(uint8(abs(cl_neg_img)));
title('Composite Laplacian Filter (Negative Center)(center=5)');

%% Apply High Boost Filter


grayImage = rgb2gray(blurredImage);

A = 1.5;
highBoostedImage = double(grayImage) + A * (double(grayImage) -
double(imfilter(grayImage, fspecial('average', 3), 'replicate')));

figure;
subplot(2, 2, 1);
imshow(grayImage);
title('Original Image');

subplot(2, 2, 2);
imshow(uint8(highBoostedImage));
title('High Boost Filtered Image (A=1.5)');

A = 1.2;
highBoostedImage = double(grayImage) + A * (double(grayImage) -
double(imfilter(grayImage, fspecial('average', 3), 'replicate')));

subplot(2, 2, 3);
imshow(grayImage);
title('Original Image');

subplot(2, 2, 4);
imshow(uint8(highBoostedImage));
title('High Boost Filtered Image (A=1.2)');

Page | 5
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 26-03-2024 Experiment:07

Output:

Page | 6
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 26-03-2024 Experiment:07

Conclusion:
This project aimed to demonstrate image processing techniques. The blurring effect
was applied to smooth the image, followed by the Laplacian operator for edge
detection, composite Laplacian for customized effects, and high boost filtering for
sharpness enhancement. These methods showcase the versatility and utility of image
enhancement techniques.

Page | 7
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-04-2024 Experiment:07

Aim: Noise model for Image restoration

Implement various noise models and their


Histogram

Noise models are


Gaussian
Rayleigh
Erlang
Salt and Pepper
Exponential
Uniform

Theory:
Noise models are essential in understanding and simulating various types of noise
that can affect signals or data in communication systems or image processing.
Each noise model has distinct characteristics that can help in analyzing and
processing noisy signals or images. Here's a brief overview of some common noise
models:
1. Gaussian Noise: Also known as white noise, it is characterized by a probability
density function (PDF) that follows a Gaussian distribution. It is commonly used
to model thermal noise in electronic systems.
2. Rayleigh Noise: This noise model is often used to describe the amplitude of
signals that have passed through a dispersive medium or encountered multipath
fading. It is characterized by a PDF that is proportional to the square of the
amplitude and an exponential term.
3. Erlang Noise: Erlang noise is a generalization of the exponential distribution
and is often used to model queuing processes. It is characterized by a PDF that
describes the time between events in a Poisson process with a rate parameter.
4. Salt and Pepper Noise: This type of noise is commonly seen in images and is
characterized by random occurrences of very bright (salt) or very dark (pepper)
pixels. It is often caused by errors in data transmission or storage.

Page | 1
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-04-2024 Experiment:07

5. Exponential Noise: Similar to the Erlang distribution, exponential noise is


characterized by a PDF that describes the time between events in a Poisson
process. It is often used to model waiting times in queuing systems.
6. Uniform Noise: This noise model assumes that the noise values are uniformly
distributed between a minimum and maximum value. It is often used in signal
processing applications where noise levels are relatively constant.
Histograms are useful tools for visualizing the distribution of noise in a signal or
image. By plotting the frequency of occurrence of different intensity levels,
histograms can provide insights into the characteristics of noise and help in
developing strategies to remove or reduce its impact.

Algorithm:
Step1: Read an image using imread command.
Step2: Using function imnoise() apply the noise like guassian, rayliegh, erlang,
uniform, salt & pepper and exponential.
Step3: Plot the images with the noise.
Step4: Plot the histograms for these noisy image using imhist().
Step5: Calculate the Probability Distribution Function (PDF) for all noisy images.
Step6: Plot the PDF for all noisy images.
Code:
clc;
clear all;
close all;
a=imread('F:\PD\Z Drive\IP\ip_noise_test.png');
a=rgb2gray(a);
a=double(a);
b=size(a);
%noisy_image=imnoise(a,'salt & pepper');

Page | 2
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-04-2024 Experiment:07

%adding uniform noise to an image


[r c]=size(a);
p=0;
q=1;
R=p+(q-p)*rand(r,c); %uniform
mmax=max(max(R));
mmin=min(min(R));
const=100/(mmax-mmin);
for x=1:1:r
for y=1:1:c
nu(x,y)=const*(R(x,y)-mmin);
end
end
noisy_image=a+nu;
figure;
subplot(1,3,1);
imshow(uint8(a));
title('Original image');
subplot(1,3,2);
imhist(uint8(noisy_image));
title('Histogram of uniform noise image');
subplot(1,3,3);
imshow(uint8(noisy_image));
title('Original image with uniform noise');

Page | 3
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-04-2024 Experiment:07

% adding rayleigh noise to an image


Rr=p+(-q*log(1-rand(r,c))).^0.5; %rayleigh
mmax=max(max(Rr));
mmin=min(min(Rr));
const=100/(mmax-mmin);
for x=1:1:r
for y=1:1:c
nr(x,y)=const*(Rr(x,y)-mmin);
end
end
noisy_imager=a+nr;
figure;
subplot(1,3,1);
imshow(uint8(a));
title('Original image');
subplot(1,3,2);
imhist(uint8(noisy_imager));
title('Histogram of rayleigh noise image');
subplot(1,3,3);
imshow(uint8(noisy_imager));
title('Original image with rayleigh noise');
%adding exponential noise to an image
Re=-log(1-rand(r,c)); %exponential

Page | 4
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-04-2024 Experiment:07

mmax=max(max(Re));
mmin=min(min(Re));
const=100/(mmax-mmin);
for x=1:1:r
for y=1:1:c
ne(x,y)=const*(Re(x,y)-mmin);
end
end
noisy_imagee=a+ne;
figure;
subplot(1,3,1);
imshow(uint8(a));
title('Original image');
subplot(1,3,2);
imhist(uint8(noisy_imagee));
title('Histogram of image with exponential
noise');
subplot(1,3,3);
imshow(uint8(noisy_imagee));
title('Original image with exponential noise');
%adding erlang noise to an image
e=2;
f=5;
k=-1/e;

Page | 5
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-04-2024 Experiment:07

Rer=zeros(r ,c);
for j=1:f
Rer=Rer+k*log(1-rand(r,c));
end
mmax=max(max(Rer));
mmin=min(min(Rer));
const=100/(mmax-mmin);
for x=1:1:r
for y=1:1:c
noiseer(x,y)=const*(Rer(x,y)-mmin);
end
end
noisy_imageer=a+noiseer;
figure;
subplot(1,3,1);
imshow(uint8(a));
title('Original image');
subplot(1,3,2);
imhist(uint8(noisy_imageer));
title('Histogram of image with erlang noise');
subplot(1,3,3);
imshow(uint8(noisy_imageer));
title('Original image with erlang noise');
%adding gaussian noise to an image

Page | 6
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-04-2024 Experiment:07

mu = input('Enter the value of mu');


sigma =input('Enter the value of sigma');
noise = a + normrnd(mu,sigma, b);
figure;
subplot(1,3,1);
imshow(uint8(a));
title('Original image');
subplot(1,3,2);
imhist(uint8(noise));
title('Histogram of image with guassian noise');
subplot(1,3,3);
imshow(uint8(noise));
title('Image with guassian noise');

% adding salt and pepper noise


p_salt = .05; %// probability of salt
p_pepper = .01; %// probability of pepper
if strcmp(class(a),'uint8')
salt_value = uint8(255);
else
salt_value = 1;
end
pepper_value = 0;
aux = rand(b); %// generate random values

Page | 7
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-04-2024 Experiment:07

a(aux<=p_salt) = salt_value; %// add salt


a((aux>p_salt) & (aux<=p_salt+p_pepper)) =
pepper_value; %// add pepper
figure;
subplot(1,2,1);
imhist(uint8(a));
title('Histogram of image with salt and pepper noise');
subplot(1,2,2);
imshow(uint8(a)); %// show image
title('Image with salt and pepper noise');

Output:

Page | 8
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-04-2024 Experiment:07

Page | 9
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-04-2024 Experiment:07

Conclusion:
We analyzed the histograms of different noise models provides a clear visualization
of their distributions, aiding in the selection of appropriate noise models for specific
applications and in developing effective noise reduction strategies.

Page | 10
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:08

Aim: Image Morphological operations


Write a MATLAB program for erosion and dilation and opening & closing using
inbuilt and without inbuilt function and also for Hit and Miss Operation

Theory:
Erosion and dilation are fundamental operations in image processing,
particularly in the field of morphological image processing. They are used to
manipulate the shapes and sizes of objects in an image. Here's a breakdown of
their concepts and how they differ:
Erosion:
 Concept: Erosion shrinks or thins the foreground objects in an image.
Imagine sliding a small structuring element (a shape like a square or
circle) over the image. A pixel in the original image is considered part of
the eroded image only if the structuring element completely fits on top of
it, and all corresponding pixels in the structuring element align with
foreground pixels in the image. This removes pixels at object boundaries
and small protrusions.
 Effect: Erosion reduces the size of foreground objects, removes noise and
small details, and separates touching objects.
 Applications: Erosion can be used for:
o Feature extraction (finding edges by eroding away irrelevant details)
o Object segmentation (separating connected objects)
o Noise reduction (removing small isolated bright or dark spots)
Dilation:
 Concept: Dilation expands or thickens the foreground objects in an image.
Similar to erosion, we slide a structuring element over the image. A pixel
is considered part of the dilated image if at least one pixel in the
structuring element overlaps with a foreground pixel in the original image.
This adds pixels to the boundaries of objects and fills small holes within
them.

Page | 1
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:08

 Effect: Dilation increases the size of foreground objects, connects narrow


breaks between objects, and fills small holes.
 Applications: Dilation can be used for:
o Feature extraction (thickening edges for better visibility)
o Object segmentation (filling gaps between objects)
o Closing small holes in objects
Opening and Closing:
Opening and closing are morphological operations that combine erosion and
dilation to achieve specific effects:
 Opening: Erosion followed by dilation. This removes small objects and
protrusions while preserving the general shape of larger objects. It acts
like an "opening" that lets small things pass through but retains larger
structures.
 Closing: Dilation followed by erosion. This fills small holes in objects
while preserving their general shape. It acts like "closing" gaps in objects
to make them more solid.
Applications of Opening and Closing:
 Opening: Used for:
o Noise reduction (removing small isolated objects)
o Feature extraction (separating touching objects)
o Morphological filtering (removing small protrusions)
 Closing: Used for:
o Removing small holes in objects
o Connecting narrow breaks
o Smoothing object boundaries

Page | 2
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:08

Choosing the Right Operation:


The choice between erosion, dilation, opening, or closing depends on the specific
image processing task you're trying to achieve. Consider the desired outcome:
 To remove small objects and noise: Use erosion.
 To enlarge objects and fill small holes: Use dilation.
 To separate touching objects and remove small protrusions: Use opening.
 To fill small holes in objects and smooth boundaries: Use closing.
Remember that these operations can be combined sequentially to achieve
complex image manipulations. By understanding their effects, you can leverage
them effectively in your image processing projects.

Algorithm:
1: Read an image using imread command.
2: Using strel() command, set the width you want to increase or decrease.
3: Apply erosion using the inbuilt command imerod().
4: Apply dilution using the inbuilt command imdilate().
5: Apply opening using the inbuilt command imopen().
6: Apply closing using the inbuilt command imclose().
7: Plot all the images using subplot and imshow() commands.

Code:
clc;
clear all;
close all;

%% Reading the image.


i = imread('C:\Users\Priyanshi\Desktop\image1.png');

%% Morphological Operations
%% imerode() function.
se = strel('disk',11);
erodedBW = imerode(i,se);

Page | 3
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:08

subplot(1,5,1);
imshow(i);
title('Original Image');

subplot(1,5,2);
imshow(erodedBW);
title('Edge Thikness increaed');

%% imdilate() function.
dilateImage = imdilate(i,se);

subplot(1,5,3);
imshow(dilateImage);
title('Edge Thikness decreased');

%% imopen() function.
openImage = imopen(i,se);

subplot(1,5,4);
imshow(openImage);
title('Opening of image');

%% imopen() function.
closeImage = imclose(i,se);

subplot(1,5,5);
imshow(closeImage);
title('Closing of image');

Output:

Page | 4
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:08

Conclusion:
By applying the erosion, we have observed that the darker portion being thick compare to
original image. Dilution showed that the darker portion’s thickness is decreased compare
to the original. Opening is kind of similar to the erosion bur here we are not having
merging of the shapes. And closing of the image decreasing the thickness as much so that
the connection line in the image just disappeared but shapes remain almost same.

Page | 5
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:09

Aim: Image segmentation practical


Effect of Different Mask (Sobel, Prewitt and Roberts, Canny and Log ) on
Edges of square with diagonals, as shown in figure (plot it using MATLAB
commands) Also apply gaussian noise and then apply various edge operators and
comment on result

Theory:
The Sobel, Prewitt, Roberts, Canny, and Laplacian of Gaussian (LoG) edge
detection masks are commonly used in image processing to detect and enhance
the edges in an image. Each of these masks has its own unique characteristics
and effects on the edges of an image.
1. Sobel Operator:
- The Sobel operator is a discrete differentiation operator that approximates the
gradient of the image intensity function.
- It is sensitive to both horizontal and vertical edges, and it produces thicker
edges compared to other operators.
- When applied to a square with diagonals, the Sobel operator will highlight
the edges of the square, including the diagonals, but the edges may appear
slightly thicker and more pronounced.
2. Prewitt Operator:
- The Prewitt operator is similar to the Sobel operator, but it uses a slightly
different kernel.
- It is also sensitive to both horizontal and vertical edges, but it tends to
produce thinner edges compared to the Sobel operator.
- When applied to a square with diagonals, the Prewitt operator will also
highlight the edges of the square, including the diagonals, but the edges may
appear slightly thinner compared to the Sobel operator.
3. Roberts Operator:
- The Roberts operator is a simple and fast edge detection algorithm that uses a
2x2 kernel.

Page | 1
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:09

- It is sensitive to diagonal edges, and it produces thinner edges compared to


the Sobel and Prewitt operators.
- When applied to a square with diagonals, the Roberts operator will primarily
highlight the diagonal edges, while the horizontal and vertical edges may be less
pronounced.
4. Canny Edge Detector:
- The Canny edge detector is a more sophisticated algorithm that involves
multiple s, including smoothing, gradient calculation, non-maximum
suppression, and hysteresis.
- It is able to detect both strong and weak edges, and it can produce thinner and
more accurate edge representations.
- When applied to a square with diagonals, the Canny edge detector will
highlight the edges of the square, including the diagonals, with a high degree of
accuracy and detail.
5. Laplacian of Gaussian (LoG) Operator:
- The LoG operator is a two- process that involves first applying a Gaussian
filter to smooth the image, and then applying the Laplacian operator to detect
edges.
- It is sensitive to both and roof edges, and it can produce thin and well-
defined edge representations.
- When applied to a square with diagonals, the LoG operator will highlight the
edges of the square, including the diagonals, with a high degree of accuracy and
detail, similar to the Canny edge detector.
In summary, the different edge detection masks will have varying effects on the
edges of a square with diagonals. The Sobel and Prewitt operators will produce
thicker edges, while the Roberts operator will primarily highlight the diagonal
edges. The Canny and LoG operators will provide the most accurate and detailed
edge representations, including the diagonal edges of the square.

Page | 2
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:09

let's explore the application of Gaussian noise to a square with diagonals and
then apply various edge detection operators to observe the results.
1. Adding Gaussian Noise:
 Gaussian noise is a type of electronic noise that has a normal
(Gaussian) distribution of random values.
 When applied to an image, it can introduce random variations in
pixel intensities, simulating the effect of sensor noise or other
environmental factors.
 Adding Gaussian noise to the square with diagonals will introduce
random variations in the pixel values, making the edges less distinct
and more difficult to detect.
Algorithm:
1: Read an image using imread command.
2: Convert to grayscale if needed using rgb2gray().
3: Add Gaussian noise using imnoise() command.
4: Apply Roberts filter using edge() command.
5: Apply Prewitt filter using edge() command.
6: Apply Sobel filter using edge() command.
7: Apply LOG filter using edge() command.
8: Apply Canny filter using edge() command.
9: Show the resultant images.

Code:
clc;
clear all;
close all;

%% Read the input image


img = imread('pears.png');

%% Convert the image to grayscale if it's not already


if size(img, 3) == 3
img = rgb2gray(img);
end

Page | 3
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:09

%% Apply Noise
noisyImage = imnoise(img, 'Gaussian', 0.05);
subplot(2,3,1);
imshow(noisyImage);
title('Noisy Image');

%% Apply Roberts filter


roberts = edge(img, 'roberts');
subplot(2,3,2);
imshow(roberts);
title('Roberts Filter');

%% Apply Prewitt filter


prewitt = edge(img, 'prewitt');
subplot(2,3,3);
imshow(prewitt);
title('Prewitt Filter');

%% Apply Sobel filter


sobel = edge(img, 'sobel');
subplot(2,3,4);
imshow(sobel);
title('Sobel Filter');

%% Apply Laplacian of Gaussian filter


log = edge(img, 'log');
subplot(2,3,5);
imshow(log);
title('Laplacian of Gaussian Filter');

%% Apply Canny filter


canny = edge(img, 'canny');
subplot(2,3,6);
imshow(canny);
title('Canny Filter');

Page | 4
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:09

Output:

Conclusion:
the different edge detection operators have varying effects on the edges of a square
with diagonals, both with and without the presence of Gaussian noise. The Canny
edge detector and the LoG operator generally provide the most accurate and well-
defined edge representations, making them more suitable for applications where
edge detection is critical, even in the presence of noise.

Page | 5
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:10

Aim: Count the object


Write an algorithm to count number of object in image. Also check efficiency of
your algorithm by varying different dependent parameters.

Theory:
To count the number of objects in an image, you can utilize various image
processing and computer vision techniques. Here's a comprehensive breakdown
of the theoretical concepts involved:
1. Image Preprocessing:
- Grayscale Conversion: Convert the RGB image into a grayscale image to
simplify the subsequent processing s.
- Noise Reduction: Apply techniques like Gaussian blurring to reduce noise and
smoothen the image.
2. Thresholding:
- Global Thresholding: Determine a global threshold value to create a binary
image, where pixels are classified as either object or background.
- Adaptive Thresholding: In scenarios where lighting conditions vary across the
image, adaptive thresholding is employed to determine the threshold for each local
region.
3. Contour Detection:
- Utilize contour detection algorithms to identify and extract the contours or
boundaries of objects in the binary image.
4. Object Counting:
- Counting Contours: Calculate the number of contours detected, which
corresponds to the number of distinct objects in the image.
5. Machine Learning Techniques (Optional):
- Object Detection Models: Utilize pre-trained object detection models such as
YOLO (You Only Look Once) or SSD (Single Shot MultiBox Detector) for
accurate and efficient object counting.

Page | 1
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:10

6. Deep Learning Techniques (Optional):


- Convolutional Neural Networks (CNN): Train a CNN on a large dataset of
labeled images to perform object counting through regression or classification
tasks.
7. Post-Processing:
- Filtering: Optionally, apply morphological operations like erosion and dilation
to refine the object boundaries and remove any extraneous artifacts.
8. Evaluation and Validation:
- Ground Truth Comparison: Compare the computed count with the ground truth
labels to assess the accuracy of the object counting algorithm.
9. Application-Specific Considerations:
- Depending on the specific application, additional considerations such as scale
invariance, rotation invariance, and occlusion handling may need to be
incorporated into the object counting framework.
By integrating these theoretical concepts into a practical implementation, you can
effectively count the number of objects within an image using image processing
and computer vision techniques.

When evaluating the efficiency of an algorithm for counting the number of objects
in an image, several dependent parameters can be varied to assess its performance.
Here's a detailed breakdown on the parameters to consider:
1. Image Resolution:
- Vary the resolution of the input image to evaluate the algorithm's scalability
and robustness to images of different sizes.
2. Noise Levels:
- Introduce varying levels of noise in the input image to test the algorithm's
resilience to noise and its ability to accurately count objects in noisy environments.

Page | 2
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:10

3. Object Size and Scale:


- Modify the size and scale of objects within the image to assess the algorithm's
capability to handle objects of different dimensions.
4. Lighting Conditions:
- Adjust the lighting conditions in the image to test the algorithm's performance
under varying illumination levels and shadows.
5. Object Density:
- Vary the density of objects within the image to evaluate the algorithm's
accuracy in counting objects within cluttered scenes.
6. Object Occlusion:
- Introduce varying levels of object occlusion to test the algorithm's ability to
identify partially occluded objects and accurately count them.
7. Color Spaces and Image Types:
- Experiment with different color spaces (RGB, HSV, etc.) and image types
(grayscale, binary) to assess the algorithm's adaptability to diverse image
representations.
8. Algorithm Parameters:
- Adjust the parameters of the image processing and computer vision algorithms
utilized for object counting, such as threshold values, contour detection
parameters, and noise reduction parameters.
9. Runtime Performance:
- Measure the algorithm's execution time for counting objects in images of
different complexities to assess its computational efficiency.
10. Evaluation Metrics:
- Utilize metrics such as precision, recall, F1 score, and accuracy to
quantitatively evaluate the algorithm's performance across the varied parameters.

Page | 3
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:10

By systematically varying these dependent parameters and evaluating the


algorithm's performance, you can comprehensively assess its efficiency and
robustness in counting the number of objects in images across diverse scenarios.
Algorithm:
 Read the input image
 Convert the image to grayscale
 Apply thresholding to create a binary image
 Perform noise reduction using morphological operations
 Label connected components in the binary image
 Count the number of labeled objects
 Display the labeled image and the count of objects

Code:
%% Read the image
image = imread('circles.png');
%% Convert the image to grayscale
if size(image, 3) == 3
image = rgb2gray(image);
end
%% Threshold the image to create a binary image
threshold = graythresh(image);
binaryImage = imbinarize(image, threshold);
%% Fill any holes in the binary image
binaryImage = imfill(binaryImage, 'holes');
%% Perform connected component analysis (CCA)
cc = bwconncomp(binaryImage);
numObjects = cc.NumObjects;
%% Display the original image and the binary image with detected
objects
subplot(1, 2, 1);
imshow(image);
title('Original Image');
subplot(1, 2, 2);
imshow(binaryImage);
title(['Binary Image with ', num2str(numObjects), ' objects']);
%% Display the count
disp(['Number of objects: ', num2str(numObjects)]);

Page | 4
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 13-04-2024 Experiment:10

Output:

Conclusion:
This rule-based algorithm offers a fast and effective solution for counting objects in
controlled environments. However, its accuracy can be limited for complex images
with overlapping or touching objects, significant background variations, or non-
uniform illumination. Deep learning methods provide a more robust solution for
such scenarios but require substantial training data and computational resources.

Page | 5
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 10-04-2024 Experiment:11

Aim: Denoising filter for image restoration


To read an image and apply Arithmetic mean filter,
Geometric mean filter, Harmonic mean filter and contra
harmonic mean filter.

Theory:
The theory of denoising filters for image restoration is a fundamental concept in
the field of digital image processing. Denoising filters are designed to remove
unwanted noise or artifacts from digital images, while preserving the underlying
image features and details.
The main idea behind denoising filters is to exploit the statistical properties of the
noise and the image signal to separate the two and effectively remove the noise
component. The theory of denoising filters is based on the following key
principles:
1. Noise Model:
- Denoising filters assume a particular noise model, such as additive white
Gaussian noise (AWGN), Poisson noise, or speckle noise, depending on the image
acquisition process and the nature of the noise.
- The noise model helps in understanding the statistical properties of the noise,
which are then used to design the denoising filter.
2. Image Priors:
- Denoising filters often incorporate prior knowledge about the properties of the
underlying image, such as smoothness, sparsity, or texture characteristics.
- These image priors help in distinguishing the desired image signal from the
noise component, enabling more effective denoising.
3. Filtering Techniques:
- Denoising filters can be implemented using various techniques, such as linear
filters (e.g., Gaussian, median, Wiener), nonlinear filters (e.g., bilateral,
anisotropic diffusion), and transform-domain filters (e.g., wavelet, sparse coding).

Page | 1
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 10-04-2024 Experiment:11

- The choice of the filtering technique depends on the noise characteristics,


image properties, and the desired level of complexity and performance.
4. Optimization Frameworks:
- Denoising can be formulated as an optimization problem, where the goal is to
find the optimal image estimate that minimizes a defined cost function or loss
function.
- The cost function typically includes terms that account for the noise model,
image priors, and the desired properties of the denoised image.
- Optimization techniques, such as variational methods, sparse optimization, or
deep learning-based approaches, can be employed to solve the denoising problem.
5. Evaluation Metrics:
- The performance of denoising filters is often evaluated using quantitative
metrics, such as peak signal-to-noise ratio (PSNR), structural similarity index
(SSIM), or visual information fidelity (VIF).
- These metrics provide a numerical measure of the quality of the denoised image
compared to the ground truth or reference image.
The theory of denoising filters is a dynamic and evolving field, with ongoing
research exploring new techniques, incorporating advanced image priors, and
leveraging the power of machine learning and deep learning for more effective
image restoration.
Algorithm:
 Step1: Read an image using imread command.
 Step2: Convert to grayscale if needed using rgb2gray().
 Step3: Add Gaussian noise using imnoise() command.
 Step4: Apply Arithmetic filter using imfilter() and fspecial() command.
 Step5: Apply Geometric filter.
 Step6: Apply Harmonic mean filter.
 Step7: Apply Contra Harmonic filter.
 Step8: Plot the resulting images.

Page | 2
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 10-04-2024 Experiment:11

Code:
clc;
close all;
clear all;

%% Create a sample image


originalImage = imread('trees.tif');
subplot(2,3,1);
imshow(originalImage);
title('Original Image');

%% Add noise to the image


noisyImage = imnoise(originalImage, 'Gaussian', 0.05);
subplot(2,3,2);
imshow(noisyImage);
title('Noisy Image');

%% Define filter sizes


filterSize = [3, 3]; % Filter size for mean filters
q = 1.5; % Q parameter for contra harmonic mean filter

%% Apply Arithmetic Mean Filter


arithmeticFiltered = imfilter(noisyImage,
fspecial('average', filterSize));
subplot(2,3,3);
imshow(arithmeticFiltered);
title('Arithmetic Mean Filtered Image');

%% Apply Geometric Mean Filter


geometricFiltered = exp(imfilter(log(double(noisyImage)
+ eps), fspecial('average', filterSize), 'replicate'));
geometricFiltered = uint8(geometricFiltered);
subplot(2,3,4);
imshow(geometricFiltered);
title('Geometric Mean Filtered Image');

%% Apply Harmonic Mean Filter

Page | 3
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 10-04-2024 Experiment:11

harmonicFiltered = 1 ./ imfilter(1./(double(noisyImage)
+ eps), fspecial('average', filterSize));
harmonicFiltered = uint8(harmonicFiltered);
subplot(2,3,5);
imshow(harmonicFiltered);
title('Harmonic Mean Filtered Image');

%% Apply Contra Harmonic Mean Filter


contraHarmonicFiltered =
imfilter(double(noisyImage).^(q+1), fspecial('average',
filterSize))./(imfilter(double(noisyImage).^q,
fspecial('average', filterSize)) + eps);
contraHarmonicFiltered = uint8(contraHarmonicFiltered);
subplot(2,3,6);
imshow(contraHarmonicFiltered);
title('Contra Harmonic Mean Filtered Image');

Output:

Page | 4
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 10-04-2024 Experiment:11

Conclusion:
the choice of mean filter depends on the specific characteristics of the noise and the
desired outcome. While Arithmetic Mean Filter is simple and effective for general
noise reduction, Geometric Mean Filter is better at preserving edges. Harmonic
Mean Filter and Contra harmonic Mean Filter can be useful for specific types of
noise but require careful parameter selection to avoid undesirable effects.

Page | 5
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-01-2024
Assignment:01
Question: Convert any Gray Scale Image into RGB image without using inbuilt
commands

Code:

i = imread('Desktop/image.jpg');
grayImage = rgb2gray(i);

%% Get image dimensions:


[rows, cols] = size(grayImage);

%% Create an empty RGB image:


rgbImage = zeros(rows, cols, 3);

%% Loop through each pixel and assign RGB values:


for i = 1:rows
for j = 1:cols
grayValue = grayImage(i, j);

%% Choose a colormap manually (adjust as needed):


if grayValue <= 64
rgbImage(i, j, 1) = 0; % Red
rgbImage(i, j, 2) = 0; % Green
rgbImage(i, j, 3) = 255 * grayValue / 64; % Blue
elseif grayValue <= 128
rgbImage(i, j, 1) = 0; % Red
rgbImage(i, j, 2) = 255* (grayValue-64) / 64; % Green
rgbImage(i, j, 3) = 0; % Blue
else
rgbImage(i, j, 1) = 255 *(grayValue-128) / 128; % Red
rgbImage(i, j, 2) = 0; % Green
rgbImage(i, j, 3) = 255 - 255*(grayValue-128)/128;% Blue
end
end
end

imshow(grayImage);
figure;
imshow(rgbImage);

Page | 1
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-01-2024
Assignment:01
Output:

Page | 2
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 09-01-2024
Assignment:01
Working principle:
Here firstly we have converted an RGB image into gray scale. Map the rows and
columns as per the size of the gray scaled image. Then we have created one empty
RGB image which have all the pixel value as zero. According to the gray value of
the gray scaled image we have divided image into three different part as gray value
<= 64, gray value <= 128, gray value <= 255 and adjusted the RED, GREEN and
BLUE shades according to the need of the image. After applying the RGB shades
we have got our final RGB image.
Conclusion:
Here we have observed that we can convert any grayscale image into RGB image
without using in built command. We can use this technique where we need RGB
image as the output but the grayscale image for processing. This won't give the exact
color as the original image but it provides a visual representation of RGB image.

Page | 3
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-01-2024
Assignment:02
Question:

(1) Identification of Number plate and (2) Detection of Speed from moving vehicle

Code:

PART 1:

%% Reading An image ploting image


a=imread(uigetfile('.jpg'));
a=rgb2gray(a);
figure;
imshow(a);
title('car');
[r c p]=size(a);
b=a(r/3:r,1:c);
imshow(b);
title('LP AREA')
[r c p]=size(b);
Out=zeros(r,c);
for i=1:r
for j=1:c
if b(i,j)>150
Out(i,j)=1;
else
Out(i,j)=0;
end
end
end

%% load Out;
BW3 = bwfill(Out,'holes');
BW3=medfilt2(BW3,[4 4]);
BW3=medfilt2(BW3,[4 4]);
BW3=medfilt2(BW3,[4 4]);
BW3=medfilt2(BW3,[5 5]);
BW3=medfilt2(BW3,[5 5]);
figure;imshow(BW3,[]);
BW3 = bwfill(BW3,'holes');
[L num]=bwlabel(BW3);
STATS=regionprops(L,'all');
Page | 1
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-01-2024
Assignment:02
disp(num);

%% close all;
cc=[];
removed=0;
for i=1:num
dd=STATS(i).Area;
cc(i)=dd;
if (dd < 50000)
L(L==i)=0;
removed = removed + 1;
num=num-1;
end
end
[L2 num2]=bwlabel(L);
figure,imshow(L2);
STATS = regionprops(L2,'All');
if num2>2
for i=1:num2
aa= STATS(i).Orientation;
if aa > 0
imshow(L==i);
end
end
disp('exit');
end
[r c]=size(L2);
Out=zeros(r,c);
k=1;
B=STATS.BoundingBox;
Xmin=B(2);
Xmax=B(2)+B(4);
Ymin=B(1);
Ymax=B(1)+B(3);
LP=[];
LP=b(Xmin+25:Xmax-20,Ymin+10:Ymax-10);
figure,imshow(LP,[]);

Page | 2
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-01-2024
Assignment:02
PART 2:

%% Read the video file


videoFile = 'video.mp4';
videoReader = VideoReader(videoFile);

%% Parameters
fps = videoReader.FrameRate;
scaleFactor = 0.8; % Adjust this based on your video resolution

%% Initialize variables
prevFrame = rgb2gray(readFrame(videoReader));
speeds = zeros(1, videoReader.NumFrames - 1);

%% Process frames
for frameIndex = 2:videoReader.NumFrames
currentFrame = rgb2gray(readFrame(videoReader));

diffFrame = abs(currentFrame - prevFrame);


binaryDiff = diffFrame > 30; % Adjust threshold as needed

% Measure speed based on the number of pixels moved


movingPixels = sum(binaryDiff(:));
speed = movingPixels * scaleFactor * fps / (2 * pi); %
Adjust as needed

% Display speed (you can save or visualize this data as


needed)
disp(['Frame ', num2str(frameIndex), ': Speed = ',
num2str(speed), ' units/sec']);

% Update variables for the next iteration


prevFrame = currentFrame;
speeds(frameIndex - 1) = speed;
end

%% Plot speed over time


figure;
plot(speeds);
xlabel('Frame Index');
ylabel('Speed (units/sec)');
title('Vehicle Speed Measurement');
Page | 3
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-01-2024
Assignment:02
Output:

PART 1:

Original Image

Black and White Image

Page | 4
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-01-2024
Assignment:02
Image after number plate area detection

Final Image of detected number plate

PART 2:
...
c
Frame 757: Speed = 530.4105 units/sec
Frame 758: Speed = 438.8288 units/sec
Frame 759: Speed = 454.0924 units/sec
Frame 760: Speed = 393.038 units/sec
Frame 761: Speed = 282.3768 units/sec
Page | 5
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-01-2024
Assignment:02
Frame 762: Speed = 370.1426 units/sec
Frame 763: Speed = 377.7744 units/sec
Frame 764: Speed = 381.5903 units/sec
Frame 765: Speed = 370.1426 units/sec
Frame 766: Speed = 469.356 units/sec
Frame 767: Speed = 522.7787 units/sec
Frame 768: Speed = 347.2471 units/sec
Frame 769: Speed = 179.3474 units/sec
Frame 770: Speed = 290.0086 units/sec
Frame 771: Speed = 267.1132 units/sec
Frame 772: Speed = 373.9585 units/sec
Frame 773: Speed = 255.6655 units/sec
Frame 774: Speed = 377.7744 units/sec
Frame 775: Speed = 255.6655 units/sec
Frame 776: Speed = 110.6612 units/sec
Frame 777: Speed = 186.9792 units/sec
Frame 778: Speed = 324.3517 units/sec
Frame 779: Speed = 301.4563 units/sec
Frame 780: Speed = 286.1927 units/sec
Frame 781: Speed = 316.7199 units/sec
Frame 782: Speed = 206.0587 units/sec
Frame 783: Speed = 87.7658 units/sec
Frame 784: Speed = 255.6655 units/sec
Frame 785: Speed = 305.2722 units/sec
Frame 786: Speed = 320.5358 units/sec
Frame 787: Speed = 251.8496 units/sec
Frame 788: Speed = 232.7701 units/sec
Frame 789: Speed = 133.5566 units/sec
Frame 790: Speed = 179.3474 units/sec
Frame 791: Speed = 362.5108 units/sec
Frame 792: Speed = 274.745 units/sec
Frame 793: Speed = 335.7994 units/sec
Frame 794: Speed = 385.4062 units/sec
Frame 795: Speed = 461.7242 units/sec
Frame 796: Speed = 484.6196 units/sec
Frame 797: Speed = 301.4563 units/sec
Page | 6
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-01-2024
Assignment:02
Frame 798: Speed = 259.4814 units/sec
Frame 799: Speed = 400.6698 units/sec
Frame 800: Speed = 354.879 units/sec
Frame 801: Speed = 2839.0316 units/sec
Frame 802: Speed = 419.7493 units/sec
Frame 803: Speed = 572.3854 units/sec
Frame 804: Speed = 461.7242 units/sec
Frame 805: Speed = 499.8833 units/sec
Frame 806: Speed = 496.0674 units/sec
Frame 807: Speed = 324.3517 units/sec
Frame 808: Speed = 305.2722 units/sec
Frame 809: Speed = 476.9878 units/sec
Frame 810: Speed = 438.8288 units/sec
Frame 811: Speed = 595.2808 units/sec
Frame 812: Speed = 717.3897 units/sec
Frame 813: Speed = 541.8582 units/sec
Frame 814: Speed = 610.5444 units/sec
Frame 815: Speed = 320.5358 units/sec
Frame 816: Speed = 366.3267 units/sec
Frame 817: Speed = 534.2264 units/sec
Frame 818: Speed = 469.356 units/sec
Frame 819: Speed = 320.5358 units/sec
Frame 820: Speed = 644.8876 units/sec
Frame 821: Speed = 251.8496 units/sec
Frame 822: Speed = 202.2428 units/sec
Frame 823: Speed = 270.9291 units/sec
Frame 824: Speed = 702.1261 units/sec
Frame 825: Speed = 190.7951 units/sec
Frame 826: Speed = 179.3474 units/sec
Frame 827: Speed = 366.3267 units/sec
Frame 828: Speed = 202.2428 units/sec
Frame 829: Speed = 45.7908 units/sec
Frame 830: Speed = 64.8703 units/sec
Frame 831: Speed = 125.9248 units/sec
Frame 832: Speed = 110.6612 units/sec
Frame 833: Speed = 209.8747 units/sec
Page | 7
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-01-2024
Assignment:02
Frame 834: Speed = 133.5566 units/sec
Frame 835: Speed = 61.0544 units/sec
Frame 836: Speed = 404.4857 units/sec
Frame 837: Speed = 206.0587 units/sec
Frame 838: Speed = 114.4771 units/sec
Frame 839: Speed = 156.452 units/sec
Frame 840: Speed = 99.2135 units/sec
Frame 841: Speed = 11.4477 units/sec
Frame 842: Speed = 145.0043 units/sec
Frame 843: Speed = 95.3976 units/sec
Frame 844: Speed = 1106.6118 units/sec
Frame 845: Speed = 156.452 units/sec
Frame 846: Speed = 125.9248 units/sec
Frame 847: Speed = 179.3474 units/sec
Frame 848: Speed = 61.0544 units/sec
Frame 849: Speed = 145.0043 units/sec
Frame 850: Speed = 225.1383 units/sec
Frame 851: Speed = 141.1884 units/sec
Output size exceeds the limit. Displaying partial results.

Page | 8
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-01-2024
Assignment:02
Working principle:
For part one we have provided an image input to check whether there is any number
plate detected or not. It checks for the area in image where it can find the number
plate. For that we convert the image into black and white image. As the color of the
number plate is white it is preferable to convert into black and white image. After
converting black and white image, we go for area detection of number plate. After
getting the perfect parameters about number plate we can directly display number
plate as an image.
For part one we have selected one video (.mp4 formatted) to apply our code on. We
firstly divided our video in many different frames. In each frame code looks for an
object and focus on the movement of the object in different frames. In each frame
we are measuring that how much change in the position of an object and frames we
have set for specific time division. So by applying this concept we have detected the
speed of an object after each and every frame in video.

Conclusion:
By using inbuilt functions and libraries of MATLAB we can do number plate
detection and object speed detection. This type of system is very helpful for
municipal corporations and traffic management departments. We can also generate
E-Challan for the detected number plate if He / She exceeding speed limit.

Page | 9
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 22-02-2024
Assignment:03
Question:

To hide and retrieve the information/image inside the cover image by doing Bit
Plane Slicing Concept.

Code:

%% HIDING PART
%% Read images
coverImage = imread('cameraman.tif');
secretImage = imread('mandi.tif');

%% Ensure the cover and hidden images have the same


size
hiddenImage = imresize(secretImage, size(coverImage));

%% Select bit plane for hiding


bitPlane = 1;

%% Prepare space for stego image


stegoImage = coverImage;

%% Loop through each pixel


for row = 1:rows
for col = 1:cols
coverLSB = bitget(coverImage(row, col),
bitPlane);
secretBit = bitget(secretImage(row, col), 1);
stegoLSB = bitxor(coverLSB, secretBit);
stegoImage(row, col) = bitset(coverImage(row,
col), bitPlane, stegoLSB);
end
end

%% plot images
subplot(2,2,1);
imshow(coverImage);
Page | 1
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 22-02-2024
Assignment:03
title('Cover Image');
subplot(2,2,2);
imshow(secretImage);
title('Secret Image');
subplot(2,2,3);
imshow(stegoImage);
title('Stego Image');

%% RETRIEVEING PART
%% Loop through each pixel
for row = 1:rows
for col = 1:cols
stegoLSB = bitget(stegoImage(row, col),
bitPlane);
coverLSB = bitxor(stegoLSB,
bitget(stegoImage(row, col), bitPlane));
extractedImage(row, col) = uint8(coverLSB *
2^7); % Set remaining bits to 0
end
end

%% plot image
subplot(2,2,4);
imshow(extractedImage);
title('Extracted Image');

%% plot histograms
figure;
subplot(1,2,1);
imhist(coverImage);
title('Cover image histogram');
subplot(1,2,2);
imhist(stegoImage);
title('Stego image histogram');

Page | 2
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 22-02-2024
Assignment:03
Output:

Page | 3
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 22-02-2024
Assignment:03
Working principle:
The working principle of hiding and retrieving data using bit plane slicing
involves manipulating the least significant bit (LSB) of each pixel in the image to
embed and extract the secret data. The LSB is the rightmost bit in the binary
representation of a number.
Hiding Data:
1. Convert Secret Data to Binary: First, the secret data is converted into
binary. For example, if the secret data is an integer, it is converted into an 8-
bit binary representation using the dec2bin function.
2. Iterate Over Pixels: The algorithm iterates through each pixel in the
grayscale image.
3. Replace LSB with Secret Bit: For each pixel, the least significant bit (LSB)
of the pixel value is replaced with the corresponding bit from the binary
representation of the secret data. This is done by using the bitset function in
MATLAB.
4. Move to the Next Bit: The algorithm proceeds to the next bit of the secret
data and continues the process until all bits are embedded or the entire image
is covered.
Retrieving Data:
1. Iterate Over Pixels: Similar to the hiding process, the algorithm iterates
through each pixel in the stego image.
2. Retrieve LSB: For each pixel, the least significant bit (LSB) is extracted
using the bitget function. This creates a binary string representing the
embedded bits.
3. Reconstruct Binary Data: The extracted binary bits are concatenated to
reconstruct the binary representation of the embedded secret data.
4. Convert to Decimal: The reconstructed binary data is converted back to
decimal using the bin2dec function.
Page | 4
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 22-02-2024
Assignment:03
Conclusion:
By using this code, we can implement the image steganography. We can hide
the data in the image so that no one can know about the data which is supposed to
be private. At the receiver side we can retrieve the data from image to get the original
data.

Page | 5
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-04-2024
Project
Problem Statement: Image Stitching

Code:
import numpy as np
import cv2
import math
import sys
from numpy import ndarray
from typing import List

def computePairPanoramic( img1: ndarray, img2: ndarray,


match_max_width_1=(sys.maxsize - 1),
match_max_width_2=(sys.maxsize - 1),
scale_factor=None, p_best_matches=1,
cut_black_part=True,
ransac_reproj_threshold=50.0) -> ndarray:

# Convert to grayscale (only if they are colored images)


if len(img1.shape) == 3:
gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
else:
gray1 = img1

if len(img2.shape) == 3:
gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
else:
gray2 = img2

# Resize images
scale_factor_1 = scale_factor
scale_factor_2 = scale_factor

if scale_factor is None:
MAX_SIZE = 1000
if np.max(gray1.shape) > MAX_SIZE:
scale_factor_1 = MAX_SIZE / np.max(gray1.shape)
else:
scale_factor_1 = 1

Page | 1
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-04-2024
Project
if np.max(gray2.shape) > MAX_SIZE:
scale_factor_2 = MAX_SIZE / np.max(gray2.shape)
else:
scale_factor_2 = 1

gray1 = cv2.resize(gray1, None, fx=scale_factor_1, fy=scale_factor_1)


gray2 = cv2.resize(gray2, None, fx=scale_factor_2, fy=scale_factor_2)

# Keypoint region selection,


mask1 = np.zeros_like(gray1)
mask1[:,-math.floor(match_max_width_1 * scale_factor_1):] = 255

mask2 = np.zeros_like(gray2)
mask2[:,:math.floor(match_max_width_2 * scale_factor_2)] = 255

#Create the SIFT object


sift = cv2.SIFT_create()

# Detect the keypoints and descriptors


kp1, des1 = sift.detectAndCompute(gray1, mask1)
kp2, des2 = sift.detectAndCompute(gray2, mask2)

# Compute the matches (by brute force)


bf = cv2.BFMatcher(cv2.NORM_L2, crossCheck=True)
matches = bf.match(des1, des2)

good_matches = matches
# Get the best matches if needed
if p_best_matches != 1:
good_matches = sorted(good_matches, key=lambda x: x.distance)
n_best_matches = math.floor(len(good_matches) * p_best_matches)
good_matches = good_matches[:n_best_matches]

# Prepare the source and destination matching points


src_pts = np.float32([kp1[m.queryIdx].pt for m in good_matches]).reshape(-1,
1, 2)
dst_pts = np.float32([kp2[m.trainIdx].pt for m in good_matches]).reshape(-1,
1, 2)

# Return the points to its original size

Page | 2
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-04-2024
Project
src_pts = src_pts / scale_factor_1
dst_pts = dst_pts / scale_factor_2

# Calculate homography matrix


homography, _ = cv2.findHomography(dst_pts, src_pts, cv2.RANSAC,
ransac_reproj_threshold)

# Using the homography matrix transform the second image (warping its
perspective)
result = cv2.warpPerspective(img2, homography, (img1.shape[1] +
img2.shape[1], img1.shape[0]))

# Copy the first image into the result image.


result[0:img1.shape[0], 0:img1.shape[1]] = img1

# Cut the left black part if needed


if cut_black_part:
if len(result.shape) == 3:
gray_r = cv2.cvtColor(result, cv2.COLOR_BGR2GRAY)
else:
gray_r = result
non_black_coords = cv2.findNonZero(gray_r)
last_pixel_pos = np.max(non_black_coords[:, 0, 0])
return result[:,:last_pixel_pos],img1.shape[1]
else:
return result,img1.shape[1]

def computePanoramicView( img_list: List, scale_factor=None,


p_best_matches=1, cut_black_part=True,
ransac_reproj_threshold=50.0) -> ndarray:

# Process left part


result_left = img_list[0]
match_max_width_left = sys.maxsize - 1
for i in range(1,len(img_list) // 2 + 1):
# Flip input images
mirr_img_i = cv2.flip(img_list[i],1)
result_left = cv2.flip(result_left,1)
result_left,match_max_width_left = computePairPanoramic(mirr_img_i,
result_left,

Page | 3
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-04-2024
Project
match_max_width_2=match_max_width_l
eft,
scale_factor=scale_factor,
p_best_matches=p_best_matches,
cut_black_part=cut_black_part,
ransac_reproj_threshold=ransac_repr
oj_threshold)
# Flip result
result_left = cv2.flip(result_left,1)

result_right = img_list[-1]
match_max_width_right = sys.maxsize - 1
for i in range(len(img_list) - 2,len(img_list) // 2,-1):
result_right,match_max_width_right = computePairPanoramic(img_list[i],
result_right,
match_max_width_2=match_max_width_right
,
scale_factor=scale_factor,
p_best_matches=p_best_matches,
cut_black_part=cut_black_part,
ransac_reproj_threshold=ransac_reproj_t
hreshold)

# Join two parts


result,_ = computePairPanoramic(result_left,
result_right,
match_max_width_1=match_max_width_left,
match_max_width_2=match_max_width_right,
scale_factor=scale_factor,
p_best_matches=p_best_matches,
cut_black_part=cut_black_part,
ransac_reproj_threshold=ransac_reproj_thresho
ld)
return result

Page | 4
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-04-2024
Project
import cv2
import matplotlib.pyplot as plt
from panoramic import computePanoramicView

# Read images

img1 = cv2.imread('imgs/img1.jpg')
img2 = cv2.imread('imgs/img2.jpg')
img3 = cv2.imread('imgs/img3.jpg')
img4 = cv2.imread('imgs/img4.jpg')
img5 = cv2.imread('imgs/img5.jpg')

# For n images
result = computePanoramicView([img1,img2,img3,img4,img5])
fig = plt.figure(figsize=(19.2, 10.8), tight_layout=True) # Plot at full screen
(1920x1080)
plt.axis('off')
plt.imshow(result)
plt.show()

Output:

Page | 5
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-04-2024
Project
Conclusion:
Image stitching is the process of combining multiple overlapping images into a
single, larger image. The key conclusion about image stitching can be summarized
as follows:

1. Alignment and Registration: The primary challenge in image stitching is


accurately aligning and registering the input images, so that common features and
overlapping regions are properly matched. This is typically done using feature
detection and matching algorithms, as well as geometric transformation models.

2. Blending and Seamless Transitions: Once the images are aligned, the next step is
to blend the overlapping regions to create a visually seamless transition between the
images. This may involve techniques such as weighted averaging, gradient domain
blending, or multiband blending to smooth out luminance and color differences.

3. Panorama Generation: One of the most common applications of image stitching


is the generation of panoramic images, where multiple images are combined to
create a wide, high-resolution view that extends beyond the field of view of a single
camera.

4. Computational Efficiency: Effective image stitching algorithms need to balance


accuracy, visual quality, and computational efficiency, as the process can be
computationally intensive, especially for large or high-resolution images.

5. Advances in Deep Learning: Recent advances in deep learning have led to the
development of end-to-end neural network-based image stitching approaches, which
can learn to perform the entire stitching process, including alignment and blending,
directly from data.
Page | 6
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)
FUNDAMENTALS OF IMAGE AND VIDEO PROCESSING (BTEC13603)

Date: 16-04-2024
Project
6. Applications Beyond Photography: While image stitching is most commonly
associated with photography and panorama creation, the techniques have also found
applications in fields such as remote sensing, medical imaging, and computer vision,
where the ability to combine multiple images into a larger, more informative
representation is valuable.

In conclusion, image stitching is a crucial technique for creating high-quality, wide-


ranging visual representations from multiple source images. The continued research
and development in this area, particularly with the integration of deep learning
methods, is expected to lead to further improvements in the accuracy, efficiency, and
versatility of image stitching algorithms.

Page | 7
SARTHAK BOSAMIYA (ET21BTEC007)
PRIYANSHI PATEL (ET21BTEC049)

You might also like