From b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b Mon Sep 17 00:00:00 2001 From: priyanka Date: Wed, 24 Jun 2015 15:03:17 +0530 Subject: initial commit / add all books --- 3176/CH5/EX5.8/Ex5_8.sce | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 3176/CH5/EX5.8/Ex5_8.sce (limited to '3176/CH5/EX5.8/Ex5_8.sce') diff --git a/3176/CH5/EX5.8/Ex5_8.sce b/3176/CH5/EX5.8/Ex5_8.sce new file mode 100644 index 000000000..db4e987db --- /dev/null +++ b/3176/CH5/EX5.8/Ex5_8.sce @@ -0,0 +1,65 @@ +//Ex5_8 +//Removal of Periodic Noise by Notch Filtering +// Version : Scilab 5.4.1 +// Operating System : Window-xp, Window-7 +//Toolbox: Image Processing Design 8.3.1-1 +//Toolbox: SIVP 0.5.3.1-2 +//Reference book name : Digital Image Processing +//book author: Rafael C. Gonzalez and Richard E. Woods + +clc; +close; +clear; +xdel(winsid())//to close all currently open figure(s). + +function[H]=notchfilter(M,N,W)//notchfilter is used to filter an image . + H=ones(M,N); + H(1:ceil(M/2-10),ceil(N/2-W/2):ceil(N/2+W/2))=0; + H(ceil(M/2+10):M,ceil(N/2-W/2):ceil(N/2+W/2))=0; + +endfunction + + + +/////////////////////////////////// Main Programm //////////////////////////////// +a=imread("Ex5_8.tif"); +//gray=rgb2gray(a); +gray=im2double(imresize(a,0.5)); +figure,ShowImage(gray,'Gray Image'); +title('Original Image'); +[M,N]=size(gray); + +h=fft2(gray);//fft2() is used to find 2-Dimensional Fast Fourier Transform of an matrix +i=log(1+abs(h)); +in=fftshift(i);//fftshift() is used to rearrange the fft output, moving the zero frequency to the center of the spectrum. +inm=mat2gray(in) +figure,ShowImage(inm,'Frequency Spectrum'); +title('Frequency Spectrum'); + +filt=notchfilter(M,N,3); // User Define Function which generate Filter Mask Corresponding to Low Frequency +filt_pass=1-filt; +//filt_shift=fftshift(filt); +figure,ShowImage(filt,'Filter Mask'); +title('Filter Mask (Band stop) to Specific Cut-Off Frequency'); + +n=filt.*fftshift(h);//Multiply the Original Spectrum with the Filter Mask. +Image_filter=real(ifft(fftshift(n))); +Image_filter=mat2gray(Image_filter) +figure,ShowImage(Image_filter,'Filtered Image'); +title('Filtered Image with Specific Cut-Off Frequency'); + + +figure,ShowImage(filt_pass,'Filter Mask'); +title('Filter Mask (Band Pass) to Specific Cut-Off Frequency'); + +n=filt_pass.*fftshift(h);//Multiply the Original Spectrum with the Filter Mask. +Image_filter=real(ifft(fftshift(n))); +Image_filter=mat2gray(Image_filter) +figure,ShowImage(Image_filter,'Filtered Image'); +title('Filtered Image (Noise Pattern) with Specific Cut-Off Frequency'); + + + + + + -- cgit