You are on page 1of 21

M.

Tech-II sem (DECS) Advanced Communications Lab


List of Experiments: 1. 2.
3. 4. Histogram equalization of an image Fourier Transform & its Inverse Fourier Transform of an image Blurring & Deblurring of an image Dilation & Erosion of an image Edge detection (Sobel, canny edge detector) of an image Sampling of an image Frequency Modulation & Demodulation of a signal.

5.
6.

7.

MATLAB PROGRAMS

1. Histogram Equalization
Aim: To perform histogram equalization of an image Equipments:
Operating System: Software: Windows XP Matlab 7.5, Image Processing Toolbox.

Theory: Program:
clc; clear all; close all; f=imread('coins.png'); figure, imshow(f); title('input image'); h=imhist(f); h1=h(1:10:256); horz=1:10:256; figure, bar(horz,h1); figure, plot(horz,h1); title('histogram equalized image');

Result:-

2. Fourier Transform & Inverse Fourier Transform


Aim: To perform Fourier Transform & its Inverse Fourier Transform of an image Equipments:
Operating System: Software: Windows XP Matlab 7.5, Image Processing Toolbox.

Theory: Program:
clc; clear all; close all; A=zeros(30,30); A(5:24,13:17)=1; subplot(1,2,1);imshow(A); title('original image'); F=fft2(A); subplot(1,2,2);imshow(F); title('fourier transformed image'); S=abs(F) Fc=fftshift(F); S2=log(1+abs(Fc)); figure,subplot(1,2,1); imshow(Fc); title('fourier transformed image'); F=ifftshift(Fc) f1=(ifft2(F)); subplot(1,2,2); imshow(f1); title('inverse transform');

Result :-

3. Blurring & Deblurring


Aim: To perform blurring & deblurring of an image Equipments:
Operating System: Software: Windows XP Matlab 7.5, Image Processing Toolbox.

Theory: Program:
clc; close all; clear all; f=imread('cameraman.tif'); subplot(1,2,1);imshow(f);title('original image'); LEN = 31; THETA = 11; PSF = fspecial('motion',LEN,THETA); Blurred = imfilter(f,PSF,'circular','conv'); subplot(1,2,2);imshow(Blurred);title('Blurred Image'); % deblurring figure,subplot(1,2,1);imshow(Blurred);title('Blurred image'); wnr1 = deconvwnr(Blurred,PSF); subplot(1,2,2);imshow(wnr1);title('Deblurred Image'); title('Restored, True PSF');

Result:-

4. Dilation & Erosion


Aim: To perform dilation & erosion of an image Equipments:
Operating System: Software: Windows XP Matlab 7.5, Image Processing Toolbox.

Theory: Program:
close all; clear all; clc; f=imread('cameraman.tif'); level=graythresh(f); f1=im2bw(f,level); s=[0 1 0; 1 1 1 ; 0 1 0]; f2=imdilate(f1,s); subplot(1,3,1);imshow(f);title('original image'); subplot(1,3,2);imshow(f1);title('binary image'); subplot(1,3,3);imshow(f2);title('dilated image');

Result:-

5. Edge Detection
Aim: To perform edge detection of an image Equipments:
Operating System: Software: Windows XP Matlab 7.5, Image Processing Toolbox.

Theory: Program:
clc;0000 close all; clear all; f=imread('trees.tif'); subplot(1,2,1); imshow(f);title('original image'); BW1=edge(f,'sobel'); BW2=edge(f,'canny'); subplot(1,2,2); imshow(BW1);title('sobel edge detector image'); figure,subplot(1,2,1);imshow(f);title('original image'); subplot(1,2,2); imshow(BW2);title('canny edge detector image');

Result:-

6. Sampling
Aim: To perform sampling of an image Equipments:
Operating System :Software:Windows XP Matlab 7.5, Image Processing Toolbox.

