diff options
Diffstat (limited to '125')
111 files changed, 1792 insertions, 0 deletions
diff --git a/125/CH1/EX1.13/Fig1_13.sce b/125/CH1/EX1.13/Fig1_13.sce new file mode 100755 index 000000000..9a17b6b67 --- /dev/null +++ b/125/CH1/EX1.13/Fig1_13.sce @@ -0,0 +1,34 @@ +//Caption: False contouring Scilab code
+//Fig1.13
+//page 13
+clc;
+close;
+a =ReadImage('E:\DIP_JAYARAMAN\Chapter1\tigerpub.jpg');
+a = uint8(a);
+figure
+imshow(a)
+title('Original image');
+//using 128 gray levels
+figure
+a_128 = grayslice(a,128);
+gray_128 = gray(128);
+ShowImage(a_128,'Image with 128 gray levels',gray_128);
+//using 64 gray levels
+figure
+a_64 = grayslice(a,64);
+gray_64 = gray(64);
+ShowImage(a_64,'Image with 64 gray levels',gray_64);
+//using 32 gray levels
+figure
+a_32 = grayslice(a,32);
+gray_32 = gray(32);
+ShowImage(a_32,'Image with 32 gray levels',gray_32);
+//using 16 gray levels
+figure
+a_16 = grayslice(a,16);
+gray_16 = gray(16);
+ShowImage(a_16,'Image with 16 gray levels',gray_16);
+//using 8 gray levels
+a_8 = grayslice(a,8);
+gray_8 = gray(8);
+ShowImage(a_8,'Image with 8 gray levels',gray_8);
\ No newline at end of file diff --git a/125/CH1/EX1.13/Fig1_13_graylevel_8_32_64_128.JPG b/125/CH1/EX1.13/Fig1_13_graylevel_8_32_64_128.JPG Binary files differnew file mode 100755 index 000000000..d1f532a86 --- /dev/null +++ b/125/CH1/EX1.13/Fig1_13_graylevel_8_32_64_128.JPG diff --git a/125/CH1/EX1.3/Example1_3.sce b/125/CH1/EX1.3/Example1_3.sce new file mode 100755 index 000000000..c806f83b2 --- /dev/null +++ b/125/CH1/EX1.3/Example1_3.sce @@ -0,0 +1,15 @@ +//Caption:Program to calculate number of samples required for an image
+//Example1.3
+//page 12
+clc;
+close;
+//dimension of the image in inches
+m = 4;
+n = 6;
+N = 400; //number of dots per inch in each direction
+N2 = 2*N; //number of dots per inch in both horizontal & vertical
+Fs = m*N2*n*N2;
+disp(Fs,'Number of samples reuqired to preserve the information in the image=')
+//Result
+//Number of samples reuqired to preserve the information in the image=
+//15360000.
\ No newline at end of file diff --git a/125/CH10/EX10.17/Fig10_17.sce b/125/CH10/EX10.17/Fig10_17.sce new file mode 100755 index 000000000..c4901e458 --- /dev/null +++ b/125/CH10/EX10.17/Fig10_17.sce @@ -0,0 +1,25 @@ +//Caption: Scilab Code for dilation and erosion process
+//Fig.10.17
+//Page553
+close;
+clear;
+clc;
+a = imread('E:\DIP_JAYARAMAN\Chapter10\morph1.bmp'); //SIVP toolbox
+//b =[1,1,1;1,1,1;1,1,1];
+StructureElement = CreateStructureElement('square', 3) ;
+a1 = DilateImage(a,StructureElement);
+a2 = ErodeImage(a,StructureElement);
+//Displaying original Image
+//imshow(a)
+figure(1)
+ShowImage(a,'Original Image');
+//Displaying Dilated Image
+//imshow(a1)
+figure(2)
+ShowImage(a1,'Dilated Image');
+xtitle('Dilated Image')
+//Displaying Eroded Image
+//imshow(a2)
+figure(3)
+ShowImage(a2,'Eroded Image');
+xtitle('Eroded Image')
\ No newline at end of file diff --git a/125/CH10/EX10.17/Fig10_17_Dilation_Erosion.JPG b/125/CH10/EX10.17/Fig10_17_Dilation_Erosion.JPG Binary files differnew file mode 100755 index 000000000..366881317 --- /dev/null +++ b/125/CH10/EX10.17/Fig10_17_Dilation_Erosion.JPG diff --git a/125/CH10/EX10.19/Fig10_19.sce b/125/CH10/EX10.19/Fig10_19.sce new file mode 100755 index 000000000..5de7f0d0d --- /dev/null +++ b/125/CH10/EX10.19/Fig10_19.sce @@ -0,0 +1,26 @@ +//Caption: Scilab Code to perform an opening and closing operation on the image
+//Fig.10.19
+//Page555
+close;
+clear;
+clc;
+a = imread('E:\DIP_JAYARAMAN\Chapter10\morph2.bmp'); //SIVP toolbox
+//b =[1,1,1;1,1,1;1,1,1];
+StructureElement = CreateStructureElement('square', 3) ;
+//Opening is done by first applying erosion and then dilation operations on image
+b1 = ErodeImage(a,StructureElement);
+b2 = DilateImage(b1,StructureElement);
+//Closing is done by first applying dilation and then erosion operation on image
+a1 = DilateImage(a,StructureElement);
+a2 = ErodeImage(a1,StructureElement);
+//Displaying original Image
+figure(1)
+ShowImage(a,'Original Image');
+//Displaying Opened Image
+figure(2)
+ShowImage(b2, 'Opened Image');
+xtitle('Opened Image')
+//Displaying Closed Image
+figure(3)
+ShowImage(a2, 'Closed Image');
+xtitle('Closed Image')
\ No newline at end of file diff --git a/125/CH10/EX10.19/Fig10_19_Image_opening_closing.JPG b/125/CH10/EX10.19/Fig10_19_Image_opening_closing.JPG Binary files differnew file mode 100755 index 000000000..0f04a00c6 --- /dev/null +++ b/125/CH10/EX10.19/Fig10_19_Image_opening_closing.JPG diff --git a/125/CH11/EX11.12/Fig11_12.sce b/125/CH11/EX11.12/Fig11_12.sce new file mode 100755 index 000000000..eca6d1fd5 --- /dev/null +++ b/125/CH11/EX11.12/Fig11_12.sce @@ -0,0 +1,21 @@ +//Caption:Read a Colour image and separate the colour image into: red,green
+//and blue planes
+//Fig.11.12: MATLAB Example2
+//page592
+clc;
+close;
+RGB = imread('E:\DIP_JAYARAMAN\Chapter11\peppers.png'); //SIVP toolbox
+a1 = RGB;
+b1 = RGB;
+c1 = RGB;
+a1(:,:,1)=0;
+b1(:,:,2)=0;
+c1(:,:,3)=0;
+figure(1)
+ShowColorImage(RGB, 'Original Color Image'); //IPD toolbox
+figure(2)
+ShowColorImage(a1, 'Red Missing');
+figure(3)
+ShowColorImage(b1, 'Green Missing');
+figure(4)
+ShowColorImage(c1, 'Blue Missing');
\ No newline at end of file diff --git a/125/CH11/EX11.12/Figure11_12_Different_Color_Planes.JPG b/125/CH11/EX11.12/Figure11_12_Different_Color_Planes.JPG Binary files differnew file mode 100755 index 000000000..bd444b8be --- /dev/null +++ b/125/CH11/EX11.12/Figure11_12_Different_Color_Planes.JPG diff --git a/125/CH11/EX11.16/Fig11_16.sce b/125/CH11/EX11.16/Fig11_16.sce new file mode 100755 index 000000000..45f136ac5 --- /dev/null +++ b/125/CH11/EX11.16/Fig11_16.sce @@ -0,0 +1,48 @@ +//Caption:Compute the histogram of the colour image
+//Fig.11.16: MATLAB Example3
+//page595
+clc;
+close;
+I = imread('E:\DIP_JAYARAMAN\Chapter11\lavender.jpg'); //SIVP toolbox
+figure(1)
+ShowColorImage(I, 'Original Color Image'); //IPD toolbox
+J = im2double(I);
+[index,map] = RGB2Ind(I); //IPD toolbox
+pixels = prod(size(index));
+hsv = rgb2hsv(J);
+h = hsv(:,1);
+s = hsv(:,2);
+v = hsv(:,3);
+//Finds location of black and white pixels
+darks = find(v<0.2);
+lights = find(s<0.05 & v>0.85);
+h([darks lights])=-1;
+//Gets the number of all pixels for each colour bin
+black_pixels = length(darks)/pixels;
+white_pixels = length(lights)/pixels;
+red = length(find((h > .9167 | h <= .083) & h ~= -1))/pixels;
+yellow = length(find(h > .083 & h <= .25))/pixels;
+green = length(find(h > .25 & h <= .4167))/pixels;
+cyan = length(find(h > .4167 & h <= .5833))/pixels;
+blue = length(find(h > .5833 & h <= .75))/pixels;
+magenta = length(find(h > .75 & h <= .9167))/pixels;
+//Plots histogram
+figure(2)
+a=gca();
+a.data_bounds=[0,0;8,1]
+n = 0:0.1:1;
+plot2d2(n,red*ones(1,length(n)),5)
+n1 = 1:0.1:2;
+plot2d2(n1,yellow*ones(1,length(n)),7)
+n2 = 2:0.1:3;
+plot2d2(n2,green*ones(1,length(n)),8)
+n3 = 3:0.1:4;
+plot2d2(n3,cyan*ones(1,length(n)),9)
+n4 = 4:0.1:5;
+plot2d2(n4,blue*ones(1,length(n)),2)
+n5 = 5:0.1:6;
+plot2d2(n5,magenta*ones(1,length(n)),3)
+n6 = 6:0.1:7;
+plot2d2(n6,white_pixels*ones(1,length(n)),0)
+n7 = 7:0.1:8
+plot2d2(n7,black_pixels*ones(1,length(n)),5)
\ No newline at end of file diff --git a/125/CH11/EX11.18/Fig11_18.sce b/125/CH11/EX11.18/Fig11_18.sce new file mode 100755 index 000000000..4174f4628 --- /dev/null +++ b/125/CH11/EX11.18/Fig11_18.sce @@ -0,0 +1,16 @@ +//Caption:Perform histogram equalisation of the given RGB image
+//Fig.11.18: MATLAB Example4
+//page596
+clc;
+close;
+a = imread('E:\DIP_JAYARAMAN\Chapter11\peppers.png'); //SIVP toolbox
+//conversion of RGB to YIQ format
+b = rgb2ntsc(a);
+//Histogram equalisation of Y component alone
+b(:,:,1) =
+//conversion of YIQ to RGB format
+c = ntsc2rgb(b);
+figure(1)
+ShowColorImage(a, 'Original Image'); //IPD toolbox
+figure(2)
+ShowColorImage(c, 'Histogtram equalized Image'); //IPD toolbox
\ No newline at end of file diff --git a/125/CH11/EX11.21/Fig11_21.sce b/125/CH11/EX11.21/Fig11_21.sce new file mode 100755 index 000000000..8067440da --- /dev/null +++ b/125/CH11/EX11.21/Fig11_21.sce @@ -0,0 +1,16 @@ +//Caption:This program performs median filtering of the colour image
+//Fig.11.21: MATLAB Example5
+//page598
+clc;
+close;
+a = imread('E:\DIP_JAYARAMAN\Chapter11\peppers.png'); //SIVP toolbox
+b = imnoise(a, 'salt & pepper', 0.2);
+c(:,:,1)= MedianFilter(b(:,:,1), [3 3]);
+c(:,:,2)= MedianFilter(b(:,:,2), [3 3]);
+c(:,:,3)= MedianFilter(b(:,:,3), [3 3]);
+figure(1)
+ShowColorImage(a, 'Original Image'); //IPD toolbox
+figure(2)
+ShowColorImage(b, 'corrupted Image'); //IPD toolbox
+figure(3)
+ShowColorImage(c, 'Median Filtered Image'); //IPD toolbox
\ No newline at end of file diff --git a/125/CH11/EX11.21/Figure11_21_MedianFiltering_ColorImage.JPG b/125/CH11/EX11.21/Figure11_21_MedianFiltering_ColorImage.JPG Binary files differnew file mode 100755 index 000000000..5f9752117 --- /dev/null +++ b/125/CH11/EX11.21/Figure11_21_MedianFiltering_ColorImage.JPG diff --git a/125/CH11/EX11.24/Fig11_24.sce b/125/CH11/EX11.24/Fig11_24.sce new file mode 100755 index 000000000..485bc2a81 --- /dev/null +++ b/125/CH11/EX11.24/Fig11_24.sce @@ -0,0 +1,26 @@ +//Caption:Fitlering only the luminance component
+//Fig.11.24: MATLAB Example6
+//page599
+clc;
+close;
+a = imread('E:\DIP_JAYARAMAN\Chapter11\peppers.png'); //SIVP toolbox
+//conversion of RGB to YIQ format
+yiq = rgb2ntsc(a);
+//Extract the Y component alone
+b = yiq(:,:,1);
+h = [-1,-1,-1;-1,8,-1;-1,-1,-1];
+//Perform high pass filtering only on Y component
+c1 = conv2d2(b,h);
+[m,n]= size(b);
+for i =1:m
+ for j=1:n
+ D(i,j)= c1(i,j);
+ end
+end
+yiq(:,:,1)=D;
+//convert YIQ to RGB format
+a1 = ntsc2rgb(yiq);
+figure(1)
+ShowColorImage(a, 'Original Image'); //IPD toolbox
+figure(2)
+ShowColorImage(a1, 'High Pass filtered Image'); //IPD toolbox
\ No newline at end of file diff --git a/125/CH11/EX11.24/Figure11_24_Filtering_Luminance_Component.JPG b/125/CH11/EX11.24/Figure11_24_Filtering_Luminance_Component.JPG Binary files differnew file mode 100755 index 000000000..43947084f --- /dev/null +++ b/125/CH11/EX11.24/Figure11_24_Filtering_Luminance_Component.JPG diff --git a/125/CH11/EX11.28/Fig11_28.sce b/125/CH11/EX11.28/Fig11_28.sce new file mode 100755 index 000000000..3969e3646 --- /dev/null +++ b/125/CH11/EX11.28/Fig11_28.sce @@ -0,0 +1,27 @@ +//Caption:Perform gamma correction for the given colour image
+//Fig.11.28: MATLAB Example7
+//page603
+close;
+clear;
+clc;
+I = imread('E:\DIP_JAYARAMAN\Chapter11\ararauna.png'); //SIVP toolbox
+gamma_Value = 0.5;
+max_intensity = 255; //for uint8 image
+//Look up table creation
+LUT = max_intensity.*(([0:max_intensity]./max_intensity).^gamma_Value);
+LUT = floor(LUT);
+//Mapping of input pixels into lookup table values
+K = double(I)+1;
+J = zeros(I);
+[m,n,p]= size(K);
+for i = 1:m
+ for j =1:n
+ for k = 1:p
+ J(i,j,k)= LUT(K(i,j,k));
+ end
+ end
+end
+figure(1)
+ShowColorImage(I, 'Original Image'); //IPD toolbox
+figure(2)
+ShowColorImage(uint8(J), 'Gamma Corrected Image'); //IPD toolbox
\ No newline at end of file diff --git a/125/CH11/EX11.28/Figure11_28_GammaCorrection_Color_Image.JPG b/125/CH11/EX11.28/Figure11_28_GammaCorrection_Color_Image.JPG Binary files differnew file mode 100755 index 000000000..c4b2240c9 --- /dev/null +++ b/125/CH11/EX11.28/Figure11_28_GammaCorrection_Color_Image.JPG diff --git a/125/CH11/EX11.30/Fig11_30.sce b/125/CH11/EX11.30/Fig11_30.sce new file mode 100755 index 000000000..33352c5fe --- /dev/null +++ b/125/CH11/EX11.30/Fig11_30.sce @@ -0,0 +1,38 @@ +//Caption:Perform Pseudo-Colouring Operation
+//Fig.11.30
+//page604
+close;
+clear;
+clc;
+K = imread('E:\DIP_JAYARAMAN\Chapter11\lenna.jpg'); //SIVP toolbox
+[m,n]= size(K);
+I = uint8(K);
+for i = 1:m
+ for j =1:n
+ if (I(i,j)>=0 & I(i,j)<50)
+ J(i,j,1)=I(i,j)+50;
+ J(i,j,2)=I(i,j)+100;
+ J(i,j,3)=I(i,j)+10;
+ elseif (I(i,j)>=50 & I(i,j)<100)
+ J(i,j,1)=I(i,j)+35;
+ J(i,j,2)=I(i,j)+128;
+ J(i,j,3)=I(i,j)+10;
+ elseif(I(i,j)>=100 & I(i,j)<150)
+ J(i,j,1)=I(i,j)+152;
+ J(i,j,2)=I(i,j)+130;
+ J(i,j,3)=I(i,j)+15;
+ elseif(I(i,j)>=150 & I(i,j)<200)
+ J(i,j,1)=I(i,j)+50;
+ J(i,j,2)=I(i,j)+140;
+ J(i,j,3)=I(i,j)+25;
+ elseif(I(i,j)>=200 & I(i,j)<=256)
+ J(i,j,1)=I(i,j)+120;
+ J(i,j,2)=I(i,j)+160;
+ J(i,j,3)=I(i,j)+45;
+ end
+ end
+end
+figure(1)
+ShowImage(K, 'Original Image'); //IPD toolbox
+figure(2)
+ShowColorImage(J, 'Pseudo Coloured Image'); //IPD toolbox
\ No newline at end of file diff --git a/125/CH11/EX11.30/Figure11_30_PseudoColouring.JPG b/125/CH11/EX11.30/Figure11_30_PseudoColouring.JPG Binary files differnew file mode 100755 index 000000000..7f653f553 --- /dev/null +++ b/125/CH11/EX11.30/Figure11_30_PseudoColouring.JPG diff --git a/125/CH11/EX11.32/Fig11_32.sce b/125/CH11/EX11.32/Fig11_32.sce new file mode 100755 index 000000000..78b1083e0 --- /dev/null +++ b/125/CH11/EX11.32/Fig11_32.sce @@ -0,0 +1,16 @@ +//Caption:Read an RGB image and segment it using the threshold method
+//Fig11.32
+//Page605
+close;
+clc;
+I = imread('E:\DIP_JAYARAMAN\Chapter11\ararauna.png'); //SIVP toolbox
+//Conversion of RGB to YCbCr
+b = rgb2ycbcr_1(I); //SIVP toolbox
+[m,n,p]=size(b);
+b = uint8(b);
+//Threshold is applied only to Cb component
+mask = b(:,:,2)>120;
+figure(1)
+ShowColorImage(I,'Original Image'); //IPD toolbox
+figure(2)
+ShowImage(mask, 'Segmented Image'); //IPD toolbox
\ No newline at end of file diff --git a/125/CH11/EX11.32/Figure11_32_Threshold_Color_Image.JPG b/125/CH11/EX11.32/Figure11_32_Threshold_Color_Image.JPG Binary files differnew file mode 100755 index 000000000..2567dfdf2 --- /dev/null +++ b/125/CH11/EX11.32/Figure11_32_Threshold_Color_Image.JPG diff --git a/125/CH11/EX11.4/Fig11_4.sce b/125/CH11/EX11.4/Fig11_4.sce new file mode 100755 index 000000000..22e93505a --- /dev/null +++ b/125/CH11/EX11.4/Fig11_4.sce @@ -0,0 +1,25 @@ +//Caption:Read an RGB image and extract the three colour components: red,green
+//and blue
+//Fig.11.4: MATLAB Example1
+//page588
+clc;
+close;
+RGB = imread('E:\DIP_JAYARAMAN\Chapter11\peppers.png'); //SIVP toolbox
+R = RGB;
+G = RGB;
+B = RGB;
+R(:,:,2)=0;
+R(:,:,3)=0;
+G(:,:,1)=0;
+G(:,:,3)=0;
+B(:,:,1)=0;
+B(:,:,2)=0;
+figure(1)
+ShowColorImage(RGB, 'Original Color Image'); //IPD toolbox
+title('Original Color Image');
+figure(2)
+ShowColorImage(R, 'Red Component');
+figure(3)
+ShowColorImage(G, 'Green Component');
+figure(4)
+ShowColorImage(B, 'Blue Component');
\ No newline at end of file diff --git a/125/CH11/EX11.4/Figure11_4_Extraction_of_three_colors.JPG b/125/CH11/EX11.4/Figure11_4_Extraction_of_three_colors.JPG Binary files differnew file mode 100755 index 000000000..295d5e6a6 --- /dev/null +++ b/125/CH11/EX11.4/Figure11_4_Extraction_of_three_colors.JPG diff --git a/125/CH12/EX12.42/Fig12_42.sce b/125/CH12/EX12.42/Fig12_42.sce new file mode 100755 index 000000000..5f016599a --- /dev/null +++ b/125/CH12/EX12.42/Fig12_42.sce @@ -0,0 +1,50 @@ +//Caption: Scilab code to generate different levels of a Gaussian pyramid
+//Fig12.42
+//Page651
+clc;
+close;
+a = imread('E:\DIP_JAYARAMAN\Chapter12\apple3.bmp');
+a = rgb2gray(a);
+b = a;
+kernelsize = input('Enter the size of the kernel:');
+sd = input('Enter the standard deviation of hte Gaussian window:');
+rf = input('Enter the Reduction Factor:');
+//Routine to generate Gaussian kernel
+k = zeros(kernelsize, kernelsize);
+[m n] = size(b);
+t = 0;
+for i = 1:kernelsize
+ for j=1:kernelsize
+ k(i,j) = exp(-((i-kernelsize/2).^2+(j-kernelsize/2).^2)/(2*sd.^2))/(2*%pi*sd.^2);
+ t = t+k(i,j);
+ end
+end
+for i = 1:kernelsize
+ for j = 1:kernelsize
+ k(i,j) = k(i,j)/t;
+ end
+end
+for t = 1:1:rf
+ //convolve it with the picture
+ FilteredImg = b;
+ if t==1
+ FilteredImg = filter2(k,b)/255;
+ else
+ FilteredImg = filter2(k,b);
+ end;
+ //compute the size of the reduced image
+ m = m/2;
+ n = n/2;
+ //create the reduced image through sampling
+ b = zeros(m,n);
+ for i = 1:m
+ for j = 1:n
+ b(i,j) = FilteredImg(i*2,j*2);
+ end;
+ end;
+ end;
+figure
+ShowImage(a,'Original Image')
+figure
+ShowImage(b,'Different Levels of Gausain Pyramid')
+title('Different Levels of Gausain Pyramid Level 2')
\ No newline at end of file diff --git a/125/CH12/EX12.42/Fig12_42_DifferentLevels_Gaussian_Pyramid.JPG b/125/CH12/EX12.42/Fig12_42_DifferentLevels_Gaussian_Pyramid.JPG Binary files differnew file mode 100755 index 000000000..79e1a8185 --- /dev/null +++ b/125/CH12/EX12.42/Fig12_42_DifferentLevels_Gaussian_Pyramid.JPG diff --git a/125/CH12/EX12.57/Fig12_57.sce b/125/CH12/EX12.57/Fig12_57.sce new file mode 100755 index 000000000..ada0b9afb --- /dev/null +++ b/125/CH12/EX12.57/Fig12_57.sce @@ -0,0 +1,41 @@ +//Caption: Scilab code to implement watermarking in spatial domain
+//Fig12.57
+//Page662
+clc
+close
+a = imread('E:\DIP_JAYARAMAN\Chapter12\cameraman.jpg');
+figure
+imshow(a)
+title('Base Image');
+b = imread('E:\DIP_JAYARAMAN\Chapter12\keyimage.jpg');
+b = rgb2gray(b);
+b = imresize(b,[32 32],'bicubic');
+[m1 n1]=size(b);
+figure
+imshow(b)
+title('Mark Image');
+[m n]=size(a);
+i1 = 1;
+j1 = 1;
+p = 1;
+c = a;
+iii = 1;
+jjj = 1;
+a = uint8(a);
+b = uint8(b);
+for ff = 1:8
+ for i = 1:32
+ jjj = 1;
+ for j = j1:j1+n1-1
+ a(i,j) = bitand(a(i,j),uint8(254)); // LSB of base image is set to zero.
+ temp = bitand(b(i,jjj),uint8((2^ff)-1)); //MSB of the mark is extracted.
+ temp = temp/((2^ff)-1);
+ c(i,j) = bitor(a(i,j),uint8(temp));//MSB of mark is inerted into the %LSB of the base
+ jjj = jjj+1;
+ end
+ end
+ j1 = j1+32;
+end
+imshow(c)
+title('Marked Image');
+imwrite(c,'E:\DIP_JAYARAMAN\Chapter12\markimg.jpg');
\ No newline at end of file diff --git a/125/CH12/EX12.57/Fig12_57_WaterMarking.JPG b/125/CH12/EX12.57/Fig12_57_WaterMarking.JPG Binary files differnew file mode 100755 index 000000000..ee98926b4 --- /dev/null +++ b/125/CH12/EX12.57/Fig12_57_WaterMarking.JPG diff --git a/125/CH12/EX12.63/Fig12_63.sce b/125/CH12/EX12.63/Fig12_63.sce new file mode 100755 index 000000000..3bc577547 --- /dev/null +++ b/125/CH12/EX12.63/Fig12_63.sce @@ -0,0 +1,52 @@ +//Caption: Scilab code to implement wavelet-based watermarking
+//Fig12.63
+//Page666
+clc;
+close;
+//Original Image
+img = imread('E:\DIP_JAYARAMAN\Chapter12\cameraman.jpg');
+figure
+imshow(img)
+title('Original Image');
+[p q] = size(img);
+//Generate the key
+//key = imread('E:\DIP_JAYARAMAN\Chapter12\keyimg1.png');
+//key = imresize(key,[p q]);
+key = imread('E:\DIP_JAYARAMAN\Chapter12\keyimage.jpg');
+key = rgb2gray(key);
+c = 0.001; //Initialise the weight of Watermarking
+figure
+imshow(key)
+title('Key');
+//Wavelet transform of original image (base image)
+img = double(img);
+key = double(key);
+[ca,ch,cv,cd] = dwt2(img,'db1');//Compute 2D wavelet transform
+//Perform the watermarking
+y = [ca ch;cv cd];
+Y = y + c*key;
+p=p/2;
+q=q/2;
+for i=1:p
+ for j=1:q
+ nca(i,j) = Y(i,j);
+ ncv(i,j) = Y(i+p,j);
+ nch(i,j) = Y(i,j+q);
+ ncd(i,j) = Y (i+p,j+q);
+ end
+end
+//Display the Watermarked image
+wimg = idwt2(nca,nch,ncv,ncd,'db1');
+wimg1 = uint8(wimg);
+figure
+imshow(wimg1)
+title('Watermarked Image')
+//Extraction of key from Watermarked image
+[rca,rch,rcv,rcd] = dwt2(wimg,'db1'); //Compute 2D wavelet transform
+n1=[rca,rch;rcv,rcd];
+N1=n1-y;
+N1 = N1*4;
+N1 = im2int8(N1);
+figure
+imshow(N1)
+title('Extract the key from watermarked image')
\ No newline at end of file diff --git a/125/CH12/EX12.9/Fig12_9.sce b/125/CH12/EX12.9/Fig12_9.sce new file mode 100755 index 000000000..2c442cac0 --- /dev/null +++ b/125/CH12/EX12.9/Fig12_9.sce @@ -0,0 +1,25 @@ +//Caption: Scilab code to perform wavelet decomposition
+//Fig12.10
+//Page624
+clc;
+close;
+x = ReadImage('E:\DIP_JAYARAMAN\Chapter12\lenna.jpg');
+//The image in unsigned integer or double has to be converted into normalized
+//double format
+x = im2double(x);
+//First Level decomposition
+[CA,CH,CV,CD]=dwt2(x,'db1');
+//Second level decomposition
+[CA1,CH1,CV1,CD1]=dwt2(CA,'db1');
+CA = im2int8(CA);
+CH = im2int8(CH);
+CV = im2int8(CV);
+CD = im2int8(CD);
+CA1 = im2int8(CA1);
+CH1 = im2int8(CH1);
+CV1 = im2int8(CV1);
+CD1 = im2int8(CD1);
+A = [CA,CH;CV,CD];
+B = [CA1,CH1;CV1,CD1];
+imshow(B)
+title('Result of Second Level Decomposition')
\ No newline at end of file diff --git a/125/CH2/EX2.12/Fig2_12.jpg b/125/CH2/EX2.12/Fig2_12.jpg Binary files differnew file mode 100755 index 000000000..e4cc014f2 --- /dev/null +++ b/125/CH2/EX2.12/Fig2_12.jpg diff --git a/125/CH2/EX2.12/Fig2_12.sce b/125/CH2/EX2.12/Fig2_12.sce new file mode 100755 index 000000000..b94b462b3 --- /dev/null +++ b/125/CH2/EX2.12/Fig2_12.sce @@ -0,0 +1,9 @@ +//Caption: Frequency Response
+//Fig2.12
+//page 60
+clc;
+close;
+[X, Y] = meshgrid(-%pi:.09:%pi);
+Z = 2*cos(X)+2*cos(Y);
+surf(X,Y,Z);
+xgrid(1)
\ No newline at end of file diff --git a/125/CH2/EX2.16/Fig2_16.jpg b/125/CH2/EX2.16/Fig2_16.jpg Binary files differnew file mode 100755 index 000000000..bc452ccad --- /dev/null +++ b/125/CH2/EX2.16/Fig2_16.jpg diff --git a/125/CH2/EX2.16/Fig2_16.sce b/125/CH2/EX2.16/Fig2_16.sce new file mode 100755 index 000000000..caa7e1a4c --- /dev/null +++ b/125/CH2/EX2.16/Fig2_16.sce @@ -0,0 +1,9 @@ +//Caption: Frequency Response
+//Fig2.16
+//page 64
+clc;
+close;
+[X, Y] = meshgrid(-%pi:.05:%pi);
+Z = 2-cos(X)-cos(Y);
+surf(X,Y,Z);
+xgrid(1)
\ No newline at end of file diff --git a/125/CH3/EX3.1/Example3_1.sce b/125/CH3/EX3.1/Example3_1.sce new file mode 100755 index 000000000..aab5c7ac9 --- /dev/null +++ b/125/CH3/EX3.1/Example3_1.sce @@ -0,0 +1,17 @@ +//Caption: 2-D Linear Convolution
+//Example3.1 & Example3.4
+//page 85 & page 107
+clc;
+x =[4,5,6;7,8,9];
+h = [1;1;1];
+disp(x,'x=')
+disp(h,'h=')
+[y,X,H] = conv2d2(x,h);
+disp(y,'Linear 2D convolution result y =')
+//Result
+//Linear 2D convolution result y =
+//
+// 4. 5. 6.
+// 11. 13. 15.
+// 11. 13. 15.
+// 7. 8. 9.
\ No newline at end of file diff --git a/125/CH3/EX3.11/Example3_11.sce b/125/CH3/EX3.11/Example3_11.sce new file mode 100755 index 000000000..da378fd02 --- /dev/null +++ b/125/CH3/EX3.11/Example3_11.sce @@ -0,0 +1,15 @@ +//Caption: Linear COnvolution of any signal with an impulse signal gives
+//rise to the same signal
+//Example3.11
+//page 121
+clc;
+x =[1,2;3,4];
+h = 1;
+y = conv2d2(x,h);
+disp(y,'Linear 2D convolution result y =')
+//Result
+//Linear 2D convolution result y =
+//// Linear 2D convolution result y =
+//
+// 1. 2.
+// 3. 4.
diff --git a/125/CH3/EX3.12/Example3_12.sce b/125/CH3/EX3.12/Example3_12.sce new file mode 100755 index 000000000..ce7187465 --- /dev/null +++ b/125/CH3/EX3.12/Example3_12.sce @@ -0,0 +1,16 @@ +//Caption: Circular Convolution between two 2D matrices
+//Example3.12
+//page 122
+clc;
+x = [1,2;3,4];
+h = [5,6;7,8];
+X = fft2d(x); //2D FFT of x matrix
+H = fft2d(h); //2D FFT of h matrix
+Y = X.*H; //Element by Element multiplication
+y = ifft2d(Y);
+disp(y,'Circular Convolution Result y =')
+//Result
+//Circular Convolution Result y =
+//
+// 70. 68.
+// 62. 60.
\ No newline at end of file diff --git a/125/CH3/EX3.13/Example3_13.sce b/125/CH3/EX3.13/Example3_13.sce new file mode 100755 index 000000000..ca2adb2e5 --- /dev/null +++ b/125/CH3/EX3.13/Example3_13.sce @@ -0,0 +1,23 @@ +//Caption: Circular Convolution expressed as linear convolution plus alias
+//Example3.13
+//page 123
+clc;
+x = [1,2;3,4];
+h = [5,6;7,8];
+y = conv2d(x,h);
+y1 = [y(:,1)+y(:,$),y(:,2)];
+y2 = [y1(1,:)+y1($,:);y1(2,:)]
+disp(y,'Linear Convolution result y=')
+disp(y2,'circular convolution expessed as linear convolution plus alias =')
+//Result
+// Linear Convolution result y=
+//
+// 5. 16. 12.
+// 22. 60. 40.
+// 21. 52. 32.
+//
+// circular convolution expessed as linear convolution plus alias =
+//
+// 70. 68.
+// 62. 60.
+//
\ No newline at end of file diff --git a/125/CH3/EX3.14/Example3_14.sce b/125/CH3/EX3.14/Example3_14.sce new file mode 100755 index 000000000..40b848a71 --- /dev/null +++ b/125/CH3/EX3.14/Example3_14.sce @@ -0,0 +1,16 @@ +//Caption: linear cross correlation of a 2D matrix
+//Example3.14
+//page 129
+clc;
+x = [3,1;2,4];
+h1 = [1,5;2,3];
+h2 = h1(:,$:-1:1);
+h = h2($:-1:1,:);
+y = conv2d(x,h)
+disp(y,'Linear cross Correlation result y=')
+//Result
+//Linear cross Correlation result y=
+//
+// 9. 9. 2.
+// 21. 24. 9.
+// 10. 22. 4.
\ No newline at end of file diff --git a/125/CH3/EX3.15/Example3_15.sce b/125/CH3/EX3.15/Example3_15.sce new file mode 100755 index 000000000..08afb469f --- /dev/null +++ b/125/CH3/EX3.15/Example3_15.sce @@ -0,0 +1,18 @@ +//Caption: Circular correlation between two signals
+//Example3.15
+//page 131
+clc;
+x = [1,5;2,4];
+h = [3,2;4,1];
+h = h(:,$:-1:1);
+h = h($:-1:1,:);
+X = fft2d(x);
+H = fft2d(h);
+Y = X.*H;
+y = ifft2d(Y);
+disp(y,'Circular Correlation result y=')
+//Result
+//Circular Correlation result y=
+//
+// 37. 23.
+// 35. 25.
\ No newline at end of file diff --git a/125/CH3/EX3.16/Example3_16.sce b/125/CH3/EX3.16/Example3_16.sce new file mode 100755 index 000000000..f4808115b --- /dev/null +++ b/125/CH3/EX3.16/Example3_16.sce @@ -0,0 +1,18 @@ +//Caption: Circular correlation between two signals
+//Example3.16
+//page 134
+clc;
+x = [5,10;15,20];
+h = [3,6;9,12];
+h = h(:,$:-1:1);
+h = h($:-1:1,:);
+X = fft2d(x);
+H = fft2d(h);
+Y = X.*H;
+y = ifft2d(Y);
+disp(y,'Circular Correlation result y=')
+//Result
+// Circular Correlation result y=
+//
+// 300. 330.
+// 420. 450.
diff --git a/125/CH3/EX3.17/Example3_17.sce b/125/CH3/EX3.17/Example3_17.sce new file mode 100755 index 000000000..9fb14bbc6 --- /dev/null +++ b/125/CH3/EX3.17/Example3_17.sce @@ -0,0 +1,15 @@ +//Caption: linear auto correlation of a 2D matrix
+//Example3.17
+//page 136
+clc;
+x1 = [1,1;1,1];
+x2 = x1(:,$:-1:1);
+x2 = x2($:-1:1,:);
+x = conv2d(x1,x2)
+disp(x,'Linear auto Correlation result x=')
+//Result
+//Linear auto Correlation result x=
+//
+// 1. 2. 1.
+// 2. 4. 2.
+// 1. 2. 1.
\ No newline at end of file diff --git a/125/CH3/EX3.18/Example3_18.sce b/125/CH3/EX3.18/Example3_18.sce new file mode 100755 index 000000000..cf32ef020 --- /dev/null +++ b/125/CH3/EX3.18/Example3_18.sce @@ -0,0 +1,16 @@ +//Caption: linear cross correlation of a 2D matrix
+//Example3.18
+//page 141
+clc;
+x = [1,1;1,1];
+h1 = [1,2;3,4];
+h2 = h1(:,$:-1:1);
+h = h2($:-1:1,:);
+y = conv2d(x,h)
+disp(y,'Linear cross Correlation result y=')
+//Result
+//Linear cross Correlation result y=
+//
+// 4. 7. 3.
+// 6. 10. 4.
+// 2. 3. 1.
\ No newline at end of file diff --git a/125/CH3/EX3.2/Example3_2.sce b/125/CH3/EX3.2/Example3_2.sce new file mode 100755 index 000000000..3a35beae6 --- /dev/null +++ b/125/CH3/EX3.2/Example3_2.sce @@ -0,0 +1,17 @@ +//Caption: 2-D Linear Convolution
+//Example3.2 & Example3.5 & Example3.9
+//page 91 & page 108 & page 116
+clc;
+x =[1,2,3;4,5,6;7,8,9];
+h = [1,1;1,1;1,1];
+y = conv2d2(x,h);
+disp(y,'Linear 2D convolution result y =')
+//Result
+// Linear 2D convolution result y =
+//
+// 1. 3. 5. 3.
+// 5. 12. 16. 9.
+// 12. 27. 33. 18.
+// 11. 24. 28. 15.
+// 7. 15. 17. 9.
+//
\ No newline at end of file diff --git a/125/CH3/EX3.3/Example3_3.sce b/125/CH3/EX3.3/Example3_3.sce new file mode 100755 index 000000000..b7e620e54 --- /dev/null +++ b/125/CH3/EX3.3/Example3_3.sce @@ -0,0 +1,14 @@ +//Caption: 2-D Linear Convolution
+//Example3.3 & Example3.6 & Example3.10
+//page 100 & page 109 & page 119
+clc;
+x =[1,2,3;4,5,6;7,8,9];
+h = [3,4,5];
+y = conv2d2(x,h);
+disp(y,'Linear 2D convolution result y =')
+//Result
+//Linear 2D convolution result y =
+//
+// 3. 10. 22. 22. 15.
+// 12. 31. 58. 49. 30.
+// 21. 52. 94. 76. 45.
\ No newline at end of file diff --git a/125/CH3/EX3.7/Example3_7.sce b/125/CH3/EX3.7/Example3_7.sce new file mode 100755 index 000000000..a7a75891c --- /dev/null +++ b/125/CH3/EX3.7/Example3_7.sce @@ -0,0 +1,15 @@ +//Caption: 2-D Linear Convolution
+//Example3.7
+//page 111
+clc;
+x =[1,2;3,4];
+h = [5,6;7,8];
+y = conv2d2(x,h);
+disp(y,'Linear 2D convolution result y =')
+//Result
+// Linear 2D convolution result y =
+//Linear 2D convolution result y =
+//
+// 5. 16. 12.
+// 22. 60. 40.
+// 21. 52. 32
\ No newline at end of file diff --git a/125/CH3/EX3.8/Example3_8.sce b/125/CH3/EX3.8/Example3_8.sce new file mode 100755 index 000000000..39d74b048 --- /dev/null +++ b/125/CH3/EX3.8/Example3_8.sce @@ -0,0 +1,15 @@ +//Caption: 2-D Linear Convolution
+//Example3.8
+//page 113
+clc;
+x =[1,2,3;4,5,6;7,8,9];
+h = [1;1;1];
+y = conv2d2(x,h);
+disp(y,'Linear 2D convolution result y =')
+//Result
+// Linear 2D convolution result y =
+//// 1. 2. 3.
+// 5. 7. 9.
+// 12. 15. 18.
+// 11. 13. 15.
+// 7. 8. 9.
diff --git a/125/CH4/EX4.10/Example4_10.sce b/125/CH4/EX4.10/Example4_10.sce new file mode 100755 index 000000000..8f9565b26 --- /dev/null +++ b/125/CH4/EX4.10/Example4_10.sce @@ -0,0 +1,14 @@ +//Caption: Program to compute discrete cosine tranform
+//Example4.10
+//page 198
+clc;
+N =4; //DCT matrix of order four
+X = dct_mtx(N);
+disp(X,'DCT matrix of order four')
+//Result
+//DCT matrix of order four
+//
+// 0.5 0.5 0.5 0.5
+// 0.6532815 0.2705981 - 0.2705981 - 0.6532815
+// 0.5 - 0.5 - 0.5 0.5
+// 0.2705981 - 0.6532815 0.6532815 - 0.2705981
\ No newline at end of file diff --git a/125/CH4/EX4.10/Example4_6_3.jpg b/125/CH4/EX4.10/Example4_6_3.jpg Binary files differnew file mode 100755 index 000000000..a8d36fdfe --- /dev/null +++ b/125/CH4/EX4.10/Example4_6_3.jpg diff --git a/125/CH4/EX4.10/Example4_6_4.jpg b/125/CH4/EX4.10/Example4_6_4.jpg Binary files differnew file mode 100755 index 000000000..fc65564e8 --- /dev/null +++ b/125/CH4/EX4.10/Example4_6_4.jpg diff --git a/125/CH4/EX4.12/Example4_12.sce b/125/CH4/EX4.12/Example4_12.sce new file mode 100755 index 000000000..335cc4b0a --- /dev/null +++ b/125/CH4/EX4.12/Example4_12.sce @@ -0,0 +1,57 @@ +//Caption: Program to perform KL transform for the given 2D matrix
+//Example4.12
+//page 208
+clear;
+clc;
+X = [4,3,5,6;4,2,7,7;5,5,6,7];
+[m,n]= size(X);
+A = [];
+E = [];
+for i =1:n
+ A = A+X(:,i);
+ E = E+X(:,i)*X(:,i)';
+end
+mx = A/n; //mean matrix
+E = E/n;
+C = E - mx*mx';//covariance matrix C = E[xx']-mx*mx'
+[V,D] = spec(C); //eigen values and eigen vectors
+d = diag(D); //diagonal elements od eigen values
+[d,i] = gsort(d); //sorting the elements of D in descending order
+for j = 1:length(d)
+ T(:,j)= V(:,i(j));
+end
+T =T'
+disp(d,'Eigen Values are U = ')
+disp(T,'The eigen vector matrix T =')
+disp(T,'The KL tranform basis is =')
+//KL transform
+for i = 1:n
+ Y(:,i)= T*X(:,i);
+end
+disp(Y,'KL transformation of the input matrix Y =')
+//Reconstruction
+for i = 1:n
+ x(:,i)= T'*Y(:,i);
+end
+disp(x,'Reconstruct matrix of the given sample matrix X =')
+//Result
+// Eigen Values are U =
+// 6.1963372
+// 0.2147417
+// 0.0264211
+// The eigen vector matrix T =
+// 0.4384533 0.8471005 0.3002988
+// 0.4460381 - 0.4951684 0.7455591
+// - 0.7802620 0.1929481 0.5949473
+// The KL tranform basis is =
+// 0.4384533 0.8471005 0.3002988
+// 0.4460381 - 0.4951684 0.7455591
+// - 0.7802620 0.1929481 0.5949473
+// KL transformation of the input matrix Y =
+// 6.6437095 4.5110551 9.9237632 10.662515
+// 3.5312743 4.0755729 3.2373664 4.4289635
+// 0.6254808 1.0198466 1.0190104 0.8336957
+// Reconstruct matrix of the given sample matrix x =
+// 4. 3. 5. 6.
+// 4. 2. 7. 7.
+// 5. 5. 6. 7.
\ No newline at end of file diff --git a/125/CH4/EX4.13/Example4_13.sce b/125/CH4/EX4.13/Example4_13.sce new file mode 100755 index 000000000..7fdb3f88d --- /dev/null +++ b/125/CH4/EX4.13/Example4_13.sce @@ -0,0 +1,33 @@ +//Caption: Program to find the singular value decomposition of given matrix
+//Example4.13
+//page 210
+clear;
+clc;
+A = [1,-2,3;3,2,-1];
+[U,S,V]= svd(A);
+A_recon = U*S*V';
+disp(U,'U =')
+disp(S,'S =')
+disp(V,'V =')
+disp(A_recon,'A matrix from svd =')
+//Result
+// U =
+//
+// - 0.7071068 0.7071068
+// 0.7071068 0.7071068
+//
+// S =
+//
+// 4.2426407 0. 0.
+// 0. 3.1622777 0.
+//
+// V =
+//
+// 0.3333333 0.8944272 - 0.2981424
+// 0.6666667 - 2.776D-16 0.7453560
+// - 0.6666667 0.4472136 0.5962848
+//
+// A matrix from svd =
+//
+// 1. - 2. 3.
+// 3. 2. - 1.
\ No newline at end of file diff --git a/125/CH4/EX4.4/Example4_4.sce b/125/CH4/EX4.4/Example4_4.sce new file mode 100755 index 000000000..9530d43d1 --- /dev/null +++ b/125/CH4/EX4.4/Example4_4.sce @@ -0,0 +1,16 @@ +//Caption: 2D DFT of 4x4 grayscale image
+//Example4.4
+//page 170
+clc;
+f = [1,1,1,1;1,1,1,1;1,1,1,1;1,1,1,1];
+N =4; //4-point DFT
+kernel = dft_mtx(N);
+F = kernel*(f*kernel');
+disp(F,'2D DFT of given 2D image =')
+//Result
+//2D DFT of given 2D image =
+//
+// 16. 0 0 0
+// 0 0 0 0
+// 0 0 0 0
+// 0 0 0 0
\ No newline at end of file diff --git a/125/CH4/EX4.5/Example4_5.sce b/125/CH4/EX4.5/Example4_5.sce new file mode 100755 index 000000000..b8856e64d --- /dev/null +++ b/125/CH4/EX4.5/Example4_5.sce @@ -0,0 +1,17 @@ +//Caption: 2D DFT of 4x4 grayscale image
+//Example4.5
+//page 171
+clc;
+F = [16,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0];
+N =4; //4-point DFT
+kernel = dft_mtx(N);
+f = (kernel*(F*kernel'))/(N^2);
+f = real(f);
+disp(f,'Inverse 2D DFT of the transformed image f =')
+//Result
+//Inverse 2D DFT of the transformed image f =
+//
+// 1. 1. 1. 1.
+// 1. 1. 1. 1.
+// 1. 1. 1. 1.
+// 1. 1. 1. 1.
\ No newline at end of file diff --git a/125/CH4/EX4.6/Example4_6.sce b/125/CH4/EX4.6/Example4_6.sce new file mode 100755 index 000000000..7e14c8b63 --- /dev/null +++ b/125/CH4/EX4.6/Example4_6.sce @@ -0,0 +1,33 @@ +//Caption:Scilab code to intergchange phase information between two images
+//Example4.6
+//page 174-175
+clc;
+close;
+a = imread('E:\DIP_JAYARAMAN\Chapter4\lena.png'); //SIVP toolbox
+b = imread('E:\DIP_JAYARAMAN\Chapter4\baboon.png');
+a = rgb2gray(a);
+b = rgb2gray(b);
+a = imresize(a,0.5);
+b = imresize(b,0.5);
+figure(1)
+ShowImage(a,'Original lena Image'); //IPD toolbox
+title('Original lena Image');
+figure(2)
+ShowImage(b,'Original baboon Image');
+title('Original baboon Image')
+ffta = fft2d(double(a));
+fftb = fft2d(double(b));
+mag_a = abs(ffta);
+mag_b = abs(fftb);
+ph_a = atan(imag(ffta),real(ffta));
+ph_b = atan(imag(fftb),real(fftb));
+newfft_a = mag_a.*(exp(%i*ph_b));
+newfft_b = mag_b.*(exp(%i*ph_a));
+rec_a = ifft2d(newfft_a);
+rec_b = ifft2d(newfft_b);
+figure(3)
+ShowImage(uint8(rec_a),'lena Image after phase reversal');
+title('lena Image after phase reversal')
+figure(4)
+ShowImage(uint8(rec_b),'baboon Image after phase reversal');
+title('baboon Image after phase reversal')
\ No newline at end of file diff --git a/125/CH4/EX4.6/Example4_6_PhaseReversal.JPG b/125/CH4/EX4.6/Example4_6_PhaseReversal.JPG Binary files differnew file mode 100755 index 000000000..e1ca63b75 --- /dev/null +++ b/125/CH4/EX4.6/Example4_6_PhaseReversal.JPG diff --git a/125/CH5/EX5.13/Fig5_13.sce b/125/CH5/EX5.13/Fig5_13.sce new file mode 100755 index 000000000..df6816cbb --- /dev/null +++ b/125/CH5/EX5.13/Fig5_13.sce @@ -0,0 +1,12 @@ +//Caption:Scilab code to determine image negative
+//Fig.5.13
+//page 252
+clc;
+close;
+a = imread('E:\DIP_JAYARAMAN\Chapter5\label.jpg');
+k = 255-double(a);
+k = uint8(k);
+imshow(a);
+title('Original onca Image')
+imshow(k);
+title('Negative of Original Image')
\ No newline at end of file diff --git a/125/CH5/EX5.13/Fig5_13_ImageNegative.JPG b/125/CH5/EX5.13/Fig5_13_ImageNegative.JPG Binary files differnew file mode 100755 index 000000000..6ff7e5eae --- /dev/null +++ b/125/CH5/EX5.13/Fig5_13_ImageNegative.JPG diff --git a/125/CH5/EX5.16/Fig5_16.sce b/125/CH5/EX5.16/Fig5_16.sce new file mode 100755 index 000000000..2bdd953db --- /dev/null +++ b/125/CH5/EX5.16/Fig5_16.sce @@ -0,0 +1,27 @@ +//Caption:Scilab code that performs threshold operation
+//Fig5.16
+//page 254
+clc;
+close;
+a = imread('E:\Digital_Image_Processing_Jayaraman\Chapter5\lena.png');
+a = rgb2gray(a);
+[m n] = size(a);
+t = input('Enter the threshold parameter');
+for i = 1:m
+ for j = 1:n
+ if(a(i,j)<t)
+ b(i,j)=0;
+ else
+ b(i,j)=255;
+ end
+ end
+end
+figure(1)
+ShowImage(a,'Original Image');
+title('Original Image')
+figure(2)
+ShowImage(b,'Thresholded Image');
+title('Thresholded Image')
+xlabel(sprintf('Threshold value is %g',t))
+//Result
+//Enter the threshold parameter 140
\ No newline at end of file diff --git a/125/CH5/EX5.16/Fig5_16_Threshold_Image.JPG b/125/CH5/EX5.16/Fig5_16_Threshold_Image.JPG Binary files differnew file mode 100755 index 000000000..d237ba7ea --- /dev/null +++ b/125/CH5/EX5.16/Fig5_16_Threshold_Image.JPG diff --git a/125/CH5/EX5.20/Fig5_20.sce b/125/CH5/EX5.20/Fig5_20.sce new file mode 100755 index 000000000..4eb754250 --- /dev/null +++ b/125/CH5/EX5.20/Fig5_20.sce @@ -0,0 +1,27 @@ +//Caption: Program performs gray level slicing without background
+//Fig.5.20
+//page256
+clc;
+x = imread('E:\Digital_Image_Processing_Jayaraman\Chapter5\lena.png');
+x = rgb2gray(x);
+y = double(x);
+[m,n]= size(y);
+L = max(max(x));
+a = round(L/2);
+b = L;
+for i =1:m
+ for j =1:n
+ if(y(i,j)>=a & y(i,j)<=b)
+ z(i,j) = L;
+ else
+ z(i,j)=0;
+ end
+ end
+end
+z = uint8(z);
+figure(1)
+ShowImage(x,'Original Image');
+title('Orginal Image')
+figure(2)
+ShowImage(z,'Gray Level Slicing');
+title('Gray Level Slicing without preserving background')
\ No newline at end of file diff --git a/125/CH5/EX5.20/Fig5_20_Gray_level_Slicing.JPG b/125/CH5/EX5.20/Fig5_20_Gray_level_Slicing.JPG Binary files differnew file mode 100755 index 000000000..52904e537 --- /dev/null +++ b/125/CH5/EX5.20/Fig5_20_Gray_level_Slicing.JPG diff --git a/125/CH5/EX5.5/Fig5_5.sce b/125/CH5/EX5.5/Fig5_5.sce new file mode 100755 index 000000000..9ed62725c --- /dev/null +++ b/125/CH5/EX5.5/Fig5_5.sce @@ -0,0 +1,16 @@ +//Caption:Scilab code for brightness enhancement
+//Fig5.5
+//page 246
+clc;
+close;
+//a = imread('E:\DIP_JAYARAMAN\Chapter5\plate.GIF'); //SIVP toolbox
+a = imread('E:\DIP_JAYARAMAN\Chapter4\baboon.png');
+a = rgb2gray(a);
+b = double(a)+50;
+b = uint8(b);
+figure(1)
+ShowImage(a,'Original Image');
+title('Original Image')
+figure(2)
+ShowImage(b,'Enhanced Image');
+title('Enhanced Image')
\ No newline at end of file diff --git a/125/CH5/EX5.5/Fig5_5_Image_Enhancement.JPG b/125/CH5/EX5.5/Fig5_5_Image_Enhancement.JPG Binary files differnew file mode 100755 index 000000000..891961bd2 --- /dev/null +++ b/125/CH5/EX5.5/Fig5_5_Image_Enhancement.JPG diff --git a/125/CH5/EX5.7/Fig5_7.sce b/125/CH5/EX5.7/Fig5_7.sce new file mode 100755 index 000000000..9328c867f --- /dev/null +++ b/125/CH5/EX5.7/Fig5_7.sce @@ -0,0 +1,15 @@ +//Caption:Scilab code for brightness suppression
+//Fig5.7
+//page 247
+clc;
+close;
+a = imread('E:\DIP_JAYARAMAN\Chapter4\baboon.png');
+a = rgb2gray(a);
+b = double(a)-50;
+b = uint8(b);
+figure(1)
+ShowImage(a,'Original Image');
+title('Original Image')
+figure(2)
+ShowImage(b,'Brightness Supressed Image');
+title('Brightness Supressed Image')
\ No newline at end of file diff --git a/125/CH5/EX5.7/Fig5_7_Brightness_Suppression.JPG b/125/CH5/EX5.7/Fig5_7_Brightness_Suppression.JPG Binary files differnew file mode 100755 index 000000000..aa5a44d87 --- /dev/null +++ b/125/CH5/EX5.7/Fig5_7_Brightness_Suppression.JPG diff --git a/125/CH5/EX5.9/Fig5_9.sce b/125/CH5/EX5.9/Fig5_9.sce new file mode 100755 index 000000000..985fcfc4d --- /dev/null +++ b/125/CH5/EX5.9/Fig5_9.sce @@ -0,0 +1,20 @@ +//Caption:Scilab code for Contrast Manipulation
+//Fig5.9
+//page 248
+clc;
+close;
+a = imread('E:\DIP_JAYARAMAN\Chapter4\lena.png');
+a = rgb2gray(a);
+b = double(a)*0.5;
+b = uint8(b)
+c = double(b)*2;
+c = uint8(c)
+figure(1)
+ShowImage(a,'Original Image');
+title('Original Image')
+figure(2)
+ShowImage(b,'Decrease in Contrast');
+title('Decrease in Contrast')
+figure(3)
+ShowImage(c,'Increase in Contrast');
+title('Increase in Contrast')
\ No newline at end of file diff --git a/125/CH5/EX5.9/Fig5_9_Contrast_Manipulation.JPG b/125/CH5/EX5.9/Fig5_9_Contrast_Manipulation.JPG Binary files differnew file mode 100755 index 000000000..ecf2d4920 --- /dev/null +++ b/125/CH5/EX5.9/Fig5_9_Contrast_Manipulation.JPG 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 Binary files differnew file mode 100755 index 000000000..3293a5608 --- /dev/null +++ b/125/CH6/EX6.1/Fig6_1_Blurring_Image.JPG 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 Binary files differnew file mode 100755 index 000000000..45de86b33 --- /dev/null +++ b/125/CH6/EX6.13/Fig6_13_Image_Restoration.JPG 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 Binary files differnew file mode 100755 index 000000000..70688f20a --- /dev/null +++ b/125/CH6/EX6.18/Fig6_18_Average_Filtering.JPG 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 Binary files differnew file mode 100755 index 000000000..b858a1054 --- /dev/null +++ b/125/CH6/EX6.21/Fig6_21_Median_Filtering_GrayImage.JPG 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 Binary files differnew file mode 100755 index 000000000..694b43140 --- /dev/null +++ b/125/CH6/EX6.23/Fig6_23_median_filtering_ColorImage.JPG 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 Binary files differnew file mode 100755 index 000000000..4b8a7780d --- /dev/null +++ b/125/CH6/EX6.24/Fig6_24_Trimmed_Filtering.JPG 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 Binary files differnew file mode 100755 index 000000000..8b8ff8a19 --- /dev/null +++ b/125/CH6/EX6.5/Fig6_7_Degraded_NoiseImage_Restoration.JPG diff --git a/125/CH6/EX6.7/Fig6_5_DegradedImage_Restoration.JPG b/125/CH6/EX6.7/Fig6_5_DegradedImage_Restoration.JPG Binary files differnew file mode 100755 index 000000000..220368740 --- /dev/null +++ b/125/CH6/EX6.7/Fig6_5_DegradedImage_Restoration.JPG 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 Binary files differnew file mode 100755 index 000000000..8b8ff8a19 --- /dev/null +++ b/125/CH6/EX6.7/Fig6_7_Degraded_NoiseImage_Restoration.JPG 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 Binary files differnew file mode 100755 index 000000000..e49026e1e --- /dev/null +++ b/125/CH6/EX6.9/Fig6_9_Degraded_NoiseImage_Restoration.JPG diff --git a/125/CH7/EX7.23/Fig7_23.jpg b/125/CH7/EX7.23/Fig7_23.jpg Binary files differnew file mode 100755 index 000000000..95f4912bf --- /dev/null +++ b/125/CH7/EX7.23/Fig7_23.jpg diff --git a/125/CH7/EX7.23/Fig7_23.sce b/125/CH7/EX7.23/Fig7_23.sce new file mode 100755 index 000000000..30830c2c6 --- /dev/null +++ b/125/CH7/EX7.23/Fig7_23.sce @@ -0,0 +1,13 @@ +//Caption: Scilab code for Differentiation of Gaussian function
+//Fig7.23
+//page388
+clc;
+close;
+sigma=input('Enter the value of sigma:')
+i=-10:.1:10;
+j=-10:.1:10;
+r=sqrt(i.*i+j.*j);
+y=(1/(sigma^2))*(((r.*r)/sigma^2)-1).*exp(-r.*r/2*sigma^2);
+plot(i,y)
+legend(sprintf('The sigma value is %g',sigma))
+xtitle('Differentiation of Gaussian function')
\ No newline at end of file diff --git a/125/CH7/EX7.23/sailing.jpg b/125/CH7/EX7.23/sailing.jpg Binary files differnew file mode 100755 index 000000000..2a6024f95 --- /dev/null +++ b/125/CH7/EX7.23/sailing.jpg diff --git a/125/CH7/EX7.25/Fig7_25.jpg b/125/CH7/EX7.25/Fig7_25.jpg Binary files differnew file mode 100755 index 000000000..f36adc4f4 --- /dev/null +++ b/125/CH7/EX7.25/Fig7_25.jpg diff --git a/125/CH7/EX7.25/Fig7_25.sce b/125/CH7/EX7.25/Fig7_25.sce new file mode 100755 index 000000000..1d0d3e6c7 --- /dev/null +++ b/125/CH7/EX7.25/Fig7_25.sce @@ -0,0 +1,19 @@ +//Caption: Scilab code for Differentiation of Gaussian Filter function
+//Fig7.25
+//page389
+clc;
+close;
+sigma1 = input('Enter the value of sigma1:')
+sigma2 = input('Enter the value of sigma2:')
+i=-10:.1:10;
+j=-10:.1:10;
+r=sqrt(i.*i+j.*j);
+y1 = (1/(sigma1^2))*(((r.*r)/sigma1^2)-1).*exp(-r.*r/2*sigma1^2);
+y2 = (1/(sigma2^2))*(((r.*r)/sigma2^2)-1).*exp(-r.*r/2*sigma2^2);
+y = y1-y2;
+plot(i,y)
+xtitle('Shape of DOG Filter')
+//Result
+//Enter the value of sigma1: 4
+//Enter the value of sigma2: 1
+//
\ No newline at end of file diff --git a/125/CH7/EX7.25/teaset.png b/125/CH7/EX7.25/teaset.png Binary files differnew file mode 100755 index 000000000..4c9fe635a --- /dev/null +++ b/125/CH7/EX7.25/teaset.png diff --git a/125/CH7/EX7.27/Fig7_27.sce b/125/CH7/EX7.27/Fig7_27.sce new file mode 100755 index 000000000..b59432f68 --- /dev/null +++ b/125/CH7/EX7.27/Fig7_27.sce @@ -0,0 +1,26 @@ +//Caption: Scilab code for Edge Detection using Different Edge detectors
+//[1]. Sobel [2].Prewitt [3].Log [4].Canny
+//Fig7.27
+//page389
+close;
+clc;
+a = imread('E:\DIP_JAYARAMAN\Chapter7\sailing.jpg');
+a = rgb2gray(a);
+c = edge(a,'sobel');
+d = edge(a,'prewitt');
+e = edge(a,'log');
+f = edge(a,'canny');
+ShowImage(a,'Original Image')
+title('Original Image')
+figure
+ShowImage(c,'Sobel')
+title('Sobel')
+figure
+ShowImage(d,'Prewitt')
+title('Prewitt')
+figure
+ShowImage(e,'Log')
+title('Log')
+figure
+ShowImage(f,'Canny')
+title('Canny')
\ No newline at end of file diff --git a/125/CH7/EX7.27/Fig7_27_Edge_Detection.JPG b/125/CH7/EX7.27/Fig7_27_Edge_Detection.JPG Binary files differnew file mode 100755 index 000000000..12b118d64 --- /dev/null +++ b/125/CH7/EX7.27/Fig7_27_Edge_Detection.JPG diff --git a/125/CH7/EX7.30/Fig7_30.sce b/125/CH7/EX7.30/Fig7_30.sce new file mode 100755 index 000000000..784a48c6d --- /dev/null +++ b/125/CH7/EX7.30/Fig7_30.sce @@ -0,0 +1,22 @@ +//Caption: Scilab code to perform watershed transform
+//Fig7.30
+//Page396
+clc;
+close;
+b = imread('E:\DIP_JAYARAMAN\Chapter7\teaset.png');
+a = rgb2gray(b);
+global EDGE_SOBEL;
+Gradient = EdgeFilter(a, EDGE_SOBEL);
+Threshold1 = CalculateOtsuThreshold(Gradient); // determine a threshold
+EdgeImage = ~SegmentByThreshold(Gradient,Threshold1);
+DistanceImage = DistanceTransform(EdgeImage);
+Threshold2 = CalculateOtsuThreshold(DistanceImage) // determine a threshold
+ThresholdImage = SegmentByThreshold(DistanceImage,Threshold2);
+MarkerImage = SearchBlobs(ThresholdImage);
+SegmentedImage = Watershed(Gradient,MarkerImage);
+figure
+ShowColorImage(b,'teaset')
+title('teaset.png')
+figure
+ColorMapLength = length(unique(SegmentedImage));
+ShowImage(SegmentedImage,'Result of Watershed Transform',jetcolormap(ColorMapLength));
\ No newline at end of file diff --git a/125/CH7/EX7.30/Fig7_30_Watershed_Transform.jpg b/125/CH7/EX7.30/Fig7_30_Watershed_Transform.jpg Binary files differnew file mode 100755 index 000000000..3c65385a8 --- /dev/null +++ b/125/CH7/EX7.30/Fig7_30_Watershed_Transform.jpg diff --git a/125/CH8/EX8.4/Problem4.sce b/125/CH8/EX8.4/Problem4.sce new file mode 100755 index 000000000..7fe484f5a --- /dev/null +++ b/125/CH8/EX8.4/Problem4.sce @@ -0,0 +1,15 @@ +//Caption: To verify the given matrix is a covaraince matrix
+//Problem 4
+//page438
+close;
+clear;
+clc;
+K = [37,-15;-15,37];
+evals = spec(K);
+evals = gsort(evals);
+disp(evals,'Eigen Values are =')
+if (evals==abs(evals)) then
+ disp('Both the eigen values are non-negative and the given matrix is a covariance matrix');
+else
+ disp('non-covariance matrix')
+end
\ No newline at end of file diff --git a/125/CH8/EX8.5/Problem5.sce b/125/CH8/EX8.5/Problem5.sce new file mode 100755 index 000000000..fcf5a3ecc --- /dev/null +++ b/125/CH8/EX8.5/Problem5.sce @@ -0,0 +1,34 @@ +//Caption: To compute the covariance of the given 2D data
+//Problem 5
+//page439
+close;
+clear;
+clc;
+X1 = [2,1]';
+X2 = [3,2]';
+X3 = [2,3]';
+X4 = [1,2]';
+X = [X1,X2,X3,X4];
+disp(X,'X=');
+[M,N] = size(X); //M=rows, N = columns
+for i =1:N
+ m(i) = mean(X(:,i));
+ A(:,i) = X(:,i)-m(i);
+end
+m = m';
+disp(m,'mean =');
+K = A'*A;
+K = K/(M-1);
+disp(K,'The Covaraince matix is K =')
+//Result
+//X=
+// 2. 3. 2. 1.
+// 1. 2. 3. 2.
+//mean =
+// 1.5 2.5 2.5 1.5
+//
+//The Covaraince matix is K =
+// 0.5 0.5 - 0.5 - 0.5
+// 0.5 0.5 - 0.5 - 0.5
+// - 0.5 - 0.5 0.5 0.5
+// - 0.5 - 0.5 0.5 0.5
\ No newline at end of file diff --git a/125/CH8/EX8.9/Problem9.sce b/125/CH8/EX8.9/Problem9.sce new file mode 100755 index 000000000..2c34220a4 --- /dev/null +++ b/125/CH8/EX8.9/Problem9.sce @@ -0,0 +1,38 @@ +//Caption: Develop a perceptron AND function with bipolar inputs and targets
+//Problem 9
+//page441
+close;
+clear;
+clc;
+X1 = [1,-1,1,-1]; //X1 and X2 are input vectors to AND function
+X2 = [1,1,-1,-1];
+//b = [1,1,1,1]; //Biasing vector
+T = [1,-1,-1,-1]; //Target vector for AND function
+W1 = 0; //Weights are initialized
+W2 = 0;
+b = 0; //bias initialized
+alpha = 1; //learning rate
+for i = 1:length(X1)
+ Yin(i) = b+X1(i)*W1+X2(i)*W2;
+ if (Yin(i)>=1)
+ Y(i)=1;
+ elseif((Yin(i)<1)&(Yin(i)>=-1))
+ Y(i)=0;
+ elseif(Yin(i)<-1)
+ Y(i)=-1;
+ end
+ disp(Yin(i),'Yin=')
+ disp(Y(i),'Y=')
+ if(Y(i)~=T(i))
+ b = b+alpha*T(i);
+ W1 = W1+alpha*T(i)*X1(i);
+ W2 = W2+alpha*T(i)*X2(i);
+ disp(b,'b=')
+ disp(W1,'W1=')
+ disp(W2,'W2=')
+ end
+end
+disp('Final Weights after one iteration are')
+disp(b,'Bias Weigth b=')
+disp(W1,'W1=')
+disp(W2,'W2=')
\ No newline at end of file diff --git a/125/CH9/EX9.59/Fig9_59.sce b/125/CH9/EX9.59/Fig9_59.sce new file mode 100755 index 000000000..38751c479 --- /dev/null +++ b/125/CH9/EX9.59/Fig9_59.sce @@ -0,0 +1,35 @@ +//Caption: Program performs Block Truncation Coding(BTC) by choosing different
+//block sizes
+//Fig.9.59: MATLAB Example1
+//page514
+close;
+clc;
+x =imread('E:\Digital_Image_Processing_Jayaraman\Chapter9\lenna.jpg'); //SIVP toolbox
+//x=imresize(x,[256 256]);
+x1=x;
+x=double(x);
+[m1 n1]=size(x);
+blk=input('Enter the block size:');
+for i = 1 : blk : m1
+for j = 1 : blk : n1
+ y = x(i:i+(blk-1),j:j+(blk-1)) ;
+ m = mean(mean(y));
+ sig=std2(y);
+ b = y > m ; //the binary block
+ K = sum(sum(b));
+ if (K ~= blk^2 ) & ( K ~= 0)
+ ml = m-sig*sqrt(K/((blk^2)-K));
+ mu = m+sig*sqrt(((blk^2)-K)/K);
+ x(i:i+(blk-1), j:j+(blk-1)) = b*mu+(1- b)*ml;
+ end
+end
+end
+//imshow(uint8(x))
+//title('Reconstructed Image')
+x = uint8(x);
+figure(1)
+imshow(x1)
+title('Original Image'); //IPD toolbox
+figure(2)
+ShowImage(x, 'Reconstructed Image'); //IPD toolbox
+title('Block Size = 8')
\ No newline at end of file diff --git a/125/CH9/EX9.59/Fig9_59_Block_Truncation.JPG b/125/CH9/EX9.59/Fig9_59_Block_Truncation.JPG Binary files differnew file mode 100755 index 000000000..d1ec0cb2a --- /dev/null +++ b/125/CH9/EX9.59/Fig9_59_Block_Truncation.JPG diff --git a/125/CH9/EX9.9/Example9_9.sce b/125/CH9/EX9.9/Example9_9.sce new file mode 100755 index 000000000..db912a3e8 --- /dev/null +++ b/125/CH9/EX9.9/Example9_9.sce @@ -0,0 +1,58 @@ +//Caption: Program performs Block Truncation Coding(BTC)
+//Example 9.9
+//page512
+close;
+clear;
+clc;
+x = [65,75,80,70;72,75,82,68;84,72,62,65;66,68,72,80];
+disp(x,'Original Block is x =')
+[m1 n1]=size(x);
+blk=input('Enter the block size:');
+for i = 1 : blk : m1
+for j = 1 : blk : n1
+ y = x(i:i+(blk-1),j:j+(blk-1)) ;
+ m = mean(mean(y));
+ disp(m,'mean value is m =')
+ sig=std2(y);
+ disp(sig,'Standard deviation of the block is =')
+ b = y > m ; //the binary block
+ disp(b,'Binary allocation matrix is B=')
+ K = sum(sum(b));
+ disp(K,'number of ones =')
+ if (K ~= blk^2 ) & ( K ~= 0)
+ ml = m-sig*sqrt(K/((blk^2)-K));
+ disp(ml,'The value of a =')
+ mu = m+sig*sqrt(((blk^2)-K)/K);
+ disp(mu,'The value of b =')
+ x(i:i+(blk-1), j:j+(blk-1)) = b*mu+(1- b)*ml;
+ end
+end
+end
+disp(round(x),'Reconstructed Block is x =')
+//Result
+//Original Block is x =
+//
+// 65. 75. 80. 70.
+// 72. 75. 82. 68.
+// 84. 72. 62. 65.
+// 66. 68. 72. 80.
+//
+//Enter the block size:4
+//mean value is m = 72.25
+//Standard deviation of the block is = 6.6282225
+//Binary allocation matrix is B=
+//
+// F T T F
+// F T T F
+// T F F F
+// F F F T
+//
+//number of ones = 6
+//The value of a = 67.115801
+//The value of b = 80.806998
+//Reconstructed Block is x =
+//
+// 67. 81. 81. 67.
+// 67. 81. 81. 67.
+// 81. 67. 67. 67.
+// 67. 67. 67. 81.
\ No newline at end of file diff --git a/125/DEPENDENCIES/Func_medianall.sci b/125/DEPENDENCIES/Func_medianall.sci new file mode 100755 index 000000000..ecf3273ba --- /dev/null +++ b/125/DEPENDENCIES/Func_medianall.sci @@ -0,0 +1,36 @@ +//The input to the function are the corrupted image ‘a’ and the dimension
+function [Out_Imag] = Func_medianall(a,N)
+a=double(a);
+[m n]=size(a);
+Out_Imag=a;
+if(modulo(N,2)==1)
+Start=(N+1)/2;
+End=Start;
+else
+ Start=N/2;
+ End=Start+1;
+end
+if(modulo(N,2)==1)
+ limit1=(N-1)/2;
+ limit2=limit1;
+else
+ 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+l);
+ I=I+1;
+ end
+ end
+ mat=gsort(mat); //Sort the elements to find the median
+ if(modulo(N,2)==1)
+ Out_Imag(i,j)=(mat(((N^2)+1)/2));
+ else
+ Out_Imag(i,j)=(mat((N^2)/2)+mat(((N^2)/2)+1))/2;
+ end
+ end
+end
\ No newline at end of file diff --git a/125/DEPENDENCIES/conv2d2.sce b/125/DEPENDENCIES/conv2d2.sce new file mode 100755 index 000000000..37350beba --- /dev/null +++ b/125/DEPENDENCIES/conv2d2.sce @@ -0,0 +1,23 @@ +function [y,X,H] = conv2d2(x,h)
+
+[x1,x2] = size(x);
+[h1,h2] = size(h);
+X = zeros(x1+h1-1,x2+h2-1);
+H = zeros(x1+h1-1,x2+h2-1);
+Y = zeros(x1+h1-1,x2+h2-1);
+for i = 1:x1
+ for j = 1:x2
+ X(i,j)=x(i,j);
+ end
+end
+for i =1:h1
+ for j = 1:h2
+ H(i,j)=h(i,j);
+ end
+end
+disp(X,'x=')
+disp(H,'h =')
+Y = fft2d(X).*fft2d(H);
+disp(Y)
+y = ifft2d(Y);
+endfunction
\ No newline at end of file diff --git a/125/DEPENDENCIES/dct_mtx.sce b/125/DEPENDENCIES/dct_mtx.sce new file mode 100755 index 000000000..b42bec4a8 --- /dev/null +++ b/125/DEPENDENCIES/dct_mtx.sce @@ -0,0 +1,7 @@ +function[DCT] = dct_mtx(n)
+[cc,rr] = meshgrid(0:n-1);
+//disp(cc)
+//disp(rr)
+DCT = sqrt(2 / n) * cos(%pi * (2*cc + 1) .* rr / (2 * n));
+DCT(1,:) = DCT(1,:) / sqrt(2);
+endfunction
\ No newline at end of file diff --git a/125/DEPENDENCIES/dft_mtx.sce b/125/DEPENDENCIES/dft_mtx.sce new file mode 100755 index 000000000..aaee76368 --- /dev/null +++ b/125/DEPENDENCIES/dft_mtx.sce @@ -0,0 +1,18 @@ +function [D] = dft_mtx(n)
+f = 2*%pi/n; // Angular increment.
+w = (0:f:2*%pi-f/2).' *%i; //Column.
+//disp(w)
+x = 0:n-1; // Row.
+D = exp(-w*x); // Exponent of outer product.
+for i = 1:n
+ for j = 1:n
+ if((abs(real(D(i,j)))<0.0001)&(abs(imag(D(i,j)))<0.0001))
+ D(i,j)=0;
+ elseif(abs(real(D(i,j)))<0.0001)
+ D(i,j)= 0+%i*imag(D(i,j));
+ elseif(abs(imag(D(i,j)))<0.0001)
+ D(i,j)= real(D(i,j))+0;
+ end
+ end
+end
+endfunction
\ No newline at end of file diff --git a/125/DEPENDENCIES/fft2d.sce b/125/DEPENDENCIES/fft2d.sce new file mode 100755 index 000000000..7cb43b663 --- /dev/null +++ b/125/DEPENDENCIES/fft2d.sce @@ -0,0 +1,25 @@ +function [a2] = fft2d(a)
+//a = any real or complex 2D matrix
+//a2 = 2D-DFT of 2D matrix 'a'
+m=size(a,1)
+n=size(a,2)
+// fourier transform along the rows
+for i=1:n
+a1(:,i)=exp(-2*%i*%pi*(0:m-1)'.*.(0:m-1)/m)*a(:,i)
+end
+// fourier transform along the columns
+for j=1:m
+a2temp=exp(-2*%i*%pi*(0:n-1)'.*.(0:n-1)/n)*(a1(j,:)).'
+a2(j,:)=a2temp.'
+end
+for i = 1:m
+ for j = 1:n
+ if((abs(real(a2(i,j)))<0.0001)&(abs(imag(a2(i,j)))<0.0001))
+ a2(i,j)=0;
+ elseif(abs(real(a2(i,j)))<0.0001)
+ a2(i,j)= 0+%i*imag(a2(i,j));
+ elseif(abs(imag(a2(i,j)))<0.0001)
+ a2(i,j)= real(a2(i,j))+0;
+ end
+ end
+end
\ No newline at end of file diff --git a/125/DEPENDENCIES/gray.sci b/125/DEPENDENCIES/gray.sci new file mode 100755 index 000000000..6630e04e8 --- /dev/null +++ b/125/DEPENDENCIES/gray.sci @@ -0,0 +1,4 @@ +function [g] = gray(m)
+ g = (0:m-1)'/max(m-1,1)
+g = [g g g]
+endfunction
\ No newline at end of file diff --git a/125/DEPENDENCIES/grayslice.sci b/125/DEPENDENCIES/grayslice.sci new file mode 100755 index 000000000..ac6012f54 --- /dev/null +++ b/125/DEPENDENCIES/grayslice.sci @@ -0,0 +1,51 @@ +function [bout] = grayslice(I,z)
+
+// Output variables initialisation (not found in input variables)
+bout=[];
+
+// Number of arguments in function call
+[%nargout,%nargin] = argn(0)
+
+if %nargin==1 then
+ z = 10;
+elseif ~type(z)==1 then
+ z = double(z);
+end;
+n = z;
+if typeof(I)=="uint8" then
+ z = (255*(0:n-1))/n;
+elseif isa(I, 'uint16') | isa(I, 'int16') then
+ z = 65535*(0:(n-1))/n;
+else // I is double or single
+ z = (0:(n-1))/n
+end;
+[m,n] = size(I);
+b = zeros(m,n);
+// Loop over all intervals, except the last
+for i = 1:length(z)-1
+ // j is the index value we will output, so it depend upon storage class
+ if typeof(b)=='uint8'
+ j = i-1;
+ else
+ j = i;
+ end
+ d = find(I>=z(i) & I<z(i+1));
+ if ~isempty(d),
+ b(d) = j;
+ end
+end
+
+// Take care of that last interval
+d = find(I >= z($));
+if ~isempty(d) then
+ // j is the index value we will output, so it depend upon storage class
+ if typeof(b)=="uint8" then
+ j = length(z)-1;
+ else
+ j = length(z);
+ end;
+ b(d) = j;
+end;
+bout = b;
+bout = double(bout);
+endfunction
\ No newline at end of file diff --git a/125/DEPENDENCIES/ifft2d.sce b/125/DEPENDENCIES/ifft2d.sce new file mode 100755 index 000000000..cae21fae0 --- /dev/null +++ b/125/DEPENDENCIES/ifft2d.sce @@ -0,0 +1,17 @@ +function [a] =ifft2d(a2)
+//a2 = 2D-DFT of any real or complex 2D matrix
+//a = 2D-IDFT of a2
+m=size(a2,1)
+n=size(a2,2)
+//Inverse Fourier transform along the rows
+for i=1:n
+a1(:,i)=exp(2*%i*%pi*(0:m-1)'.*.(0:m-1)/m)*a2(:,i)
+end
+//Inverse fourier transform along the columns
+for j=1:m
+atemp=exp(2*%i*%pi*(0:n-1)'.*.(0:n-1)/n)*(a1(j,:)).'
+a(j,:)=atemp.'
+end
+a = a/(m*n)
+a = real(a)
+endfunction
\ No newline at end of file diff --git a/125/DEPENDENCIES/rgb2ycbcr_1.sci b/125/DEPENDENCIES/rgb2ycbcr_1.sci new file mode 100755 index 000000000..19f37604d --- /dev/null +++ b/125/DEPENDENCIES/rgb2ycbcr_1.sci @@ -0,0 +1,11 @@ +function [ycc] = rgb2ycbcr_1(rgb)
+ //rgb=im2double(rgb);
+ rgb = double(rgb)
+ tmp=int_cvtcolor(rgb, 'rgb2ycrcb');
+ ycc=zeros(tmp);
+
+ ycc(:,:,1) = tmp(:,:,1);
+ ycc(:,:,2) = tmp(:,:,3);
+ ycc(:,:,3) = tmp(:,:,2);
+ clear tmp;
+endfunction
\ No newline at end of file |