Advertisement
Benlahbib_Abdessamad

Untitled

Jul 1st, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 11.10 KB | None | 0 0
  1. % --------------------------------------------------------------------
  2. function erosion_Callback(hObject, eventdata, handles)
  3. % hObject    handle to erosion (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. image=handles.courant_data;
  7. se = strel('disk',8);
  8. b = imerode(image,se);
  9. handles.ima_traite = b;
  10. axes(handles.imgT);
  11. subimage(b);
  12. handles.output = hObject;
  13. guidata(hObject, handles);
  14.  
  15. % --------------------------------------------------------------------
  16. function dilatation_Callback(hObject, eventdata, handles)
  17. % hObject    handle to dilatation (see GCBO)
  18. % eventdata  reserved - to be defined in a future version of MATLAB
  19. % handles    structure with handles and user data (see GUIDATA)
  20. image=handles.courant_data;
  21. se = strel('disk',8);
  22. b = imdilate(image,se);
  23. handles.ima_traite = b;
  24. axes(handles.imgT);
  25. subimage(b);
  26. handles.output = hObject;
  27. guidata(hObject, handles);
  28.  
  29. % --------------------------------------------------------------------
  30. function ouverture_Callback(hObject, eventdata, handles)
  31. % hObject    handle to ouverture (see GCBO)
  32. % eventdata  reserved - to be defined in a future version of MATLAB
  33. % handles    structure with handles and user data (see GUIDATA)
  34. image=handles.courant_data;
  35. se = strel('disk',3);
  36. b = imopen(image,se);
  37. handles.ima_traite = b;
  38. axes(handles.imgT);
  39. subimage(b);
  40. handles.output = hObject;
  41. guidata(hObject, handles);
  42.  
  43. % --------------------------------------------------------------------
  44. function fermeture_Callback(hObject, eventdata, handles)
  45. % hObject    handle to fermeture (see GCBO)
  46. % eventdata  reserved - to be defined in a future version of MATLAB
  47. % handles    structure with handles and user data (see GUIDATA)
  48. image=handles.courant_data;
  49. se = strel('line',11,90);
  50. b = imclose(image,se);
  51. %imshow(b);
  52. handles.ima_traite = b;
  53. axes(handles.imgT);
  54. subimage(b);
  55. handles.output = hObject;
  56. guidata(hObject, handles);
  57.  
  58. % --------------------------------------------------------------------
  59. function tophat_Callback(hObject, eventdata, handles)
  60. % hObject    handle to tophat (see GCBO)
  61. % eventdata  reserved - to be defined in a future version of MATLAB
  62. % handles    structure with handles and user data (see GUIDATA)
  63. image=handles.courant_data;
  64. se = strel('disk',30);
  65. b = imtophat(image,se);
  66. handles.ima_traite = b;
  67. axes(handles.imgT);
  68. subimage(b);
  69. handles.output = hObject;
  70. guidata(hObject, handles);
  71.  
  72. % --------------------------------------------------------------------
  73. function bottom_hat_Callback(hObject, eventdata, handles)
  74. % hObject    handle to bottom_hat (see GCBO)
  75. % eventdata  reserved - to be defined in a future version of MATLAB
  76. % handles    structure with handles and user data (see GUIDATA)
  77. image=handles.courant_data;
  78. se = strel('disk',30);
  79. b = imbothat(image,se);
  80. handles.ima_traite = b;
  81. axes(handles.imgT);
  82. subimage(b);
  83. handles.output = hObject;
  84. guidata(hObject, handles);
  85.  
  86. % --------------------------------------------------------------------
  87. function gradient_interne_Callback(hObject, eventdata, handles)
  88. % hObject    handle to gradient_interne (see GCBO)
  89. % eventdata  reserved - to be defined in a future version of MATLAB
  90. % handles    structure with handles and user data (see GUIDATA)
  91. image=handles.courant_data;
  92. se = strel('disk',3);
  93. b = imerode(image,se);
  94. img = image - b;
  95. handles.ima_traite = img;
  96. axes(handles.imgT);
  97. subimage(img);
  98. handles.output = hObject;
  99. guidata(hObject, handles);
  100.  
  101. % --------------------------------------------------------------------
  102. function gradient_externe_Callback(hObject, eventdata, handles)
  103. % hObject    handle to gradient_externe (see GCBO)
  104. % eventdata  reserved - to be defined in a future version of MATLAB
  105. % handles    structure with handles and user data (see GUIDATA)
  106. image=handles.courant_data;
  107. se = strel('disk',3);
  108. b = imdilate(image,se);
  109. img = b - image ;
  110. handles.ima_traite = img;
  111. axes(handles.imgT);
  112. subimage(img);
  113. handles.output = hObject;
  114. guidata(hObject, handles);
  115.  
  116. % --------------------------------------------------------------------
  117. function gradient_morphologique_Callback(hObject, eventdata, handles)
  118. % hObject    handle to gradient_morphologique (see GCBO)
  119. % eventdata  reserved - to be defined in a future version of MATLAB
  120. % handles    structure with handles and user data (see GUIDATA)
  121. image=handles.courant_data;
  122. se = strel('disk',3);
  123. a=  imerode(image,se);
  124. b = imdilate(image,se);
  125. img = b - a ;
  126. handles.ima_traite = img;
  127. axes(handles.imgT);
  128. subimage(img);
  129. handles.output = hObject;
  130. guidata(hObject, handles);
  131.  
  132.  
  133.  
  134.  
  135.  
  136. % --------------------------------------------------------------------
  137. function harris_Callback(hObject, eventdata, handles)
  138. % hObject    handle to harris (see GCBO)
  139. % eventdata  reserved - to be defined in a future version of MATLAB
  140. % handles    structure with handles and user data (see GUIDATA)
  141.  
  142. img = handles.courant_data;
  143. %==========================================================================
  144. if(size(img,3)==3)
  145.     display('l''image est en couleur')
  146.     img=rgb2gray(img);
  147. end
  148. %==========================================================================
  149.  
  150. lambda=0.04;
  151. sigma=1; seuil=200; r=6; w=5*sigma;
  152. [m,n]=size(img)
  153. imd=double(img);
  154. dx=[-1 0 1
  155.     -2 0 2
  156.     -1 0 1]; % derivée horizontale : filtre de Sobel
  157. dy=dx'; % derivée verticale : filtre de Sobel
  158. % dx=[-1 1];
  159. % dy=dx';
  160. g = fspecial('gaussian',max(1,fix(w)), sigma);
  161. Ix=conv2(imd,dx,'same');
  162. Iy=conv2(imd,dy,'same');
  163. Ix2=conv2(Ix.^2, g, 'same');
  164. Iy2=conv2(Iy.^2, g, 'same');
  165. Ixy=conv2(Ix.*Iy, g,'same');
  166. % M=[Ix2 Ixy
  167. %     Ixy Iy2];
  168. detM=Ix2.*Iy2-Ixy.^2;
  169. trM=Ix2+Iy2;
  170. R=detM-lambda*trM.^2;
  171. %==========================================================================
  172. R1=(1000/(1+max(max(R))))*R;
  173. %==========================================================================          
  174. [u,v]=find(R1<=seuil);
  175. nb=length(u);
  176. for k=1:nb
  177.     R1(u(k),v(k))=0;
  178. end
  179. R11=zeros(m+2*r,n+2*r);
  180. R11(r+1:m+r,r+1:n+r)=R1;
  181. [m1,n1]=size(R11);
  182. for i=r+1:m1-r
  183.     for j=r+1:n1-r
  184.         fenetre=R11(i-r:i+r,j-r:j+r);
  185.         ma=max(max(fenetre));
  186.         if fenetre(r+1,r+1)<ma
  187.             R11(i,j)=0;
  188.         end
  189.     end
  190. end
  191. subplot(1,2,2); imshow(img)
  192. hold on
  193. R11=R11(r+1:m+r,r+1:n+r);
  194. [x,y]=find(R11);
  195. nb=length(x)
  196. plot(y,x,'.r')
  197. hold off
  198.  
  199. % --------------------------------------------------------------------
  200. function susan_Callback(hObject, eventdata, handles)
  201. % hObject    handle to susan (see GCBO)
  202. % eventdata  reserved - to be defined in a future version of MATLAB
  203. % handles    structure with handles and user data (see GUIDATA)
  204. % =====================chargement et conversion de limage==================
  205. im = handles.courant_data;
  206. % =======================conversion de l'image=============================
  207. d = length(size(im));
  208. % im = imnoise(im,'speckle',0.02);
  209. if d==3
  210.     image=double(rgb2gray(im));
  211. elseif d==2
  212.     image=double(im);
  213. end
  214. %subplot(1,2,1)
  215.  
  216. %imshow(im)
  217. [n,m]=size(image);
  218. % =============================données=====================================
  219. rayon=2;
  220. alpha=50;
  221. r=2;
  222. alpha=alpha/100;
  223. % ========================génerateur de mask===============================
  224. mask=zeros(2*rayon+1);
  225. b=ones(rayon+1);
  226. for i=1:rayon+1
  227.     for j=1:rayon+1
  228.         if (rayon==1)
  229.            if(j>i)
  230.             b(i,j)=0;
  231.            end
  232.          else
  233.              if(j>i+1)
  234.             b(i,j)=0;
  235.          end
  236.         end
  237.     end
  238. end
  239. mask(1:rayon+1,rayon+1:2*rayon+1)=b;
  240. mask(1:rayon+1,1:rayon+1)=rot90(b);
  241. mask0=mask;
  242. mask0=flipdim(mask0,1);
  243. mask=mask0+mask;
  244. mask(rayon+1,:)=mask(rayon+1,:)-1;
  245. % ==========================réponse maximale===============================
  246. max_reponse=sum(sum(mask));
  247. % =====================balayage de toute l'image===========================
  248. f=zeros(n,m);
  249. for i=(rayon+1):n-rayon
  250.     for j=(rayon+1):m-rayon
  251.  
  252.           image_courant=image(i-rayon:i+rayon,j-rayon:j+rayon);
  253.  
  254.     image_courant_mask=image_courant.*mask;
  255.  
  256.          inteniste_cental= image_courant_mask(rayon+1,rayon+1);
  257.          s=exp(-1*(((image_courant_mask-inteniste_cental)/max_reponse).^6));
  258.        somme=sum(sum(s));
  259. %   si le centre du mask est un 0 il faut soustraire les zeros des filtres
  260.                 if (inteniste_cental==0)
  261.                     somme=somme-length((find(mask==0)));
  262.                 end      
  263.          f(i,j)=somme;          
  264.      end
  265. end
  266. % =============selection et seuillage des points d'interét=================
  267. ff=f(rayon+1:n-(rayon+1),rayon+1:m-(rayon+1));
  268. minf=min(min(ff));
  269. maxf=max(max(f));
  270. fff=f;
  271. d=2*r+1;
  272. temp1=round(n/d);
  273. if (temp1-n/d)<0.5 &(temp1-n/d)>0
  274.     temp1=temp1-1;
  275. end
  276. temp2=round(m/d);
  277. if (temp2-m/d)<0.5 &(temp2-m/d)>0
  278.     temp2=temp2-1;
  279. end
  280. fff(n:temp1*d+d,m:temp2*d+d)=0;
  281. temp1
  282. temp2
  283.  
  284. fff;
  285.  
  286. sizefff=size(fff)
  287. for i=(r+1):d:temp1*d+d
  288. for j=(r+1):d:temp2*d+d
  289.      window=fff(i-r:i+r,j-r:j+r);
  290.      window0=window;
  291.    [xx,yy]=find(window0==0);
  292.                for k=1:length(xx)
  293.                  window0(xx(k),yy(k))=max(max(window0));
  294.                end
  295.                minwindow=min(min(window0));
  296. [y,x]=find(minwindow~=window & window<=minf+alpha*(maxf-minf) & window>0);
  297. [u,v]=find(minwindow==window);
  298. if length(u)>1
  299.              for l=2:length(u)
  300.                      fff(i-r-1+u(l),j-r-1+v(l))=0   ;      
  301.              end
  302. end
  303. if length(x)~=0
  304.         for l=1:length(y)
  305.             fff(i-r-1+y(l),j-r-1+x(l))=0   ;
  306.         end
  307. end
  308. fff;
  309. end
  310. end
  311.  
  312.  
  313. seuil=minf+alpha*(maxf-minf);
  314.  
  315.     [u,v]=find(minf<=fff & fff<=seuil );
  316. % ==============affichage des resultats====================================
  317. subplot(1,2,2);
  318. imshow(im)
  319. hold on
  320. %axes(handles.imgT);
  321. plot(v,u,'.r','MarkerSize',10)
  322. %nombre_de_point_dinteret=length(v)
  323. hold off
  324. %handles.ima_traite = im;
  325.  
  326. %subimage(im);
  327. %handles.output = hObject;
  328. %guidata(hObject, handles);
  329.  
  330.  
  331.  
  332.  
  333. % --------------------------------------------------------------------
  334. function electrostatique_Callback(hObject, eventdata, handles)
  335. % hObject    handle to electrostatique (see GCBO)
  336. % eventdata  reserved - to be defined in a future version of MATLAB
  337. % handles    structure with handles and user data (see GUIDATA)
  338.  
  339. img = handles.courant_data;
  340. k=0.04; sigma=1; seuil=100; r=6; w=5*sigma;
  341. [m,n]=size(img); imd=double(img);
  342. dxa=[-sqrt(2)/4 0 sqrt(2)/4 ; -1 0 1 ; -sqrt(2)/4 0 sqrt(2)/4];
  343. % dxa=[sqrt(2)/4 0 -sqrt(2)/4; 1 0 -1; sqrt(2)/4 0 -sqrt(2)/4];
  344. dya=dxa'; % derivée verticale
  345. g=fspecial('gaussian',max(1,fix(5*sigma)),sigma); % gaussien
  346. Ixa=conv2(imd,dxa,'same');
  347. Iya=conv2(imd,dya,'same');
  348. Ixa2 = conv2(Ixa.^2, g, 'same');
  349. Iya2 = conv2(Iya.^2, g, 'same');
  350. Ixya = conv2(Ixa.*Iya, g,'same');
  351. R=Ixa2.*Iya2-Ixya.^2-k*(Ixa2+Iya2).^2;
  352. R1=(1000/(max(max(R))))*R; %normalisation
  353. [u,v]=find(R1<=seuil);
  354. nb=length(u);
  355. for k=1:nb
  356. R1(u(k),v(k))=0;
  357. end
  358. R11=zeros(m+2*r,n+2*r);
  359. R11(r+1:m+r,r+1:n+r)=R1;
  360. [m1,n1]=size(R11);
  361. for i=r+1:m1-r
  362. for j=r+1:n1-r
  363. fenetre=R11(i-r:i+r,j-r:j+r);
  364. ma=max(max(fenetre));
  365. if fenetre(r+1,r+1)<ma
  366. R11(i,j)=0;
  367. end
  368. end
  369. end
  370. subplot(1,2,2); imshow(img)
  371. hold on
  372. R11=R11(r+1:m+r,r+1:n+r);
  373. [x,y]=find(R11);
  374. nb=length(x)
  375. plot(y,x,'.r')
  376. %title('detection des points d''interet')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement