Advertisement
Benlahbib_Abdessamad

Untitled

Jun 30th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 5.22 KB | None | 0 0
  1. % --------------------------------------------------------------------
  2. function harris_Callback(hObject, eventdata, handles)
  3. % hObject    handle to harris (see GCBO)
  4. % eventdata  reserved - to be defined in a future version of MATLAB
  5. % handles    structure with handles and user data (see GUIDATA)
  6.  
  7. img = handles.courant_data;
  8. %==========================================================================
  9. if(size(img,3)==3)
  10.     display('l''image est en couleur')
  11.     img=rgb2gray(img);
  12. end
  13. %==========================================================================
  14.  
  15. lambda=0.04;
  16. sigma=1; seuil=200; r=6; w=5*sigma;
  17. [m,n]=size(img)
  18. imd=double(img);
  19. dx=[-1 0 1
  20.     -2 0 2
  21.     -1 0 1]; % derivée horizontale : filtre de Sobel
  22. dy=dx'; % derivée verticale : filtre de Sobel
  23. % dx=[-1 1];
  24. % dy=dx';
  25. g = fspecial('gaussian',max(1,fix(w)), sigma);
  26. Ix=conv2(imd,dx,'same');
  27. Iy=conv2(imd,dy,'same');
  28. Ix2=conv2(Ix.^2, g, 'same');
  29. Iy2=conv2(Iy.^2, g, 'same');
  30. Ixy=conv2(Ix.*Iy, g,'same');
  31. % M=[Ix2 Ixy
  32. %     Ixy Iy2];
  33. detM=Ix2.*Iy2-Ixy.^2;
  34. trM=Ix2+Iy2;
  35. R=detM-lambda*trM.^2;
  36. %==========================================================================
  37. R1=(1000/(1+max(max(R))))*R;
  38. %==========================================================================          
  39. [u,v]=find(R1<=seuil);
  40. nb=length(u);
  41. for k=1:nb
  42.     R1(u(k),v(k))=0;
  43. end
  44. R11=zeros(m+2*r,n+2*r);
  45. R11(r+1:m+r,r+1:n+r)=R1;
  46. [m1,n1]=size(R11);
  47. for i=r+1:m1-r
  48.     for j=r+1:n1-r
  49.         fenetre=R11(i-r:i+r,j-r:j+r);
  50.         ma=max(max(fenetre));
  51.         if fenetre(r+1,r+1)<ma
  52.             R11(i,j)=0;
  53.         end
  54.     end
  55. end
  56. subplot(1,2,2); imshow(img)
  57. hold on
  58. R11=R11(r+1:m+r,r+1:n+r);
  59. [x,y]=find(R11);
  60. nb=length(x)
  61. plot(y,x,'.r')
  62. hold off
  63.  
  64. % --------------------------------------------------------------------
  65. function susan_Callback(hObject, eventdata, handles)
  66. % hObject    handle to susan (see GCBO)
  67. % eventdata  reserved - to be defined in a future version of MATLAB
  68. % handles    structure with handles and user data (see GUIDATA)
  69. % =====================chargement et conversion de limage==================
  70. im = handles.courant_data;
  71. % =======================conversion de l'image=============================
  72. d = length(size(im));
  73. % im = imnoise(im,'speckle',0.02);
  74. if d==3
  75.     image=double(rgb2gray(im));
  76. elseif d==2
  77.     image=double(im);
  78. end
  79. %subplot(1,2,1)
  80.  
  81. %imshow(im)
  82. [n,m]=size(image);
  83. % =============================données=====================================
  84. rayon=2;
  85. alpha=50;
  86. r=2;
  87. alpha=alpha/100;
  88. % ========================génerateur de mask===============================
  89. mask=zeros(2*rayon+1);
  90. b=ones(rayon+1);
  91. for i=1:rayon+1
  92.     for j=1:rayon+1
  93.         if (rayon==1)
  94.            if(j>i)
  95.             b(i,j)=0;
  96.            end
  97.          else
  98.              if(j>i+1)
  99.             b(i,j)=0;
  100.          end
  101.         end
  102.     end
  103. end
  104. mask(1:rayon+1,rayon+1:2*rayon+1)=b;
  105. mask(1:rayon+1,1:rayon+1)=rot90(b);
  106. mask0=mask;
  107. mask0=flipdim(mask0,1);
  108. mask=mask0+mask;
  109. mask(rayon+1,:)=mask(rayon+1,:)-1;
  110. % ==========================réponse maximale===============================
  111. max_reponse=sum(sum(mask));
  112. % =====================balayage de toute l'image===========================
  113. f=zeros(n,m);
  114. for i=(rayon+1):n-rayon
  115.     for j=(rayon+1):m-rayon
  116.  
  117.           image_courant=image(i-rayon:i+rayon,j-rayon:j+rayon);
  118.  
  119.     image_courant_mask=image_courant.*mask;
  120.  
  121.          inteniste_cental= image_courant_mask(rayon+1,rayon+1);
  122.          s=exp(-1*(((image_courant_mask-inteniste_cental)/max_reponse).^6));
  123.        somme=sum(sum(s));
  124. %   si le centre du mask est un 0 il faut soustraire les zeros des filtres
  125.                 if (inteniste_cental==0)
  126.                     somme=somme-length((find(mask==0)));
  127.                 end      
  128.          f(i,j)=somme;          
  129.      end
  130. end
  131. % =============selection et seuillage des points d'interét=================
  132. ff=f(rayon+1:n-(rayon+1),rayon+1:m-(rayon+1));
  133. minf=min(min(ff));
  134. maxf=max(max(f));
  135. fff=f;
  136. d=2*r+1;
  137. temp1=round(n/d);
  138. if (temp1-n/d)<0.5 &(temp1-n/d)>0
  139.     temp1=temp1-1;
  140. end
  141. temp2=round(m/d);
  142. if (temp2-m/d)<0.5 &(temp2-m/d)>0
  143.     temp2=temp2-1;
  144. end
  145. fff(n:temp1*d+d,m:temp2*d+d)=0;
  146. temp1
  147. temp2
  148.  
  149. fff;
  150.  
  151. sizefff=size(fff)
  152. for i=(r+1):d:temp1*d+d
  153. for j=(r+1):d:temp2*d+d
  154.      window=fff(i-r:i+r,j-r:j+r);
  155.      window0=window;
  156.    [xx,yy]=find(window0==0);
  157.                for k=1:length(xx)
  158.                  window0(xx(k),yy(k))=max(max(window0));
  159.                end
  160.                minwindow=min(min(window0));
  161. [y,x]=find(minwindow~=window & window<=minf+alpha*(maxf-minf) & window>0);
  162. [u,v]=find(minwindow==window);
  163. if length(u)>1
  164.              for l=2:length(u)
  165.                      fff(i-r-1+u(l),j-r-1+v(l))=0   ;      
  166.              end
  167. end
  168. if length(x)~=0
  169.         for l=1:length(y)
  170.             fff(i-r-1+y(l),j-r-1+x(l))=0   ;
  171.         end
  172. end
  173. fff;
  174. end
  175. end
  176.  
  177.  
  178. seuil=minf+alpha*(maxf-minf);
  179.  
  180.     [u,v]=find(minf<=fff & fff<=seuil );
  181. % ==============affichage des resultats====================================
  182. subplot(1,2,2);
  183. imshow(im)
  184. hold on
  185. %axes(handles.imgT);
  186. plot(v,u,'.r','MarkerSize',10)
  187. %nombre_de_point_dinteret=length(v)
  188. hold off
  189. %handles.ima_traite = im;
  190.  
  191. %subimage(im);
  192. %handles.output = hObject;
  193. %guidata(hObject, handles);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement