Image Processing in MATLAB Part 2
Image Processing in MATLAB Part 2
Strategies for Enhancing Visual Impact, Distortion Minimization, and Image Enhancement
1. Objective:
The objective of this lab report is to provide with a foundational understanding of image processing in
MATLAB, focusing on enhancing visual quality, reducing distortions, and applying transformative
modifications.
2. Introduction
Code
%Image Complement
original_image = imread('img1.jpeg');
gray_image = rgb2gray(original_image); % convert RGB to Gray Scale
im2bw: This command is used to convert the image into binary image in Matlab.
Code
%Conversion of image into binary image
image_variable = imread("img1.jpeg");
binary1 = im2bw(image_variable); %Convert into binary image
Code
%Logarithmic Transformation
image=imread("img1.jpeg");
gray_image = rgb2gray(image);
double_value=im2double(gray_image);
Output1=2*log(1+double_value); %set the scaling factor of 2
Output2=2.5*log(1+double_value); %set the scaling factor of 2.5
Output3=3*log(1+double_value); %set the scaling factor of 3
I = imread('img1.jpeg');
Id = im2double(I);
output1 = 4*(((1+0.3).^(Id))-1);
output2 = 4*(((1+0.4).^(Id))-1);
output3 = 4*(((1+0.6).^(Id))-1);
Code
I = imread('image.png');
Id = im2double(I);
output1 = 2*(Id.^0.5);
output2 = 2*(Id.^1.5);
output3 = 2*(Id.^3.0);
subplot(2,2,1), imshow(I);
subplot(2,2,2), imshow(output1);
subplot(2,2,3), imshow(output2);
subplot(2,2,4), imshow(output3);;
I = imread('sky.jpg');
N=imnoise(I,'salt & pepper', 0.08);
imshow(N)
2.8 Removing Salt and Pepper Noise using Mean Filter in MATLAB
To remove noise, we will use a built-in function of MATLAB named “imfilter()”. This function is used to
apply various types of filters to images. First load an image. Then added salt and pepper noise to the
image. After that, create a 3 x 3 convolutional kernel and convert the kernel into a mean filter by replacing
the values of the matrix by 1/9. Finally using the “imfilter()” function, apply the mean filter to the image.
Code
I = imread('img1.jpg');
N=imnoise(I,'salt & pepper', 0.03);
mf = ones(3, 3)/9;
noise_free = imfilter(N,mf);
The first step of applying median filter to remove noises from images in MATLAB is to read the image
using 'imread()' function. Then using 'medfilt2()' function to remove the noises. The 'medfilt2()' function
requires two input arguments. One is the noise image and second is the size of filter.
First generate a noisy image using 'imnoise()' function. Then used the noisy image in the filter. Define the
size of the filter [3 3]. That means it is square area containing 9 pixels. Before passing the image, split it
into three channels - red, green and blue. It is because the filter can handle one channel at a time. Passing
an image with all three channels together will trigger an error.
Once all three channels are filtered by 'midfilt2' filter, using 'cat' function, the channels are combined
together to form the same RGB image with less noise.
Code
I = imread('img1.jpg');
N = imnoise(I, 'salt & pepper', 0.3);