├── .gitignore ├── Lena.jpg ├── Result images ├── fus1.jpg ├── fus1db.jpg ├── fus2.jpg ├── fus2db.jpg ├── fus3.jpg ├── fus3db.jpg ├── sacle2db.jpg ├── scale1.jpg ├── scale1db.jpg └── scale2.jpg ├── img_LH_and_HL_recomp.m ├── img_decomp.m ├── img_fuse.m ├── img_fusion.m ├── img_hl.m ├── img_lh.m ├── img_recomp.m ├── multi_decompose.m ├── rec_decomp.m ├── vkdb2.m └── vkhaar.m /.gitignore: -------------------------------------------------------------------------------- 1 | *pdf 2 | 3 | -------------------------------------------------------------------------------- /Lena.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybv/edge_detection/b031bac67ff80acbd099203201b5fed297dea84e/Lena.jpg -------------------------------------------------------------------------------- /Result images/fus1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybv/edge_detection/b031bac67ff80acbd099203201b5fed297dea84e/Result images/fus1.jpg -------------------------------------------------------------------------------- /Result images/fus1db.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybv/edge_detection/b031bac67ff80acbd099203201b5fed297dea84e/Result images/fus1db.jpg -------------------------------------------------------------------------------- /Result images/fus2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybv/edge_detection/b031bac67ff80acbd099203201b5fed297dea84e/Result images/fus2.jpg -------------------------------------------------------------------------------- /Result images/fus2db.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybv/edge_detection/b031bac67ff80acbd099203201b5fed297dea84e/Result images/fus2db.jpg -------------------------------------------------------------------------------- /Result images/fus3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybv/edge_detection/b031bac67ff80acbd099203201b5fed297dea84e/Result images/fus3.jpg -------------------------------------------------------------------------------- /Result images/fus3db.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybv/edge_detection/b031bac67ff80acbd099203201b5fed297dea84e/Result images/fus3db.jpg -------------------------------------------------------------------------------- /Result images/sacle2db.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybv/edge_detection/b031bac67ff80acbd099203201b5fed297dea84e/Result images/sacle2db.jpg -------------------------------------------------------------------------------- /Result images/scale1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybv/edge_detection/b031bac67ff80acbd099203201b5fed297dea84e/Result images/scale1.jpg -------------------------------------------------------------------------------- /Result images/scale1db.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybv/edge_detection/b031bac67ff80acbd099203201b5fed297dea84e/Result images/scale1db.jpg -------------------------------------------------------------------------------- /Result images/scale2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybv/edge_detection/b031bac67ff80acbd099203201b5fed297dea84e/Result images/scale2.jpg -------------------------------------------------------------------------------- /img_LH_and_HL_recomp.m: -------------------------------------------------------------------------------- 1 | function [img_LH_recomp,img_HL_recomp]=img_LH_and_HL_recomp(LH,HL,it,lphaar2,hphaar2) 2 | for j=1:it 3 | approx = zeros(size(HL{j},1),size(HL{j},2)); 4 | for i = j:-1:1 5 | [m,n] = size(HL{i}); 6 | if(i==j) 7 | approx = [approx,zeros(m,n);HL{i},zeros(m,n)]; 8 | else 9 | approx = [approx,zeros(m,n);zeros(m,n),zeros(m,n)]; 10 | end 11 | 12 | end 13 | img_HL_recomp{j} = img_recomp(approx,j,lphaar2,hphaar2); 14 | end 15 | 16 | 17 | for j=1:it 18 | approx = zeros(size(LH{j},1),size(LH{j},2)); 19 | for i = j:-1:1 20 | [m,n] = size(LH{i}); 21 | if(i==j) 22 | approx = [approx,LH{i};zeros(m,n),zeros(m,n)]; 23 | else 24 | approx = [approx,zeros(m,n);zeros(m,n),zeros(m,n)]; 25 | end 26 | 27 | end 28 | img_LH_recomp{j} = img_recomp(approx,j,lphaar2,hphaar2); 29 | end 30 | end -------------------------------------------------------------------------------- /img_decomp.m: -------------------------------------------------------------------------------- 1 | function [LL, LH, HL, HH] = img_decomp(I,lphaar, hphaar) 2 | LL = conv2(I,lphaar ,'same'); 3 | LL = imresize(LL,[size(LL,1) size(LL,2)/2]); 4 | LL = conv2(LL,lphaar,'same'); 5 | LL = imresize(LL,[size(LL,1)/2 size(LL,2)]); 6 | LH = conv2(I,lphaar,'same'); 7 | LH = imresize(LH,[size(LH,1) size(LH,2)/2]); 8 | LH = conv2(LH,hphaar,'same'); 9 | LH = imresize(LH,[size(LH,1)/2 size(LH,2)]); 10 | HL = conv2(I,hphaar,'same'); 11 | HL = imresize(HL,[size(HL,1) size(HL,2)/2]); 12 | HL = conv2(HL,lphaar,'same'); 13 | HL = imresize(HL,[size(HL,1)/2 size(HL,2)]); 14 | HH = conv2(I,hphaar,'same'); 15 | HH = imresize(HH,[size(HH,1) size(HH,2)/2]); 16 | HH = conv2(HH,hphaar,'same'); 17 | HH = imresize(HH,[size(HH,1)/2 size(HH,2)]); 18 | %figure 19 | %imshow(LL); 20 | %figure 21 | %imshow(LH); 22 | %figure 23 | %imshow(HL); 24 | %figure 25 | %imshow(HH); 26 | end 27 | 28 | -------------------------------------------------------------------------------- /img_fuse.m: -------------------------------------------------------------------------------- 1 | function [edge_image] = img_fuse( h_img, v_img ) 2 | 3 | h_img=double(h_img); 4 | v_img=double(v_img); 5 | 6 | [row,col] = size(h_img); 7 | for i = 1:row 8 | for j = 1:col 9 | if abs(h_img(i,j)) > abs(v_img(i,j)) 10 | edge_image(i,j) = h_img(i,j); 11 | else 12 | edge_image(i,j) = v_img(i,j); 13 | end 14 | end 15 | end 16 | % imshow(edge_image,[]); 17 | end 18 | 19 | -------------------------------------------------------------------------------- /img_fusion.m: -------------------------------------------------------------------------------- 1 | function Final=img_fusion(LH_out,HL_out,lphaar,hphaar,lphaar2,hphaar2,it2) 2 | 3 | %LH_output here 4 | it2=1; 5 | LL=[];LH=[];HL=[];HH=[]; 6 | 7 | app_img = LH_out; % Initializing the Approximation Image. 8 | 9 | for i = 1:it2 10 | [LL{i}, LH{i} ,HL{i} , HH{i}] = img_decomp(app_img, lphaar, hphaar); 11 | app_img = LL{i}; 12 | end 13 | 14 | 15 | LH_final = LL{it2}; 16 | for i = it2:-1:1 17 | LH_final = [LH_final,LH{i};HL{i},HH{i}]; 18 | end 19 | LH_final=(LH_final-min(min(LH_final)))/(max(max(LH_final)) - min(min(LH_final))); 20 | 21 | %HL_output here 22 | app_img = HL_out; % Initializing the Approximation Image. 23 | 24 | for i = 1:it2 25 | [LL{i}, LH{i} ,HL{i} , HH{i}] = img_decomp(app_img, lphaar, hphaar); 26 | app_img = LL{i}; 27 | end 28 | 29 | HL_final = LL{it2}; 30 | for i = it2:-1:1 31 | HL_final = [HL_final,LH{i};HL{i},HH{i}]; 32 | end 33 | HL_final=(HL_final-min(min(HL_final)))/(max(max(HL_final)) - min(min(HL_final))); 34 | 35 | Final = img_fuse(LH_final, HL_final); 36 | 37 | 38 | 39 | 40 | Final = img_recomp(Final, it2, lphaar2, hphaar2); 41 | Final=(Final-min(min(Final)))/(max(max(Final)) - min(min(Final))); 42 | end -------------------------------------------------------------------------------- /img_hl.m: -------------------------------------------------------------------------------- 1 | function HL=img_hl(I,it,lphaar,hphaar) 2 | 3 | app_img = I; % Initializing the Approximation Image. 4 | 5 | for i = 1:it 6 | [LL{i}, LH{i} ,HL{i} , HH{i}] = img_decomp(app_img, lphaar, hphaar); 7 | app_img = LL{i}; 8 | % figure 9 | %imshow(HL{i}); 10 | end 11 | 12 | 13 | end -------------------------------------------------------------------------------- /img_lh.m: -------------------------------------------------------------------------------- 1 | function LH=img_lh(I,it,lphaar,hphaar) 2 | 3 | app_img = I; % Initializing the Approximation Image. 4 | 5 | for i = 1:it 6 | 7 | [LL{i}, LH{i} ,HL{i} , HH{i}] = img_decomp(app_img, lphaar, hphaar); 8 | app_img = LL{i}; 9 | % figure 10 | % imshow(LH{i}); 11 | end 12 | 13 | end -------------------------------------------------------------------------------- /img_recomp.m: -------------------------------------------------------------------------------- 1 | function recomp_image = img_recomp( input,n ,lphaar, hphaar) 2 | [rw cl]=size(input); 3 | for i=n:-1:1 4 | sz=rw*(0.5^(i-1)); 5 | low_band=input(1:sz,1:sz); 6 | LL=low_band(1:sz/2,1:sz/2); 7 | LH=low_band(1:sz/2,(1+sz/2):sz); 8 | HL=low_band((1+sz/2):sz,1:sz/2); 9 | HH=low_band((1+sz/2):sz,(1+sz/2):sz); 10 | 11 | 12 | LL_new = imresize(LL,[size(LL,1)*2 size(LL,2)]); 13 | LL_new = conv2(LL_new,lphaar ,'same'); 14 | 15 | 16 | LH_new = imresize(LH,[size(LH,1)*2 size(LH,2)]); 17 | LH_new = conv2(LH_new,hphaar ,'same'); 18 | L=LL_new+LH_new; 19 | 20 | 21 | L = imresize(L,[size(L,1) size(L,2)*2]); 22 | L = conv2(L,lphaar ,'same'); 23 | 24 | HL_new = imresize(HL,[size(HL,1)*2 size(HL,2)]); 25 | HL_new = conv2(HL_new,lphaar ,'same'); 26 | 27 | HH_new = imresize(HH,[size(HH,1)*2 size(HH,2)]); 28 | HH_new = conv2(HH_new,hphaar ,'same'); 29 | H=HL_new+LH_new; 30 | 31 | H = imresize(H,[size(H,1) size(H,2)*2]); 32 | H = conv2(H,hphaar ,'same'); 33 | 34 | 35 | LH_image=L+H; 36 | 37 | 38 | input(1:sz,1:sz)=LH_image(1:sz,1:sz); 39 | 40 | end 41 | recomp_image=input; 42 | end 43 | 44 | -------------------------------------------------------------------------------- /multi_decompose.m: -------------------------------------------------------------------------------- 1 | function recomposed_decomposed=multi_decompose(recomposed,it2,lp_filter,hp_filter) 2 | 3 | Approx_img = recomposed; % Initializing the Approximation Image. 4 | 5 | for i = 1:it2 6 | [LL{i}, LH{i} ,HL{i} , HH{i}] = Decompose(Approx_img, lp_filter, hp_filter); 7 | Approx_img = LL{i}; 8 | end 9 | 10 | band = LL{it2}; 11 | for i = it2:-1:1 12 | band = [band,LH{i};HL{i},HH{i}]; 13 | end 14 | recomposed_decomposed=band; 15 | end -------------------------------------------------------------------------------- /rec_decomp.m: -------------------------------------------------------------------------------- 1 | function recomp_decomposed=rec_decomp(recomposed,it2,lphaar,hphaar) 2 | 3 | app_img = recomposed; % Initializing the Approximation Image. 4 | 5 | for i = 1:it2 6 | [LL{i}, LH{i} ,HL{i} , HH{i}] = img_decomp(app_img, lphaar, hphaar); 7 | app_img = LL{i}; 8 | end 9 | 10 | subband = LL{it2}; 11 | for i = it2:-1:1 12 | subband = [subband,LH{i};HL{i},HH{i}]; 13 | end 14 | recomp_decomposed=subband; 15 | end -------------------------------------------------------------------------------- /vkdb2.m: -------------------------------------------------------------------------------- 1 | %Project #1 (Wavelet-based Edge Detection and Fusion) 2 | %using db2 wavelet 3 | %Irugu Guruswamy Vaibhav Krishna 4 | %Nirupan Maruthappan 5 | 6 | lpdb2 =[ -0.12940952255092145 0.22414386804185735 0.83651630373746899 0.48296291314469025 ] 7 | hpdb2= [-0.48296291314469025 0.83651630373746899 -0.22414386804185735 -0.12940952255092145 ] 8 | lpdb22=[0.48296291314469025 0.83651630373746899 0.22414386804185735 -0.12940952255092145 ] 9 | hpdb22 =[-0.12940952255092145 -0.22414386804185735 0.83651630373746899 -0.48296291314469025 ] 10 | 11 | x = imread('lena.jpg'); 12 | I = im2double(x); 13 | it = 3; 14 | it2= 2; 15 | LH=img_lh(I,it,lpdb2,hpdb2); 16 | HL=img_hl(I,it,lpdb2,hpdb2); 17 | 18 | 19 | 20 | [LH_recomp,HL_recomp]=img_LH_and_HL_recomp(LH,HL,it,lpdb22,hpdb22) 21 | 22 | 23 | for i=1:it 24 | LH_recomp_decomposed{i}=rec_decomp(LH_recomp{i},it2,lpdb2,hpdb2); 25 | HL_recomp_decomposed{i}=rec_decomp(HL_recomp{i},it2,lpdb2,hpdb2); 26 | end 27 | 28 | for i=1:it 29 | fused{i}=img_fusion(LH_recomp{i},HL_recomp{i},lpdb2,hpdb2,lpdb22,hpdb22,it2); 30 | 31 | figure 32 | imshow(fused{i},[]); 33 | end 34 | 35 | %The scale multiplication is implemented using the corelation of two adjacent dwt scales 36 | %in this case, the correlation is computed using the two adjacent levels , 2 and 3 37 | scale2= (4*fused{2}+2*fused{3})/4.4721; 38 | %in this case, the correlation is computed using the two adjacent levels , 1 and 2 39 | scale1= (8*fused{1}+4*fused{2})/8.944; 40 | 41 | figure 42 | figure 43 | imshow(im2bw(scale1,0.70));%noise suppressed at this treshold 44 | figure 45 | imshow(im2bw(scale2,0.70)); 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /vkhaar.m: -------------------------------------------------------------------------------- 1 | %Project #1 (Wavelet-based Edge Detection and Fusion) 2 | %using haar wavelet 3 | %Irugu Guruswamy Vaibhav Krishna 4 | %Nirupan Maruthappan 5 | 6 | 7 | lphaar = [1/sqrt(2),1/sqrt(2)]; 8 | hphaar = [-1/sqrt(2),1/sqrt(2)]; 9 | hphaar2 = [1/sqrt(2),-1/sqrt(2)]; 10 | lphaar2 = [1/sqrt(2),1/sqrt(2)]; 11 | 12 | 13 | x = imread('lena.jpg'); 14 | I = im2double(x); 15 | it = 3; 16 | it2= 2; 17 | LH=img_lh(I,it,lphaar,hphaar); 18 | HL=img_hl(I,it,lphaar,hphaar); 19 | 20 | 21 | 22 | [LH_recomp,HL_recomp]=img_LH_and_HL_recomp(LH,HL,it,lphaar2,hphaar2) 23 | 24 | 25 | for i=1:it 26 | LH_recomp_decomposed{i}=rec_decomp(LH_recomp{i},it2,lphaar,hphaar); 27 | HL_recomp_decomposed{i}=rec_decomp(HL_recomp{i},it2,lphaar,hphaar); 28 | end 29 | 30 | for i=1:it 31 | fused{i}=img_fusion(LH_recomp{i},HL_recomp{i},lphaar,hphaar,lphaar2,hphaar2,it2); 32 | figure 33 | imshow(fused{i},[]); 34 | end 35 | 36 | 37 | %The scale multiplication is implemented using the corelation of two adjacent dwt scales 38 | %in this case, the correlation is computed using the two adjacent levels , 2 and 3 39 | scale2= (4*fused{2}+2*fused{3})/4.4721; 40 | %in this case, the correlation is computed using the two adjacent levels , 1 and 2 41 | scale1= (8*fused{1}+4*fused{2})/8.944; 42 | 43 | figure 44 | imshow(im2bw(scale1,0.70));%noise removed at this treshold 45 | figure 46 | imshow(im2bw(scale2,0.70)); 47 | 48 | 49 | 50 | --------------------------------------------------------------------------------