├── bluecat.jpg ├── edge_detection.m ├── README.md ├── bilinear_interpolation.m └── edgedirected_interpolation.m /bluecat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czxrrr/super-resolution/HEAD/bluecat.jpg -------------------------------------------------------------------------------- /edge_detection.m: -------------------------------------------------------------------------------- 1 | %% use the canny operator to detect edge 2 | img=imread('bluecat.jpg'); 3 | img=im2double(img); 4 | 5 | I=rgb2gray(img); 6 | 7 | sharp = edge(I,'canny'); 8 | figure; 9 | imshow(sharp) 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # super-resolution 2 | This project aims to use edge-directed interpolation to zoom in pictures. 3 | There are 2 approaches to do the inpterpolation. 4 | 1 bilinear interpolation for the smooth area. 5 | 2 new edge-directed interpolation for the sharp area. 6 | (Sharp area can be detected by various methods.) 7 | ## citation 8 | [1] Xin Li, Member, IEEE, and Michael T. Orchard, Fellow, IEEE "New Edge-Directed Interpolation" in IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 10, NO. 10, OCTOBER 2001 9 | -------------------------------------------------------------------------------- /bilinear_interpolation.m: -------------------------------------------------------------------------------- 1 | %% ----bilinear interpolation 2 | %this process handles the smooth area 3 | %after this we will use New edge-directed interpolation to deal with the 4 | %sharp area. 5 | [height,width,~]=size(img); 6 | simg=zeros(height*2,width*2,3); 7 | for i=1:height 8 | for j=1:width 9 | for k=1:3 10 | simg(i*2,j*2,k)=img(i,j,k); 11 | end 12 | end 13 | end 14 | %imshow(simg); 15 | % x interpolation 16 | for i=1:height 17 | for j=1:width 18 | for k=1:3 19 | if(i==1) 20 | simg(i*2-1,j*2,k)=simg(i*2,j*2,k); 21 | else 22 | simg(i*2-1,j*2,k)=0.5*(simg(i*2-2,j*2,k)+simg(i*2,j*2,k)); 23 | end 24 | end 25 | end 26 | end 27 | % y interpolation 28 | for i=1:height 29 | for j=1:width 30 | for k=1:3 31 | if(j==1) 32 | simg(i*2,j*2-1,k)=simg(i*2,j*2,k); 33 | simg(i*2-1,j*2-1,k)=simg(i*2-1,j*2,k); 34 | else 35 | simg(i*2,j*2-1,k)=0.5*(simg(i*2,j*2,k)+simg(i*2,j*2-2,k)); 36 | simg(i*2-1,j*2-1,k)=0.5*(simg(i*2-1,j*2,k)+simg(i*2-1,j*2-2,k)); 37 | end 38 | end 39 | end 40 | end 41 | imshow(simg); 42 | 43 | 44 | -------------------------------------------------------------------------------- /edgedirected_interpolation.m: -------------------------------------------------------------------------------- 1 | %% edge-directed interpolation for sharp areas 2 | 3 | m=5; 4 | y=zeros(m^2,1); % m^2 * 1 5 | C=zeros(m^2,4); % m^2 * 4 6 | 7 | %% step 1 reconstruct the points with the form of (2*i+1,2*j+1) 8 | for k=1:3 % 3 colors 9 | for i=4:height-4 10 | for j=4:width-4 11 | if(sharp(i,j)==1) 12 | temp=1; 13 | for ii=(i+1-ceil(m/2)):(i+floor(m/2)) 14 | for jj=j+1-ceil(m/2):j+floor(m/2) 15 | y(temp)=simg(2*ii,2*jj,k); 16 | C(temp,1)=simg(2*ii-2,2*jj-2,k); 17 | C(temp,2)=simg(2*ii+2,2*jj-2,k); 18 | C(temp,3)=simg(2*ii+2,2*jj+2,k); 19 | C(temp,4)=simg(2*ii-2,2*jj+2,k); 20 | temp=temp+1; 21 | end 22 | end 23 | alpha=(C'*C)\(C'*y); 24 | simg(2*i+1,2*j+1,k)=(alpha(1)*simg(2*i,2*j,k)+alpha(2)*simg(2*i+2,2*j,k)... 25 | +alpha(3)*simg(2*i+2,2*j+2,k)+alpha(4)*simg(2*i,2*j+2,k)); 26 | 27 | end 28 | end 29 | end 30 | end 31 | 32 | 33 | %% step 2 reconstructed the points with the forms of (2*i+1,2*j) 34 | for k=1:3 % 3 colors 35 | for i=4:height-4 36 | for j=4:width-4 37 | if(sharp(i,j)==1) 38 | temp=1; 39 | for ii=(i+1-ceil(m/2)):(i+floor(m/2)) 40 | for jj=j+1-ceil(m/2):j+floor(m/2) 41 | y(temp)=simg(2*ii+1,2*jj-1,k); 42 | C(temp,1)=simg(2*ii-1,2*jj-1,k); 43 | C(temp,2)=simg(2*ii+1,2*jj-3,k); 44 | C(temp,3)=simg(2*ii+3,2*jj-1,k); 45 | C(temp,4)=simg(2*ii+1,2*jj+1,k); 46 | temp=temp+1; 47 | end 48 | end 49 | alpha=(C'*C)\(C'*y); 50 | simg(2*i+1,2*j,k)=(alpha(1)*simg(2*i,2*j,k)+alpha(2)*simg(2*i+1,2*j-1,k)... 51 | +alpha(3)*simg(2*i+2,2*j,k)+alpha(4)*simg(2*i+1,2*j+1,k)); 52 | end 53 | end 54 | end 55 | end 56 | %% step 3 reconstructed the points with the forms of (2*i,2*j+1) 57 | 58 | for k=1:3 % 3 colors 59 | for i=4:height-4 60 | for j=4:width-4 61 | if(sharp(i,j)==1) 62 | temp=1; 63 | for ii=(i+1-ceil(m/2)):(i+floor(m/2)) 64 | for jj=j+1-ceil(m/2):j+floor(m/2) 65 | y(temp)=simg(2*ii+1,2*jj-1,k); 66 | C(temp,1)=simg(2*ii-1,2*jj-1,k); 67 | C(temp,2)=simg(2*ii+1,2*jj-3,k); 68 | C(temp,3)=simg(2*ii+3,2*jj-1,k); 69 | C(temp,4)=simg(2*ii+1,2*jj+1,k); 70 | temp=temp+1; 71 | end 72 | end 73 | alpha=(C'*C)\(C'*y); 74 | simg(2*i,2*j+1,k)=(alpha(1)*simg(2*i-1,2*j+1,k)+alpha(2)*simg(2*i,2*j,k)... 75 | +alpha(3)*simg(2*i+1,2*j+1,k)+alpha(4)*simg(2*i,2*j+2,k)); 76 | end 77 | end 78 | end 79 | end 80 | imshow(simg); 81 | --------------------------------------------------------------------------------