summaryrefslogtreecommitdiff
path: root/125/CH6
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /125/CH6
downloadScilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip
initial commit / add all books
Diffstat (limited to '125/CH6')
-rwxr-xr-x125/CH6/EX6.1/Fig6_1.sce19
-rwxr-xr-x125/CH6/EX6.1/Fig6_1_Blurring_Image.JPGbin0 -> 5350 bytes
-rwxr-xr-x125/CH6/EX6.13/Fig6_13.sce42
-rwxr-xr-x125/CH6/EX6.13/Fig6_13_Image_Restoration.JPGbin0 -> 32640 bytes
-rwxr-xr-x125/CH6/EX6.18/Fig6_18.sce31
-rwxr-xr-x125/CH6/EX6.18/Fig6_18_Average_Filtering.JPGbin0 -> 20161 bytes
-rwxr-xr-x125/CH6/EX6.21/Fig6_21.sce49
-rwxr-xr-x125/CH6/EX6.21/Fig6_21_Median_Filtering_GrayImage.JPGbin0 -> 19829 bytes
-rwxr-xr-x125/CH6/EX6.23/Fig6_23.sce26
-rwxr-xr-x125/CH6/EX6.23/Fig6_23_median_filtering_ColorImage.JPGbin0 -> 14265 bytes
-rwxr-xr-x125/CH6/EX6.24/Fig6_24.sce36
-rwxr-xr-x125/CH6/EX6.24/Fig6_24_Trimmed_Filtering.JPGbin0 -> 13007 bytes
-rwxr-xr-x125/CH6/EX6.5/Fig6_5.sce37
-rwxr-xr-x125/CH6/EX6.5/Fig6_7_Degraded_NoiseImage_Restoration.JPGbin0 -> 47700 bytes
-rwxr-xr-x125/CH6/EX6.7/Fig6_5_DegradedImage_Restoration.JPGbin0 -> 30761 bytes
-rwxr-xr-x125/CH6/EX6.7/Fig6_7.sce38
-rwxr-xr-x125/CH6/EX6.7/Fig6_7_Degraded_NoiseImage_Restoration.JPGbin0 -> 47700 bytes
-rwxr-xr-x125/CH6/EX6.9/Fig6_9.sce41
-rwxr-xr-x125/CH6/EX6.9/Fig6_9_Degraded_NoiseImage_Restoration.JPGbin0 -> 43989 bytes
19 files changed, 319 insertions, 0 deletions
diff --git a/125/CH6/EX6.1/Fig6_1.sce b/125/CH6/EX6.1/Fig6_1.sce
new file mode 100755
index 000000000..4506c995b
--- /dev/null
+++ b/125/CH6/EX6.1/Fig6_1.sce
@@ -0,0 +1,19 @@
+//Caption:Scilab code to create motion blur
+//Fig6.1
+//page 326
+clc;
+close;
+a = imread('E:\DIP_JAYARAMAN\Chapter6\humm.jpg');//SIVP toolbox
+//filter coefficients of fspecial('motion',10,25)
+H =[0,0,0,0,0,0,0,0.0032,0.0449,0.0865,0.0072;...
+0,0,0,0,0,0.0092,0.0509,0.0925,0.0629,0.0213,0;...
+0,0,0,0.0152,0.0569,0.0985,0.0569,0.0152,0,0,0;...
+0,0.0213,0.0629,0.0925,0.0509,0.0092,0,0,0,0,0;...
+0.0072,0.0865,0.0449,0.0032,0,0,0,0,0,0,0];
+Motion_Blur = imfilter(a,H);
+Motion_Blur =uint8(Motion_Blur);
+ShowImage(a,'original Image')
+title('original Image')
+figure
+ShowImage(Motion_Blur,'Motion Blurred Image')
+title('10x25 Motion Blurred Image') \ No newline at end of file
diff --git a/125/CH6/EX6.1/Fig6_1_Blurring_Image.JPG b/125/CH6/EX6.1/Fig6_1_Blurring_Image.JPG
new file mode 100755
index 000000000..3293a5608
--- /dev/null
+++ b/125/CH6/EX6.1/Fig6_1_Blurring_Image.JPG
Binary files differ
diff --git a/125/CH6/EX6.13/Fig6_13.sce b/125/CH6/EX6.13/Fig6_13.sce
new file mode 100755
index 000000000..ff50a910d
--- /dev/null
+++ b/125/CH6/EX6.13/Fig6_13.sce
@@ -0,0 +1,42 @@
+//Caption: Scilab code to perform wiener filtering of the corrupted image
+//Fig6.13
+//Page 339
+close;
+clc;
+x = imread('E:\DIP_JAYARAMAN\Chapter6\flower2.jpg'); //SIVP toolbox
+x=double(rgb2gray(x));
+sigma = 50;
+Gamma = 1;
+alpha = 1; // It indicates Wiener filter
+[M N]=size(x);
+h = zeros(M,N);
+for i = 1:5
+ for j = 1:5
+ h(i,j) = 1/25;
+ end
+end
+Freqa = fft2d(x);
+Freqh = fft2d(h);
+y = real(ifft2d(Freqh.*Freqa)) //image degradation
+y = y+25*rand(M,N,"normal"); //Adding random noise with normal distribution
+Freqy = fft2d(y);
+Powy = abs(Freqy).^2/(M*N);
+sFreqh = Freqh.*(abs(Freqh)>0)+1/Gamma*(abs(Freqh)==0);
+iFreqh = 1/sFreqh;
+iFreqh = iFreqh'.*(abs(Freqh)*Gamma>1)+Gamma*abs(sFreqh)*iFreqh*(abs(sFreqh)*Gamma<=1);
+iFreqh = iFreqh/(max(max(abs(iFreqh))));
+Powy = Powy.*(Powy>sigma^2)+sigma^2*(Powy<=sigma^2);
+Freqg = iFreqh.*(Powy-sigma^2)./(Powy-(1-alpha)*sigma^2);
+ResFreqa = Freqg.*Freqy;
+Resa = real(ifft2d(ResFreqa));
+x = uint8(x);
+y = uint8(y);
+Resa = uint8(Resa);
+ShowImage(x,'Original Image')
+title('Original Image')
+figure
+ShowImage(y,'Degraded Image')
+title('Degraded Image')
+figure
+ShowImage(Resa,'Restored Image')
+title('Restored Image') \ No newline at end of file
diff --git a/125/CH6/EX6.13/Fig6_13_Image_Restoration.JPG b/125/CH6/EX6.13/Fig6_13_Image_Restoration.JPG
new file mode 100755
index 000000000..45de86b33
--- /dev/null
+++ b/125/CH6/EX6.13/Fig6_13_Image_Restoration.JPG
Binary files differ
diff --git a/125/CH6/EX6.18/Fig6_18.sce b/125/CH6/EX6.18/Fig6_18.sce
new file mode 100755
index 000000000..695254b9f
--- /dev/null
+++ b/125/CH6/EX6.18/Fig6_18.sce
@@ -0,0 +1,31 @@
+//Caption:Scilab code to Perform Average Filtering operation
+//Fig6.18
+//page 349
+clc;
+close;
+a= imread('E:\DIP_JAYARAMAN\Chapter6\lenna.jpg');//SIVP toolbox
+a=imnoise(a,'salt & pepper', 0.2); //Add salt&pepper noise tothe image
+a=double(a);
+[m n]=size(a);
+N=input('enter the window size='); //The window size can be 3x3,5x5etc
+Start=(N+1)/2;
+Out_Imag=a;
+for i=Start:(m-Start+1)
+for j=Start:(n-Start+1)
+ limit=(N-1)/2;
+ Sum=0;
+ for k=-limit:limit,
+ for l=-limit:limit,
+ Sum=Sum+a(i+k,j+l);
+ end
+ end
+ Out_Imag(i,j)=Sum/(N*N);
+end
+end
+a = uint8(a);
+Out_Imag = uint8(Out_Imag);
+ShowImage(a,'original Image')
+title('Noisy Image')
+figure
+ShowImage(Out_Imag,'average filtered Image')
+title('5x5 average filtered Image'); \ No newline at end of file
diff --git a/125/CH6/EX6.18/Fig6_18_Average_Filtering.JPG b/125/CH6/EX6.18/Fig6_18_Average_Filtering.JPG
new file mode 100755
index 000000000..70688f20a
--- /dev/null
+++ b/125/CH6/EX6.18/Fig6_18_Average_Filtering.JPG
Binary files differ
diff --git a/125/CH6/EX6.21/Fig6_21.sce b/125/CH6/EX6.21/Fig6_21.sce
new file mode 100755
index 000000000..aead6967b
--- /dev/null
+++ b/125/CH6/EX6.21/Fig6_21.sce
@@ -0,0 +1,49 @@
+//Caption:Scilab code to Perform median filtering
+//Fig6.21
+//page 352
+clc;
+close;
+c = imread('E:\DIP_JAYARAMAN\Chapter6\cameraman.jpg');//SIVP toolbox
+N = input('Enter the window size');
+a = double(imnoise(c,'salt & pepper',0.2));
+[m,n] = size(a);
+b = a;
+if(modulo(N,2)==1)
+ Start = (N+1)/2;
+ End = Start;
+ limit1 = (N-1)/2;
+ limit2 = limit1;
+else
+ Start = N/2;
+ End = Start+1;
+ limit1 = (N/2)-1;
+ limit2 = limit1+1;
+end
+for i = Start:(m-End+1)
+ for j = Start:(n-End+1)
+ I =1;
+ for k = -limit1:limit2
+ for l = -limit1:limit2
+ mat(I)= a(i+k,j+1)
+ I = I+1;
+ end
+ end
+ mat = gsort(mat);
+ if(modulo(N,2)==1)
+ b(i,j) = (mat(((N^2)+1)/2));
+ else
+ b(i,j) = (mat((N^2)/2)+mat(((N^2)/2)+1))/2;
+ end
+ end
+end
+a = uint8(a);
+b = uint8(b);
+figure
+ShowImage(c,'Original Image')
+title('Original Image')
+figure
+ShowImage(a,'noisy image')
+title('noisy image')
+figure
+ShowImage(b,'Median Filtered Image')
+title('5x5 Median Filtered Image') \ No newline at end of file
diff --git a/125/CH6/EX6.21/Fig6_21_Median_Filtering_GrayImage.JPG b/125/CH6/EX6.21/Fig6_21_Median_Filtering_GrayImage.JPG
new file mode 100755
index 000000000..b858a1054
--- /dev/null
+++ b/125/CH6/EX6.21/Fig6_21_Median_Filtering_GrayImage.JPG
Binary files differ
diff --git a/125/CH6/EX6.23/Fig6_23.sce b/125/CH6/EX6.23/Fig6_23.sce
new file mode 100755
index 000000000..8ec3f9b9b
--- /dev/null
+++ b/125/CH6/EX6.23/Fig6_23.sce
@@ -0,0 +1,26 @@
+//Caption:Scilab code to Perform median filtering of colour image
+//Fig6.23(a)
+//page 353
+clc;
+close;
+a=imread('E:\DIP_JAYARAMAN\Chapter6\peppers.png'); //SIVP toolbox
+N=input('enter the window size');
+b=imresize(a,[256,256]);
+b=imnoise(b,'salt & pepper',.1);
+[m n]=size(b);
+R=b(:,:,1);
+G=b(:,:,2);
+B=b(:,:,3);
+Out_R=Func_medianall(R,N);//Applying Median filter to ‘R’ plane
+Out_G=Func_medianall(G,N);//Applying Median filter to ‘G’ plane
+Out_B=Func_medianall(B,N);//Applying Median filter to ‘B’ plane
+Out_Image(:,:,1)=Out_R;
+Out_Image(:,:,2)=Out_G;
+Out_Image(:,:,3)=Out_B;
+b = uint8(b);
+Out_Image = uint8(Out_Image);
+//ShowColorImage(b,'noise added')
+//title('noise added')
+figure
+ShowColorImage(Out_Image,'3x3 median filtered')
+title('3x3 median filtered') \ No newline at end of file
diff --git a/125/CH6/EX6.23/Fig6_23_median_filtering_ColorImage.JPG b/125/CH6/EX6.23/Fig6_23_median_filtering_ColorImage.JPG
new file mode 100755
index 000000000..694b43140
--- /dev/null
+++ b/125/CH6/EX6.23/Fig6_23_median_filtering_ColorImage.JPG
Binary files differ
diff --git a/125/CH6/EX6.24/Fig6_24.sce b/125/CH6/EX6.24/Fig6_24.sce
new file mode 100755
index 000000000..2d6c7af5a
--- /dev/null
+++ b/125/CH6/EX6.24/Fig6_24.sce
@@ -0,0 +1,36 @@
+//Caption:Scilab code to Perform Trimmed Average Filter
+//Alpha trimmed average filter
+//Fig6.24
+//page 355
+clc;
+close;
+c = imread('E:\DIP_JAYARAMAN\Chapter6\lenna.jpg');//SIVP toolbox
+s = 1; //s denotes the number of values to be left in the end
+r = 1;
+N = 9; //3x3 window
+a = double(imnoise(c,'gaussian'));
+[m,n] = size(a);
+b = zeros(m,n);
+for i= 2:m-1
+ for j = 2:n-1
+ mat = [a(i,j),a(i,j-1),a(i,j+1),a(i-1,j),a(i+1,j),a(i-1,j-1),...
+ a(i-1,j+1),a(i-1,j+1),a(i+1,j+1)];
+ sorted_mat = gsort(mat);
+ Sum=0;
+ for k=r+s:(N-s)
+ Sum = Sum+mat(k);
+ end
+ b(i,j)= Sum/(N-r-s);
+ end
+end
+a = uint8(a);
+b = uint8(b);
+//figure
+//imshow(c)
+//title('Original Image')
+figure
+ShowImage(a,'noisy image')
+title('noisy image')
+figure
+ShowImage(b,'Trimmed Average Filtered Image')
+title('Trimmed Average Filtered Image') \ No newline at end of file
diff --git a/125/CH6/EX6.24/Fig6_24_Trimmed_Filtering.JPG b/125/CH6/EX6.24/Fig6_24_Trimmed_Filtering.JPG
new file mode 100755
index 000000000..4b8a7780d
--- /dev/null
+++ b/125/CH6/EX6.24/Fig6_24_Trimmed_Filtering.JPG
Binary files differ
diff --git a/125/CH6/EX6.5/Fig6_5.sce b/125/CH6/EX6.5/Fig6_5.sce
new file mode 100755
index 000000000..c82622ead
--- /dev/null
+++ b/125/CH6/EX6.5/Fig6_5.sce
@@ -0,0 +1,37 @@
+//Caption:Scilab code performs inverse filtering
+//Degrade the image by means of a known blur
+//Apply inverse filter to the blurred image and see the restored image
+//Fig6.5
+//page 330
+clc;
+close;
+x =imread('E:\DIP_JAYARAMAN\Chapter6\flower2.jpg');
+x=double(rgb2gray(x));
+[M N]=size(x);
+h = zeros(M,N);
+for i = 1:11
+ for j = 1:11
+ h(i,j) = 1/121;
+ end
+end
+sigma = sqrt(4*10^(-7));
+freqx = fft2d(x); //Fourier transform of input image
+freqh = fft2d(h);//Fourier transform of degradation
+y = real(ifft2d(freqh.*freqx));
+freqy = fft2d(y);
+powfreqx = freqx.^2/(M*N);
+alpha = 0.5; //Indicates inverse filter
+freqg = ((freqh.')').*abs(powfreqx)./(abs(freqh.^2).*abs(powfreqx)+alpha*sigma^2);
+Resfreqx = freqg.*freqy;
+Resa = real(ifft2d(Resfreqx));
+x = uint8(x);
+y = uint8(y);
+Resa = uint8(Resa)
+ShowImage(x,'Original Image')
+title('Original Image')
+figure
+ShowImage(y,'Degraded Image')
+title('Degraded Image')
+figure
+ShowImage(Resa,'Restored Image')
+title('Restored Image') \ No newline at end of file
diff --git a/125/CH6/EX6.5/Fig6_7_Degraded_NoiseImage_Restoration.JPG b/125/CH6/EX6.5/Fig6_7_Degraded_NoiseImage_Restoration.JPG
new file mode 100755
index 000000000..8b8ff8a19
--- /dev/null
+++ b/125/CH6/EX6.5/Fig6_7_Degraded_NoiseImage_Restoration.JPG
Binary files differ
diff --git a/125/CH6/EX6.7/Fig6_5_DegradedImage_Restoration.JPG b/125/CH6/EX6.7/Fig6_5_DegradedImage_Restoration.JPG
new file mode 100755
index 000000000..220368740
--- /dev/null
+++ b/125/CH6/EX6.7/Fig6_5_DegradedImage_Restoration.JPG
Binary files differ
diff --git a/125/CH6/EX6.7/Fig6_7.sce b/125/CH6/EX6.7/Fig6_7.sce
new file mode 100755
index 000000000..cc531f3e9
--- /dev/null
+++ b/125/CH6/EX6.7/Fig6_7.sce
@@ -0,0 +1,38 @@
+//Caption:Scilab code performs inverse filtering
+//Degrade the image by means of a known blur and white noise
+//The image is degraded as well as corrupted by noise
+//Apply inverse filter to restore the image
+//Fig6.7
+//page 332
+clc;
+close;
+x =imread('E:\DIP_JAYARAMAN\Chapter6\flower2.jpg');
+x=double(rgb2gray(x));
+[M N]=size(x);
+h = zeros(M,N);
+for i = 1:11
+ for j = 1:11
+ h(i,j) = 1/121;
+ end
+end
+sigma = sqrt(4*10^(-7));
+freqx = fft2d(x); //Fourier transform of input image
+freqh = fft2d(h);//Fourier transform of degradation
+y = real(ifft2d(freqh.*freqx))+10*rand(M,N,'normal');
+freqy = fft2d(y);
+powfreqx = freqx.^2/(M*N);
+alpha = 0.5; //Indicates inverse filter
+freqg = ((freqh.')').*abs(powfreqx)./(abs(freqh.^2).*abs(powfreqx)+alpha*sigma^2);
+Resfreqx = freqg.*freqy;
+Resa = real(ifft2d(Resfreqx));
+x = uint8(x);
+y = uint8(y);
+Resa = uint8(Resa)
+ShowImage(x,'Original Image')
+title('Original Image')
+figure
+ShowImage(y,'Degraded+noise Image')
+title('Degraded+noise Image')
+figure
+ShowImage(Resa,'Restored Image')
+title('Restored Image') \ No newline at end of file
diff --git a/125/CH6/EX6.7/Fig6_7_Degraded_NoiseImage_Restoration.JPG b/125/CH6/EX6.7/Fig6_7_Degraded_NoiseImage_Restoration.JPG
new file mode 100755
index 000000000..8b8ff8a19
--- /dev/null
+++ b/125/CH6/EX6.7/Fig6_7_Degraded_NoiseImage_Restoration.JPG
Binary files differ
diff --git a/125/CH6/EX6.9/Fig6_9.sce b/125/CH6/EX6.9/Fig6_9.sce
new file mode 100755
index 000000000..b6acb5a48
--- /dev/null
+++ b/125/CH6/EX6.9/Fig6_9.sce
@@ -0,0 +1,41 @@
+//Caption:Scilab code performs Pseudo inverse filtering
+//Degrade the image by means of a known blur and white noise
+//The image is degraded as well as corrupted by noise
+//Apply Pseudo inverse filter to restore the image
+//Fig6.9
+//page 333
+clc;
+close;
+x =imread('E:\DIP_JAYARAMAN\Chapter6\flower2.jpg');
+x=double(rgb2gray(x));
+[M N]=size(x);
+h = zeros(M,N);
+for i = 1:11
+ for j = 1:11
+ h(i,j) = 1/121;
+ end
+end
+mask_b = ones(11,11)/121;
+[m1,n1] = size(mask_b);
+Thr_Freq = 0.2;
+freqx = fft2d(x); //Fourier transform of input image
+freqh = fft2d(h);//Fourier transform of degradation
+y = real(ifft2d(freqh.*freqx))+25*rand(M,N,'normal');
+freqy = fft2d(y);
+psf=zeros(M,N);
+psf(M/2+1-(m1-1)/2:M/2+1+(m1-1)/2,N/2+1-(n1-1)/2:N/2+1+(n1-1)/2) = mask_b;
+psf = fftshift(psf);
+freq_res = fft2d(psf);
+Inv_filt = freq_res./((abs(freq_res)).^2+Thr_Freq);
+z = real(ifft2d(freqy.*Inv_filt));
+x = uint8(x);
+y = uint8(y);
+z = uint8(z)
+ShowImage(x,'Original Image')
+title('Original Image')
+figure
+ShowImage(y,'Degraded+noise Image')
+title('Degraded+noise Image')
+figure
+ShowImage(z,'Restored Image')
+title('Restored Image') \ No newline at end of file
diff --git a/125/CH6/EX6.9/Fig6_9_Degraded_NoiseImage_Restoration.JPG b/125/CH6/EX6.9/Fig6_9_Degraded_NoiseImage_Restoration.JPG
new file mode 100755
index 000000000..e49026e1e
--- /dev/null
+++ b/125/CH6/EX6.9/Fig6_9_Degraded_NoiseImage_Restoration.JPG
Binary files differ