Theory: Program:
if (nargin==0) hFig = figure( 'visible','off' ); hImage = image; Child = get( hImage,'cdata' ); close( hFig ); out = updownsample( Child,300,300,0,1 ); figure; colormap gray; subplot( 1,2,1 ); imagesc( Child ); subplot( 1,2,2 ); imagesc( out ); return elseif (nargin<5) error( 'UpDownSample - insufficient input parameters' ); end % get input image size, and calculate the gain [in_y_sz,in_x_sz] = size( in_m ); gain_x = out_x_sz/in_x_sz; gain_y = out_y_sz/in_y_sz; % check if up/down sampling is needed at all if (gain_x == 1) & (gain_y==1) % same gain -> do not change sampling rate if is_fourier_flag switch is_real_flag case 0, out_m = ifft2( in_m ); case 1, out_m = real( ifft2( in_m ) ); case 2, out_m = abs( ifft2( in_m ) ); end else out_m = in_m; end else % upsample or downsample as needed % convert to fourier domain, if input is given in the space domain if ~is_fourier_flag

in_m = fft2(in_m); end % if the input is even & output is odd-> use floor for all % if the output is even & input is odd -> use ceil for all % for downsampling -> the opposite if (~mod( in_x_sz,2 ) & (out_x_sz>in_x_sz)) | (mod( in_x_sz,2 ) & (out_x_sz<in_x_sz)) x_output_space = max(floor((out_x_sz-in_x_sz)/2),0) + [1:min(in_x_sz,out_x_sz)]; x_input_space = max(floor((in_x_sz-out_x_sz)/2),0) + [1:min(in_x_sz,out_x_sz)]; else x_output_space = max(ceil((out_x_sz-in_x_sz)/2),0) + [1:min(in_x_sz,out_x_sz)]; x_input_space = max(ceil((in_x_sz-out_x_sz)/2),0) + [1:min(in_x_sz,out_x_sz)]; end if (~mod( in_y_sz,2 ) & (out_y_sz>in_y_sz)) | (mod( in_y_sz,2 ) & (out_y_sz<in_y_sz)) y_output_space = max(floor((out_y_sz-in_y_sz)/2),0) + [1:min(in_y_sz,out_y_sz)]; y_input_space = max(floor((in_y_sz-out_y_sz)/2),0) + [1:min(in_y_sz,out_y_sz)]; else y_output_space = max(ceil((out_y_sz-in_y_sz)/2),0) + [1:min(in_y_sz,out_y_sz)]; y_input_space = max(ceil((in_y_sz-out_y_sz)/2),0) + [1:min(in_y_sz,out_y_sz)]; end % perform the up/down sampling padded_out_m = zeros( out_y_sz,out_x_sz ); in_m = fftshift(in_m); padded_out_m( y_output_space,x_output_space ) = in_m(y_input_space,x_input_space); out_m = (gain_x*gain_y)*ifft2(ifftshift(padded_out_m)); switch is_real_flag case 0, % do nothing case 1, out_m = real( out_m ); case 2, out_m = abs( out_m ); end end

Result:-

7. Frequency Modulation & Demodulation


Aim: To perform Frequency Modulation & Demodulation of a signal Equipments:
Operating System: Software: Windows XP Matlab 7.5, Image Processing Toolbox.

Theory: Program:
Fs = 8000; % Sampling rate of signal Fc = 3000; % Carrier frequency t = [0:Fs]/Fs; % Sampling times s1 = sin(2*pi*10*t); % Channel 1 %s2 = sin(2*pi*150*t)+2*sin(2*pi*900*t); % Channel 2 %x = [s1]; % Two-channel signal dev = 50; % Frequency deviation in modulated signal y = fmmod(s1,Fc,Fs,dev); % Modulate both channels. z = fmdemod(y,Fc,Fs,dev); % Demodulate both channels. subplot(2,1,1); plot(t,y); title('frequency modulated image');% Plot x on top. subplot(2,1,2); plot(t,z);title('demodulated image');% Plot y below.

Result:-

You might also like