Tuesday, June 17, 2014

DSP Project Details(Source code and ppt)

Output Image of Harris Corner point detection

 When u execute the code, the test image file opened and u have to select by the mouse the region where u want to find the Harris points,  then the code will print out and display the feature points in the selected region.

Output-1



Output-2



Output-3

Matlab simulation code for Harris Corner Point Detection

  1. % Harris detector
  2. % The code calculates
  3. % the Harris Feature Points(FP) 
  4. % 
  5. % When u execute the code, the test image file opened
  6. % and u have to select by the mouse the region where u
  7. % want to find the Harris points, 
  8. % then the code will print out and display the feature
  9. % points in the selected region.
  10. % You can select the number of FPs by changing the variables 
  11. % max_N & min_N

  12. load Imag;

  13. I =double(frame);

  14. %****************************
  15. imshow(frame);

  16. k = waitforbuttonpress;
  17. point1 = get(gca,'CurrentPoint');  %button down detected
  18. rectregion = rbbox;  %%%return figure units
  19. point2 = get(gca,'CurrentPoint');%%%%button up detected
  20. point1 = point1(1,1:2); %%% extract col/row min and maxs
  21. point2 = point2(1,1:2);
  22. lowerleft = min(point1, point2);
  23. upperright = max(point1, point2); 
  24. ymin = round(lowerleft(1)); 

  25. %%% Length and height of the bounded rectangle region
  26. ymax = round(upperright(1));
  27. xmin = round(lowerleft(2));
  28. xmax = round(upperright(2));
  29. %***********************************

  30. Aj=6;
  31. cmin=xmin-Aj; cmax=xmax+Aj; rmin=ymin-Aj; rmax=ymax+Aj;
  32. min_N=12;max_N=16;

  33. %%%%%%%%%%%%%%Interest Points%%%%%%%%%%%%%%%%%%
  34. sigma=2; Thrshold=20; r=6; disp=1;
  35. dx = [-1 0 1; -1 0 1; -1 0 1]; % The Mask 
  36.     dy = dx';
  37.    
  38.     %%%%%% Derivatives of Ix and Iy
  39.     Ix = conv2(I(cmin:cmax,rmin:rmax), dx, 'same');   
  40.     Iy = conv2(I(cmin:cmax,rmin:rmax), dy, 'same');
  41.     
  42.      %%%%%% Gaussien Filter
  43.     g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);
  44.     
  45.     %%%%% Convulation of Ix2, Iy2,Ixy using Gaussian window
  46.     Ix2 = conv2(Ix.^2, g, 'same');  
  47.     Iy2 = conv2(Iy.^2, g, 'same');
  48.     Ixy = conv2(Ix.*Iy, g,'same');
  49.    
  50.     %%%%%%%%%%%%%% Compute the cornerness values
  51.     k = 0.04;
  52.     R11 = (Ix2.*Iy2 - Ixy.^2) - k*(Ix2 + Iy2).^2;
  53.     R11=(1000/max(max(R11)))*R11;
  54.     R=R11;
  55.     ma=max(max(R));
  56.     sze = 2*r+1; 
  57.     MX = ordfilt2(R,sze^2,ones(sze));
  58.     R11 = (R==MX)&(R>Thrshold); 
  59.     count=sum(sum(R11(5:size(R11,1)-5,5:size(R11,2)-5)));
  60.     
  61.     %%%%% Find local maxima above some threshold to detect interest points 
  62.     loop=0;
  63.     while (((count<min_N)|(count>max_N))&(loop<30))
  64.         if count>max_N
  65.             Thrshold=Thrshold*1.5;
  66.         elseif count < min_N
  67.             Thrshold=Thrshold*0.5;
  68.         end
  69.         
  70.         R11 = (R==MX)&(R>Thrshold); 
  71.         count=sum(sum(R11(5:size(R11,1)-5,5:size(R11,2)-5)));
  72.         loop=loop+1;
  73.     end
  74.     
  75.     
  76. R=R*0;
  77.     R(5:size(R11,1)-5,5:size(R11,2)-5)=R11(5:size(R11,1)-5,5:size(R11,2)-5);
  78. [r1,c1] = find(R);
  79.     PIP=[r1+cmin,c1+rmin]
  80.    

  81.    %%%%%%%%%%%%%%%%%%%% Display
  82.    
  83.    Size_PI=size(PIP,1);
  84.    for r=1: Size_PI
  85.    I(PIP(r,1)-2:PIP(r,1)+2,PIP(r,2)-2)=255;
  86.    I(PIP(r,1)-2:PIP(r,1)+2,PIP(r,2)+2)=255;
  87.    I(PIP(r,1)-2,PIP(r,2)-2:PIP(r,2)+2)=255;
  88.    I(PIP(r,1)+2,PIP(r,2)-2:PIP(r,2)+2)=255;
  89.    
  90.    end
  91.    
  92.    imshow(uint8(I))