You are on page 1of 13

A

LAB REPORT
ON

Submitted by:
Akash Kumar Gaur
Reg. no.: 20146017
B.Tech. 8th Semester

Submitted to:

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


ENGINEERING
MOTILAL NEHRU NATIONAL INSTITUTE OF TECHNOLOGY
ALLAHABAD-211004, INDIA
INDEX

S Experiment Name Date of Date of Sign & Remarks


No. Experiment Submission
Experiment No:-1

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.

Tool used:- MATLAB R2015a.

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:-

Fig 1: Original image Fig 3: Green image

Fig 2: Red image


Fig 4: Blue image

2
Fig 5: Gray scale image Fig 7:YCBCR image

Fig 6: HSV image

Fig 8: Resized 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.

Tool used:- MATLAB R2015a.


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.
The discrete cosine transform helps separate the image into parts of differing importance
(with respect to the image's visual quality). The DCT is similar to the discrete Fourier transform.
It transforms a signal or image from the spatial domain to the frequency domain.
It is a separable linear transformation; that is, the two-dimensional transform
is equivalent to a one-dimensional DCT performed along a single dimension followed by a
one- dimensional DCT in the other dimension. The definition of the two-dimensional DCT for
an input image A and output image B is

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

figure; imshow(I); end


f=f+1;
imshow(log(abs(p)),[]), end
colormap(jet(64)), colorbar; end

I_resize= imresize(I,[512 512]); figure; imshow(img,[]);


figure; imshow(img_1,[]);
pd= dct2(I_resize); w_shortcut_dct = blkproc(I_resize,
[8 8], @dct2);
w_shortcut_idct =
figure; imshow(I_resize); blkproc(w_shortcut_dct, [8 8],
@idct2);
r=1; figure; imshow(w_shortcut_idct, []);
for ii=1:8:505
for jj=1:8:505 function f = ddct(xi)
for i=0:1:7
for j=0:1:7
m(i+1,j+1) = for m=1:1:8
I_resize(i+ii,j+jj); for n=1:1:8
if(m==1)
end
cm=0.707;
end
else
x{r}= m;
cm=1;
m=[];
end
r=r+1;
if(n==1)
end cn=0.707;
end
else
for l=1:1:4096 cn=1;
w{l}=dct2(x{l});
end
end
l=0;
for f=1:1:4096 for x=1:1:8
y{f}=idct2(w{f}); for y=1:1:8
end
for l=1:1:4096
l=l+(xi(x,y)*cos((2*x+1)*(m-
pp=x{l};
1)*pi/(16))*cos((2*y-1)*(n-
lpp{l}=ddct(pp); 1)*pi/(16)));
end
end
end
f=1; f(m,n)=0.25*cm*cn*l;
for ii=1:8:505
for jj=1:8:505
mn=y{f}; end
mp=lpp{f}; end
for i=0:1:7 end

5
Output:-

Fig. 2.1- Grayscale image.

Fig. 2.2- resized image (512X512).

6
Fig. 2.3- Recovered image through idct(8X8) using for loop.

Fig. 2.5- Recovered image through idct(8X8) using blkproc.

7
Fig. 2.5- Matrix of resized image (512X512).

Fig. 2.6- Matrix of resized image x(1) of size 8X8.

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.

Tool used:- MATLAB R2015a.

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);

I= rgb2gray(imread('C:\Users\M- lp= wiener2(I_noise,[3 3],0.5); figure,


PC\Desktop\flower.jpg')); imshow(lp);
I_noise=imnoise(I,'gaussian',0,.01); [psnr1,mse1]=measerr(I,I_noise);
figure; imshow(I); [psnr2,mse2]=measerr(I,filteredRGB);
figure; imshow(I_noise); [psnr3,mse3]=measerr(I,lp);

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.

Fig. 3.5- MSE and PSNR values of recovered images.

Result:-
The experiment has been performed successfully and the obtained results have been recorded.

10
11

You might also like