Professional Documents
Culture Documents
LAB REPORT
ON
Submitted by:
Akash Kumar Gaur
Reg. no.: 20146017
B.Tech. 8th Semester
Submitted to:
Aim: Write a program to read a RGB image and perform the following operation on the image:
(a). Extract Red ,Green and Blue components of the image and then combine them to
get the orginal image.
(b). Convert the RGB image into gray scale using the following equation.
Y=(77/256)*R+(150/256)*G+(29/256)*B
(c). Convert the image into hsv and ycbcr and resize the original image.
Theory:-
An RGB image, sometimes referred to as a truecolor image, is stored in MATLAB as an m-by-n-
by-3 data array that defines red, green, and blue color components for each individual
pixel. RGB images do not use a palette. The color of each pixel is determined by the combination
of the red, green, and blue intensities stored in each color plane at the pixel's location. Graphics file
formats store RGB images as 24-bit images, where the red, green, and blue components are 8
bits each.An RGB MATLAB array can be of class double, uint8, or uint16.
The main purpose of the RGB color model is for the sensing, representation and display
of images in electronic systems, such as televisions and computers, though it has also been used in
conventional photography.HSVor related models are often used in computer vision
and image analysis for feature detection or image segmentation.
MATLAB Code:-
clc; i1(:,:,1)=R;
clear all; close all; i1(:,:,2)=t;
i=imread('flower.jpg'); i1(:,:,3)=t;
imtool(i); imtool(uint8(i1));
figure(1);imshow(i); t=zeros(size(G));
R=i(:,:,1); i2(:,:,1)=t;
G=i(:,:,2); i2(:,:,2)=G;
B=i(:,:,3); i2(:,:,3)=t;
imtool(uint8(R)); imtool(uint8(i2));
imtool(uint8(G)); t=zeros(size(B));
imtool(uint8(B)); i3(:,:,1)=t;
t=zeros(size(R)); i3(:,:,2)=t;
i1=zeros(size(i)); i3(:,:,3)=B;
i2=zeros(size(i)); imtool(uint8(i3));
i3=zeros(size(i)); p=i1+i2+i3;
p=zeros(size(i)); imtool(uint8(p));
y=zeros(size(i));
1
y=(77/256)*R+(150/256)*G+(29/256)*B; imtool(hsv);
imtool(uint8(y)); ycbcr=rgb2ycbcr(i);
grey=zeros(size(i)); imtool(ycbcr);
grey=rgb2gray(i); k=imresize(i,[1000 1000]);
imtool(grey); imtool(k);
hsv=rgb2hsv(i);
Observed Images:-
2
Fig 5: Gray scale image Fig 7:YCBCR image
Result : -
The experiment has been performed successfully and the obtained results have been recorded.
3
Experiment No:-2
Aim:- Write a program to read a RGB image and calculate the DCT of the image and recover
the original image.
Where,
and
M and N are the row and column size of A, respectively. If you apply the DCT to real data, the
result is also real. The DCT tends to concentrate information, making it useful for image
compression applications. The inverse discrete cosine transform reconstructs a sequence from its
discrete cosine transform (DCT) coefficients. The idct function is the inverse of the dct function.
Commands used-
1)B = blkproc(A,[m n],fun)
blkproc processes the image A by applying the function fun to each distinct m -by- n block of A,
padding A with zeros if necessary. fun is a function that accepts an m -by- n matrix, x
, and
returns a matrix, vector, or scalar y.
4
Matlab Code:-
clc; for j=0:1:7
clear all; img(ii+i,jj+j) =
close all; mn(i+1,j+1);
I= rgb2gray(imread('C:\Users\M- img_1(ii+i,jj+j) =
PC\Desktop\flower.jpg')); mp(i+1,j+1);
p = dct2(I); end
5
Output:-
6
Fig. 2.3- Recovered image through idct(8X8) using for loop.
7
Fig. 2.5- Matrix of resized image (512X512).
Result:-
The experiment has been performed successfully and the obtained results have been recorded.
8
Experiment No:-3
Aim: Write a program to add gaussian noise to grayscale image and then recover the original
image by using appropriate filter, Weiner and gaussian filter also performance parameters such
as correlation, MSE and PSNR of original and recovered image.
Theory:-
Gaussian noise is statistical noise having a probability density function (PDF) equal to that of the
normal distribution, which is also known as the Gaussian distribution. In other words, the values
that the noise can take on are Gaussian-distributed.
In digital image processing Gaussian noise can be reduced using a spatial filter, though
when smoothing an image, an undesirable outcome may result in the blurring of fine-scaled
image edges and details because they also correspond to blocked high frequencies.
The Wiener filter is a filter used to produce an estimate of a desired or target random
process by linear time-invariant (LTI) filtering of an observed noisy process, assuming known
stationary signal and noise spectra, and additive noise.While a Gaussian filter is a filter whose
impulse response is a Gaussian function (or an approximation to it). Gaussian filters have the
properties of having no overshoot to a step function input while minimizing the rise and fall time.
Performance parameters such as Mean Square Error (MSE) and the Peak Signal to Noise
Ratio (PSNR) are the two error metrics used to compare image compression quality. The MSE
represents the cumulative squared error between the compressed and the original image, whereas
PSNR represents a measure of the peak error.
Function Used
Matlab Code:-
clc; h = fspecial('gaussian',[3 3],0.1);
clear all; filteredRGB = imfilter(I_noise, h);
close all; figure, imshow(filteredRGB);
9
Output:-
Fig. 3.1- Grayscale image. Fig. 3.2- Grayscale image with noise.
Fig. 3.3- Recovered image using gaussian Fig. 3.3- Recovered image using weiner
Filter. Filter.
Result:-
The experiment has been performed successfully and the obtained results have been recorded.
10
11