diff options
Diffstat (limited to '3176/CH4')
-rw-r--r-- | 3176/CH4/EX4.18/Ex4_18.sce | 216 | ||||
-rw-r--r-- | 3176/CH4/EX4.19/Ex4_19.sce | 165 | ||||
-rw-r--r-- | 3176/CH4/EX4.20/Ex4_20.sce | 152 | ||||
-rw-r--r-- | 3176/CH4/EX4.21/Ex4_21.sce | 179 | ||||
-rw-r--r-- | 3176/CH4/EX4.22/Ex4_22.sce | 126 | ||||
-rw-r--r-- | 3176/CH4/EX4.23/Ex4_23.sce | 225 | ||||
-rw-r--r-- | 3176/CH4/EX4.24/Ex4_24.sce | 126 |
7 files changed, 572 insertions, 617 deletions
diff --git a/3176/CH4/EX4.18/Ex4_18.sce b/3176/CH4/EX4.18/Ex4_18.sce index 8a3e54776..ec3586868 100644 --- a/3176/CH4/EX4.18/Ex4_18.sce +++ b/3176/CH4/EX4.18/Ex4_18.sce @@ -1,108 +1,108 @@ -//Ex4_18
-//Image Smoothing Using Gaussian Lowpass Filter.
-// 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]=lowpassfilter(type1,M,N,D0,n)//lowpassfilter is used to filter an image .
- u=0:(M-1);
- v=0:(N-1);
- idx=find(u>M/2);
- u(idx)=u(idx)-M;
- idy=find(v>N/2);
- v(idy)=v(idy)-N;
- [U,V]=meshgrid(v,u);
- D=sqrt(U.^2+V.^2);
- select type1
-
- case'gaussian'then
- H=exp(-(D.^2)./(2*(D0^2)));
- else
- disp('Unknownfiltertype.')
- end
-endfunction
-
-
-
-/////////////////////////////////// Main Programm ////////////////////////////////
-a=imread("Ex4_18.tif");
-//gray=rgb2gray(a);
-gray=im2double(a);
-
-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','color','blue','fontsize',4);
-
-/////////////////////////// Filtering With Cut-off Frequency 10 ///////////////////////
-filt=lowpassfilter('gaussian',M,N,10); // Function which generate Filter Mask Corresponding to Low Frequency
-//filt_shift=fftshift(filt);
-//figure,ShowImage(filt_shift,'Filter Mask');
-//title('Filter Mask to Specific Cut-Off Frequency');
-n=filt.*h;//Multiply the Original Spectrum with the Filter Mask.
-Image_filter=real(ifft(n));
-Image_filter=mat2gray(Image_filter)
-figure,ShowImage(Image_filter,'Filtered Image');
-title('Filtered Image with Cut-Off Frequency 10','color','blue','fontsize',4);
-
-
-/////////////////////////// Filtering With Cut-off Frequency 30 ///////////////////////
-filt=lowpassfilter('gaussian',M,N,30); // Function which generate Filter Mask Corresponding to Low Frequency
-//filt_shift=fftshift(filt);
-//figure,ShowImage(filt_shift,'Filter Mask');
-//title('Filter Mask to Specific Cut-Off Frequency');
-n=filt.*h;//Multiply the Original Spectrum with the Filter Mask.
-Image_filter=real(ifft(n));
-Image_filter=mat2gray(Image_filter)
-figure,ShowImage(Image_filter,'Filtered Image');
-title('Filtered Image with Cut-Off Frequency 30','color','blue','fontsize',4);
-
-
-/////////////////////////// Filtering With Cut-off Frequency 60 ///////////////////////
-filt=lowpassfilter('gaussian',M,N,60); // Function which generate Filter Mask Corresponding to Low Frequency
-//filt_shift=fftshift(filt);
-//figure,ShowImage(filt_shift,'Filter Mask');
-//title('Filter Mask to Specific Cut-Off Frequency');
-n=filt.*h;//Multiply the Original Spectrum with the Filter Mask.
-Image_filter=real(ifft(n));
-Image_filter=mat2gray(Image_filter)
-figure,ShowImage(Image_filter,'Filtered Image');
-title('Filtered Image with Cut-Off Frequency 60','color','blue','fontsize',4);
-
-
-/////////////////////////// Filtering With Cut-off Frequency 160 ///////////////////////
-filt=lowpassfilter('gaussian',M,N,160); // Function which generate Filter Mask Corresponding to Low Frequency
-//filt_shift=fftshift(filt);
-//figure,ShowImage(filt_shift,'Filter Mask');
-//title('Filter Mask to Specific Cut-Off Frequency');
-n=filt.*h;//Multiply the Original Spectrum with the Filter Mask.
-Image_filter=real(ifft(n));
-Image_filter=mat2gray(Image_filter)
-figure,ShowImage(Image_filter,'Filtered Image');
-title('Filtered Image with Cut-Off Frequency 160','color','blue','fontsize',4);
-
-
-/////////////////////////// Filtering With Cut-off Frequency 460 ///////////////////////
-filt=lowpassfilter('gaussian',M,N,460); // Function which generate Filter Mask Corresponding to Low Frequency
-//filt_shift=fftshift(filt);
-//figure,ShowImage(filt_shift,'Filter Mask');
-//title('Filter Mask to Specific Cut-Off Frequency');
-n=filt.*h;//Multiply the Original Spectrum with the Filter Mask.
-Image_filter=real(ifft(n));
-Image_filter=mat2gray(Image_filter)
-figure,ShowImage(Image_filter,'Filtered Image');
-title('Filtered Image with Cut-Off Frequency 460','color','blue','fontsize',4);
+//Ex4_18 +//Image Smoothing Using Gaussian Lowpass Filter. +// 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]=lowpassfilter(type1,M,N,D0,n)//lowpassfilter is used to filter an image . + u=0:(M-1); + v=0:(N-1); + idx=find(u>M/2); + u(idx)=u(idx)-M; + idy=find(v>N/2); + v(idy)=v(idy)-N; + [U,V]=meshgrid(v,u); + D=sqrt(U.^2+V.^2); + select type1 + + case'gaussian' + H=exp(-(D.^2)./(2*(D0^2))); + else + disp('Unknownfiltertype.') + end +endfunction + + + +/////////////////////////////////// Main Programm //////////////////////////////// +a=imread("Ex4_18.tif"); +//gray=rgb2gray(a); +gray=im2double(a); + +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','color','blue','fontsize',4); + +/////////////////////////// Filtering With Cut-off Frequency 10 /////////////////////// +filt=lowpassfilter('gaussian',M,N,10); // Function which generate Filter Mask Corresponding to Low Frequency +//filt_shift=fftshift(filt); +//figure,ShowImage(filt_shift,'Filter Mask'); +//title('Filter Mask to Specific Cut-Off Frequency'); +n=filt.*h;//Multiply the Original Spectrum with the Filter Mask. +Image_filter=real(ifft(n)); +Image_filter=mat2gray(Image_filter) +figure,ShowImage(Image_filter,'Filtered Image'); +title('Filtered Image with Cut-Off Frequency 10','color','blue','fontsize',4); + + +/////////////////////////// Filtering With Cut-off Frequency 30 /////////////////////// +filt=lowpassfilter('gaussian',M,N,30); // Function which generate Filter Mask Corresponding to Low Frequency +//filt_shift=fftshift(filt); +//figure,ShowImage(filt_shift,'Filter Mask'); +//title('Filter Mask to Specific Cut-Off Frequency'); +n=filt.*h;//Multiply the Original Spectrum with the Filter Mask. +Image_filter=real(ifft(n)); +Image_filter=mat2gray(Image_filter) +figure,ShowImage(Image_filter,'Filtered Image'); +title('Filtered Image with Cut-Off Frequency 30','color','blue','fontsize',4); + + +/////////////////////////// Filtering With Cut-off Frequency 60 /////////////////////// +filt=lowpassfilter('gaussian',M,N,60); // Function which generate Filter Mask Corresponding to Low Frequency +//filt_shift=fftshift(filt); +//figure,ShowImage(filt_shift,'Filter Mask'); +//title('Filter Mask to Specific Cut-Off Frequency'); +n=filt.*h;//Multiply the Original Spectrum with the Filter Mask. +Image_filter=real(ifft(n)); +Image_filter=mat2gray(Image_filter) +figure,ShowImage(Image_filter,'Filtered Image'); +title('Filtered Image with Cut-Off Frequency 60','color','blue','fontsize',4); + + +/////////////////////////// Filtering With Cut-off Frequency 160 /////////////////////// +filt=lowpassfilter('gaussian',M,N,160); // Function which generate Filter Mask Corresponding to Low Frequency +//filt_shift=fftshift(filt); +//figure,ShowImage(filt_shift,'Filter Mask'); +//title('Filter Mask to Specific Cut-Off Frequency'); +n=filt.*h;//Multiply the Original Spectrum with the Filter Mask. +Image_filter=real(ifft(n)); +Image_filter=mat2gray(Image_filter) +figure,ShowImage(Image_filter,'Filtered Image'); +title('Filtered Image with Cut-Off Frequency 160','color','blue','fontsize',4); + + +/////////////////////////// Filtering With Cut-off Frequency 460 /////////////////////// +filt=lowpassfilter('gaussian',M,N,460); // Function which generate Filter Mask Corresponding to Low Frequency +//filt_shift=fftshift(filt); +//figure,ShowImage(filt_shift,'Filter Mask'); +//title('Filter Mask to Specific Cut-Off Frequency'); +n=filt.*h;//Multiply the Original Spectrum with the Filter Mask. +Image_filter=real(ifft(n)); +Image_filter=mat2gray(Image_filter) +figure,ShowImage(Image_filter,'Filtered Image'); +title('Filtered Image with Cut-Off Frequency 460','color','blue','fontsize',4);
\ No newline at end of file diff --git a/3176/CH4/EX4.19/Ex4_19.sce b/3176/CH4/EX4.19/Ex4_19.sce index 6adcbaf41..eec9ddb9a 100644 --- a/3176/CH4/EX4.19/Ex4_19.sce +++ b/3176/CH4/EX4.19/Ex4_19.sce @@ -1,86 +1,79 @@ -//Ex4_19
-//Using Highpass Filter and Thresholding for Image Enhancement
-// 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]=lowpassfilter(type1,M,N,D0,n)//lowpassfilter is used to filter an image .
- u=0:(M-1);
- v=0:(N-1);
- idx=find(u>M/2);
- u(idx)=u(idx)-M;
- idy=find(v>N/2);
- v(idy)=v(idy)-N;
- [U,V]=meshgrid(v,u);
- D=sqrt(U.^2+V.^2);
- select type1
-
- case'ideal'then
- H=double(D<=D0);
-
- case'Laplacian'then
- H=1+(4*(%pi)^2*D^2);
-
- case'butterworth'then
- if argn(2)==4 then
- n=1;
- end
- H = ones(M,N)./(1+(D./D0).^(2*n));
-
- case'gaussian'then
- H=exp(-(D.^2)./(2*(D0^2)));
- else
- disp('Unknownfiltertype.')
- end
-endfunction
-
-
-
-/////////////////////////////////// Main Programm ////////////////////////////////
-a=imread("Ex4_19.tif");
-//gray=rgb2gray(a);
-gray=im2double(imresize(a,[540 540]));
-
-figure,ShowImage(gray,'Gray Image');
-title('Original Image','color','blue','fontsize',4);
-[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=1-lowpassfilter('butterworth',M,N,50,4); // User Define Function which generate Filter Mask
-filt_shift=fftshift(filt);
-//figure,ShowImage(filt_shift,'Filter Mask');
-//title('Filter Mask to Specific Cut-Off Frequency');
-
-n=filt.*h;//Multiply the Original Spectrum with the Filter Mask.
-Image_filter=real(ifft(n));
-Image_filter=mat2gray(Image_filter)
-figure,ShowImage(Image_filter,'Filtered Image');
-title('Filtered Image with Specific Cut-Off Frequency','color','blue','fontsize',4);
-
-thr = maskthresh(Image_filter);
-
-Image_Enhance=im2bw(Image_filter,thr);
-figure,ShowImage(Image_Enhance,'Filtered Image');
-title('Enhance Image','color','blue','fontsize',4);
-
-
-
-
-
-
-
+//Ex4_19 +//Using Highpass Filter and Thresholding for Image Enhancement +// 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]=lowpassfilter(type1,M,N,D0,n)//lowpassfilter is used to filter an image . + u=0:(M-1); + v=0:(N-1); + idx=find(u>M/2); + u(idx)=u(idx)-M; + idy=find(v>N/2); + v(idy)=v(idy)-N; + [U,V]=meshgrid(v,u); + D=sqrt(U.^2+V.^2); + select type1 + + case'ideal' + H=double(D<=D0); + + case'Laplacian' + H=1+(4*(%pi)^2*D^2); + + case'butterworth' + if argn(2)==4 + n=1; + end + H = ones(M,N)./(1+(D./D0).^(2*n)); + + case'gaussian' + H=exp(-(D.^2)./(2*(D0^2))); + else + disp('Unknownfiltertype.') + end +endfunction + + + +/////////////////////////////////// Main Programm //////////////////////////////// +a=imread("Ex4_19.tif"); +//gray=rgb2gray(a); +gray=im2double(imresize(a,[540 540])); + +figure,ShowImage(gray,'Gray Image'); +title('Original Image','color','blue','fontsize',4); +[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=1-lowpassfilter('butterworth',M,N,50,4); // User Define Function which generate Filter Mask +filt_shift=fftshift(filt); +//figure,ShowImage(filt_shift,'Filter Mask'); +//title('Filter Mask to Specific Cut-Off Frequency'); + +n=filt.*h;//Multiply the Original Spectrum with the Filter Mask. +Image_filter=real(ifft(n)); +Image_filter=mat2gray(Image_filter) +figure,ShowImage(Image_filter,'Filtered Image'); +title('Filtered Image with Specific Cut-Off Frequency','color','blue','fontsize',4); + +thr = maskthresh(Image_filter); + +Image_Enhance=im2bw(Image_filter,thr); +figure,ShowImage(Image_Enhance,'Filtered Image'); +title('Enhance Image','color','blue','fontsize',4);
\ No newline at end of file diff --git a/3176/CH4/EX4.20/Ex4_20.sce b/3176/CH4/EX4.20/Ex4_20.sce index a193300fd..41226efb3 100644 --- a/3176/CH4/EX4.20/Ex4_20.sce +++ b/3176/CH4/EX4.20/Ex4_20.sce @@ -1,80 +1,72 @@ -//Ex4_20
-// Image Sharping in Frequency Domain Using the Laplacian
-// 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]=lowpassfilter(type1,M,N,D0,n)//lowpassfilter is used to filter an image .
- u=0:(M-1);
- v=0:(N-1);
- idx=find(u>M/2);
- u(idx)=u(idx)-M;
- idy=find(v>N/2);
- v(idy)=v(idy)-N;
- [U,V]=meshgrid(v,u);
- D=sqrt(U.^2+V.^2);
- select type1
-
- case'ideal'then
- H=double(D<=D0);
-
- case'Laplacian'then
- H_temp=double(D<=D0);
- H=(4*(%pi)^2*D^2);
- H=H.*H_temp;
-
- case'butterworth'then
- if argn(2)==4 then
- n=1;
- end
- H = ones(M,N)./(1+(D./D0).^(2*n));
- H_temp=ones(M,N)+(4*(%pi)^2*D^2);
- H=H.*H_temp;
-
- case'gaussian'then
- H=exp(-(D.^2)./(2*(D0^2)));
- else
- disp('Unknownfiltertype.')
- end
-endfunction
-
-
-
-/////////////////////////////////// Main Programm ////////////////////////////////
-a=imread("Ex4_20.tif");
-//gray=rgb2gray(a);
-gray=im2double(imresize(a,[540 540]));
-
-figure,ShowImage(gray,'Gray Image');
-title('Original Image','color','blue','fontsize',4);
-[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);
-filt=lowpassfilter('Laplacian',M,N,55); // User Define Function which generate Filter Mask Corresponding to Low Frequency
-filt_shift=fftshift(filt);
-n=filt.*h;//Multiply the Original Spectrum with the Filter Mask.
-Image_filter=real(ifft(n));
-Image_filter=mat2gray(Image_filter);
-
-z=gray+Image_filter;
-figure,ShowImage(mat2gray(z),'Filtered Image');
-title('Filtered Image with Specific Cut-Off Frequency','color','blue','fontsize',4);
-
-
-
-
-
-
-
-
+//Ex4_20 +// Image Sharping in Frequency Domain Using the Laplacian +// 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]=lowpassfilter(type1,M,N,D0,n)//lowpassfilter is used to filter an image . + u=0:(M-1); + v=0:(N-1); + idx=find(u>M/2); + u(idx)=u(idx)-M; + idy=find(v>N/2); + v(idy)=v(idy)-N; + [U,V]=meshgrid(v,u); + D=sqrt(U.^2+V.^2); + select type1 + + case'ideal' + H=double(D<=D0); + + case'Laplacian' + H_temp=double(D<=D0); + H=(4*(%pi)^2*D^2); + H=H.*H_temp; + + case'butterworth' + if argn(2)==4 + n=1; + end + H = ones(M,N)./(1+(D./D0).^(2*n)); + H_temp=ones(M,N)+(4*(%pi)^2*D^2); + H=H.*H_temp; + + case'gaussian' + H=exp(-(D.^2)./(2*(D0^2))); + else + disp('Unknownfiltertype.') + end +endfunction + + + +/////////////////////////////////// Main Programm //////////////////////////////// +a=imread("Ex4_20.tif"); +//gray=rgb2gray(a); +gray=im2double(imresize(a,[540 540])); + +figure,ShowImage(gray,'Gray Image'); +title('Original Image','color','blue','fontsize',4); +[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); +filt=lowpassfilter('Laplacian',M,N,55); // User Define Function which generate Filter Mask Corresponding to Low Frequency +filt_shift=fftshift(filt); +n=filt.*h;//Multiply the Original Spectrum with the Filter Mask. +Image_filter=real(ifft(n)); +Image_filter=mat2gray(Image_filter); + +z=gray+Image_filter; +figure,ShowImage(mat2gray(z),'Filtered Image'); +title('Filtered Image with Specific Cut-Off Frequency','color','blue','fontsize',4);
\ No newline at end of file diff --git a/3176/CH4/EX4.21/Ex4_21.sce b/3176/CH4/EX4.21/Ex4_21.sce index a0e4f18b6..25e6c570a 100644 --- a/3176/CH4/EX4.21/Ex4_21.sce +++ b/3176/CH4/EX4.21/Ex4_21.sce @@ -1,93 +1,86 @@ -//Ex4_21
-//Image Enhancement using High frequency Emphasis 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]=lowpassfilter(type1,M,N,D0,n)//lowpassfilter is used to filter an image .
- u=0:(M-1);
- v=0:(N-1);
- idx=find(u>M/2);
- u(idx)=u(idx)-M;
- idy=find(v>N/2);
- v(idy)=v(idy)-N;
- [U,V]=meshgrid(v,u);
- D=sqrt(U.^2+V.^2);
- select type1
-
- case'ideal'then
- H=double(D<=D0);
-
- case'Laplacian'then
- H=1+(4*(%pi)^2*D^2);
-
-
- case'butterworth'then
- if argn(2)==4 then
- n=1;
- end
- H = ones(M,N)./(1+(D./D0).^(2*n));
-
- case'gaussian'then
- H=exp(-(D.^2)./(2*(D0^2)));
- else
- disp('Unknownfiltertype.')
- end
-endfunction
-
-
-
-/////////////////////////////////// Main Programm ////////////////////////////////
-a=imread("Ex4_21.tif");
-//gray=rgb2gray(a);
-gray=im2double(imresize(a,[540 540]));
-
-figure,ShowImage(gray,'Gray Image');
-title('Original Image','color','blue','fontsize',4);
-[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','color','blue','fontsize',4);
-
-////////////////////////////////// Filtering With Cut-off Frequency 10 ///////////////////////
-filt=1-lowpassfilter('gaussian',M,N,40); // User Define Function which generate Filter Mask
-n=filt.*h;//Multiply the Original Spectrum with the Filter Mask.
-Image_filter=real(ifft(n));
-Image_filter=mat2gray(Image_filter)
-figure(1),ShowImage(Image_filter,'Filtered Image');
-title('Filtered Image (High Pass) with Cut-Off Frequency 40','color','blue','fontsize',4);
-
-
-///////////////////// high boost filtering //////////////////////////////
-filt=0.5+(0.75.*(1-lowpassfilter('gaussian',M,N,40,4))); // User Define Function which generate Filter Mask
-n=filt.*h;//Multiply the Original Spectrum with the Filter Mask.
-Image_filter=real(ifft(n));
-
-Image_filter=mat2gray(Image_filter)
-figure,ShowImage(Image_filter,'Filtered Image');
-title('Filtered Image with Specific Cut-Off Frequency','color','blue','fontsize',4);
-
-
-Image_Enhance=bricontra(Image_filter,180,170,'m'); // Brightness Contrast agjustment (Intensity Transformation)
-figure,ShowImage(Image_Enhance,'Filtered Image');
-title('Enhance Image','color','blue','fontsize',4);
-
-
-
-
-
-
-
+//Ex4_21 +//Image Enhancement using High frequency Emphasis 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]=lowpassfilter(type1,M,N,D0,n)//lowpassfilter is used to filter an image . + u=0:(M-1); + v=0:(N-1); + idx=find(u>M/2); + u(idx)=u(idx)-M; + idy=find(v>N/2); + v(idy)=v(idy)-N; + [U,V]=meshgrid(v,u); + D=sqrt(U.^2+V.^2); + select type1 + + case'ideal' + H=double(D<=D0); + + case'Laplacian' + H=1+(4*(%pi)^2*D^2); + + + case'butterworth' + if argn(2)==4 + n=1; + end + H = ones(M,N)./(1+(D./D0).^(2*n)); + + case'gaussian' + H=exp(-(D.^2)./(2*(D0^2))); + else + disp('Unknownfiltertype.') + end +endfunction + + + +/////////////////////////////////// Main Programm //////////////////////////////// +a=imread("Ex4_21.tif"); +//gray=rgb2gray(a); +gray=im2double(imresize(a,[540 540])); + +figure,ShowImage(gray,'Gray Image'); +title('Original Image','color','blue','fontsize',4); +[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','color','blue','fontsize',4); + +////////////////////////////////// Filtering With Cut-off Frequency 10 /////////////////////// +filt=1-lowpassfilter('gaussian',M,N,40); // User Define Function which generate Filter Mask +n=filt.*h;//Multiply the Original Spectrum with the Filter Mask. +Image_filter=real(ifft(n)); +Image_filter=mat2gray(Image_filter) +figure(1),ShowImage(Image_filter,'Filtered Image'); +title('Filtered Image (High Pass) with Cut-Off Frequency 40','color','blue','fontsize',4); + + +///////////////////// high boost filtering ////////////////////////////// +filt=0.5+(0.75.*(1-lowpassfilter('gaussian',M,N,40,4))); // User Define Function which generate Filter Mask +n=filt.*h;//Multiply the Original Spectrum with the Filter Mask. +Image_filter=real(ifft(n)); + +Image_filter=mat2gray(Image_filter) +figure,ShowImage(Image_filter,'Filtered Image'); +title('Filtered Image with Specific Cut-Off Frequency','color','blue','fontsize',4); + + +Image_Enhance=bricontra(Image_filter,180,170,'m'); // Brightness Contrast agjustment (Intensity Transformation) +figure,ShowImage(Image_Enhance,'Filtered Image'); +title('Enhance Image','color','blue','fontsize',4);
\ No newline at end of file diff --git a/3176/CH4/EX4.22/Ex4_22.sce b/3176/CH4/EX4.22/Ex4_22.sce index 1c4ce8727..299398dfa 100644 --- a/3176/CH4/EX4.22/Ex4_22.sce +++ b/3176/CH4/EX4.22/Ex4_22.sce @@ -1,67 +1,59 @@ -//Ex4_22
-// Image Enhancement using Homomorphic 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]=filter(type1,M,N,D0,low,high,c)//lowpassfilter is used to filter an image .
- u=0:(M-1);
- v=0:(N-1);
- idx=find(u>M/2);
- u(idx)=u(idx)-M;
- idy=find(v>N/2);
- v(idy)=v(idy)-N;
- [U,V]=meshgrid(v,u); // Generate 2-d matrix from 1-d matrix
- D=sqrt(U.^2+V.^2); // distnace calculation
- select type1
- case'Homomorphic'then
- H=((high-low).*(1-(exp(-c*(D.^2)./(D0^2)))))+low;
- else
- disp('Unknownfiltertype.')
- end
-endfunction
-
-
-/////////////////////////////////// Main Programm ////////////////////////////////
-
-a=imread("Ex4_22.tif");
-//gray=rgb2gray(a);
-gray=im2double(imresize(a,[540 540]));
-
-figure,ShowImage(gray,'Gray Image');
-title('Original Image','color','blue','fontsize',4);
-[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);
-low=0.25;
-high=2;
-c=1;
-D0=80;
-filt=filter('Homomorphic',M,N,D0,low,high,c); // User Define Function which generate Filter Mask
-
-n=filt.*h;//Multiply the Original Spectrum with the Filter Mask.
-Image_filter=real(ifft(n));
-//Image_Enhance = hiseq(a);
-
-Image_filter=mat2gray(Image_filter);
-figure,ShowImage(Image_filter,'Filtered Image');
-title('Filtered Image with Specific Cut-Off Frequency','color','blue','fontsize',4);
-
-
-
-
-
-
-
-
+//Ex4_22 +// Image Enhancement using Homomorphic 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]=filter(type1,M,N,D0,low,high,c)//lowpassfilter is used to filter an image . + u=0:(M-1); + v=0:(N-1); + idx=find(u>M/2); + u(idx)=u(idx)-M; + idy=find(v>N/2); + v(idy)=v(idy)-N; + [U,V]=meshgrid(v,u); // Generate 2-d matrix from 1-d matrix + D=sqrt(U.^2+V.^2); // distnace calculation + select type1 + case'Homomorphic' + H=((high-low).*(1-(exp(-c*(D.^2)./(D0^2)))))+low; + else + disp('Unknownfiltertype.') + end +endfunction + + +/////////////////////////////////// Main Programm //////////////////////////////// + +a=imread("Ex4_22.tif"); +//gray=rgb2gray(a); +gray=im2double(imresize(a,[540 540])); + +figure,ShowImage(gray,'Gray Image'); +title('Original Image','color','blue','fontsize',4); +[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); +low=0.25; +high=2; +c=1; +D0=80; +filt=filter('Homomorphic',M,N,D0,low,high,c); // User Define Function which generate Filter Mask + +n=filt.*h;//Multiply the Original Spectrum with the Filter Mask. +Image_filter=real(ifft(n)); +//Image_Enhance = hiseq(a); + +Image_filter=mat2gray(Image_filter); +figure,ShowImage(Image_filter,'Filtered Image'); +title('Filtered Image with Specific Cut-Off Frequency','color','blue','fontsize',4);
\ No newline at end of file diff --git a/3176/CH4/EX4.23/Ex4_23.sce b/3176/CH4/EX4.23/Ex4_23.sce index 3e62f4732..c3288a5f3 100644 --- a/3176/CH4/EX4.23/Ex4_23.sce +++ b/3176/CH4/EX4.23/Ex4_23.sce @@ -1,117 +1,108 @@ -//Ex4_23
-// Reduction of Moire Pattern Using 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(type1,M,N,D0,n)//notchfilter is used to filter an image .
- u=0:(M-1);
- v=0:(N-1);
- idx=find(u>M/2);
- u(idx)=u(idx)-M;
- idy=find(v>N/2);
- v(idy)=v(idy)-N;
- [U,V]=meshgrid(v,u);
- D=sqrt(U.^2+V.^2);
- x=[41 45 82 86 162 166 203 207];
- y=[112 55 112 56 114 58 115 58];
- select type1
- case'ideal'then
- //H=double(D<=D0);
-H=ones(M,N);
-for a=1:M
- for b=1:N
- for i=1:length(x)
- d=sqrt((a-x(i))*(a-x(i))+(b-y(i))*(b-y(i)));
- if (d<D0)
- //H(a,b)=1-(1/(1+(d/D0)^(2*n)));
- H(a,b)=0
- end
- end
- end
-end
-
- case'butterworth'then
- if argn(2)==4 then
- n=1;
- end
- //H = ones(M,N)./(1+(D./D0).^(2*n));
- H=ones(M,N);
- for a=1:M
- for b=1:N
- for i=1:length(x)
- d=sqrt((a-x(i))*(a-x(i))+(b-y(i))*(b-y(i)));
- if (d<D0)
- H(a,b)=1-(1/(1+(d/D0)^(2*n)));
- //H(a,b)=0
- end
- end
- end
-end
-
- case'gaussian'then
- //H=exp(-(D.^2)./(2*(D0^2)));
- H=ones(M,N);
- for a=1:M
- for b=1:N
- for i=1:length(x)
- d=sqrt((a-x(i))*(a-x(i))+(b-y(i))*(b-y(i)));
- if (d<D0)
- //H(a,b)=1-(1/(1+(d/D0)^(2*n)));
- H(a,b)=1-(exp(-(d.^2)./(2*(D0^2))));
- //H(a,b)=0
- end
- end
- end
-end
- else
- disp('Unknownfiltertype.')
- end
-
-endfunction
-
-
-/////////////////////////////////// Main Programm ////////////////////////////////
-
-a=imread("Ex4_23.tif");
-//gray=rgb2gray(a);
-gray=im2double(a);
-
-figure,ShowImage(gray,'Gray Image');
-title('Original Image','color','blue','fontsize',4);
-[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','color','blue','fontsize',4);
-
-filt=notchfilter('gaussian',M,N,9,2); // User Define Function which generate Filter Mask Corresponding to Low Frequency
-
-//filt_shift=fftshift(filt);
-n=filt.*fftshift(h);//Multiply the Original Spectrum with the Filter Mask.
-figure,ShowImage(abs(n),'Frequency Spectrum');
-title('Spectrum After Filtering','color','blue','fontsize',4);
-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','color','blue','fontsize',4);
-
-
-
-
-
-
-
-
-
+//Ex4_23 +// Reduction of Moire Pattern Using 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(type1,M,N,D0,n)//notchfilter is used to filter an image . + u=0:(M-1); + v=0:(N-1); + idx=find(u>M/2); + u(idx)=u(idx)-M; + idy=find(v>N/2); + v(idy)=v(idy)-N; + [U,V]=meshgrid(v,u); + D=sqrt(U.^2+V.^2); + x=[41 45 82 86 162 166 203 207]; + y=[112 55 112 56 114 58 115 58]; + select type1 + case'ideal' + //H=double(D<=D0); +H=ones(M,N); +for a=1:M + for b=1:N + for i=1:length(x) + d=sqrt((a-x(i))*(a-x(i))+(b-y(i))*(b-y(i))); + if (d<D0) + //H(a,b)=1-(1/(1+(d/D0)^(2*n))); + H(a,b)=0 + end + end + end +end + + case'butterworth' + if argn(2)==4 + n=1; + end + //H = ones(M,N)./(1+(D./D0).^(2*n)); + H=ones(M,N); + for a=1:M + for b=1:N + for i=1:length(x) + d=sqrt((a-x(i))*(a-x(i))+(b-y(i))*(b-y(i))); + if (d<D0) + H(a,b)=1-(1/(1+(d/D0)^(2*n))); + //H(a,b)=0 + end + end + end +end + + case'gaussian' + //H=exp(-(D.^2)./(2*(D0^2))); + H=ones(M,N); + for a=1:M + for b=1:N + for i=1:length(x) + d=sqrt((a-x(i))*(a-x(i))+(b-y(i))*(b-y(i))); + if (d<D0) + //H(a,b)=1-(1/(1+(d/D0)^(2*n))); + H(a,b)=1-(exp(-(d.^2)./(2*(D0^2)))); + //H(a,b)=0 + end + end + end +end + else + disp('Unknownfiltertype.') + end + +endfunction + + +/////////////////////////////////// Main Programm //////////////////////////////// + +a=imread("Ex4_23.tif"); +//gray=rgb2gray(a); +gray=im2double(a); + +figure,ShowImage(gray,'Gray Image'); +title('Original Image','color','blue','fontsize',4); +[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','color','blue','fontsize',4); + +filt=notchfilter('gaussian',M,N,9,2); // User Define Function which generate Filter Mask Corresponding to Low Frequency + +//filt_shift=fftshift(filt); +n=filt.*fftshift(h);//Multiply the Original Spectrum with the Filter Mask. +figure,ShowImage(abs(n),'Frequency Spectrum'); +title('Spectrum After Filtering','color','blue','fontsize',4); +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','color','blue','fontsize',4);
\ No newline at end of file diff --git a/3176/CH4/EX4.24/Ex4_24.sce b/3176/CH4/EX4.24/Ex4_24.sce index 1e50e6749..aa4ec99fc 100644 --- a/3176/CH4/EX4.24/Ex4_24.sce +++ b/3176/CH4/EX4.24/Ex4_24.sce @@ -1,66 +1,60 @@ -//Ex4_24
-// Enhancement of Corrupted Cassini Saturn Image 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-5),ceil(N/2-W/2):ceil(N/2+W/2))=0;
- H(ceil(M/2+5):M,ceil(N/2-W/2):ceil(N/2+W/2))=0;
-
-endfunction
-
-
-
-/////////////////////////////////// Main Programm ////////////////////////////////
-a=imread("Ex4_24.tif");
-//gray=rgb2gray(a);
-gray=im2double(a);
-
-figure,ShowImage(gray,'Gray Image');
-title('Original Image','color','blue','fontsize',4);
-[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','color','blue','fontsize',4);
-
-filt=notchfilter(M,N,7); // 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','color','blue','fontsize',4);
-
-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','color','blue','fontsize',4);
-
-
-figure,ShowImage(filt_pass,'Filter Mask');
-title('Filter Mask (Band Pass) to Specific Cut-Off Frequency','color','blue','fontsize',4);
-
-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','color','blue','fontsize',4);
-
-
-
-
-
-
+//Ex4_24 +// Enhancement of Corrupted Cassini Saturn Image 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-5),ceil(N/2-W/2):ceil(N/2+W/2))=0; + H(ceil(M/2+5):M,ceil(N/2-W/2):ceil(N/2+W/2))=0; + +endfunction + + + +/////////////////////////////////// Main Programm //////////////////////////////// +a=imread("Ex4_24.tif"); +//gray=rgb2gray(a); +gray=im2double(a); + +figure,ShowImage(gray,'Gray Image'); +title('Original Image','color','blue','fontsize',4); +[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','color','blue','fontsize',4); + +filt=notchfilter(M,N,7); // 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','color','blue','fontsize',4); + +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','color','blue','fontsize',4); + + +figure,ShowImage(filt_pass,'Filter Mask'); +title('Filter Mask (Band Pass) to Specific Cut-Off Frequency','color','blue','fontsize',4); + +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','color','blue','fontsize',4);
\ No newline at end of file |