Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. close all;
  2. clearvars;
  3. clc;
  4.  
  5. image=imread('ccl1.png');
  6. figure(1);
  7. subplot(1,2,1);
  8. imshow(image);
  9. [XX,YY]=size(image);
  10. L=1;
  11. N=100;
  12. id = zeros(N);
  13. lut=zeros(N);
  14. for i = 1:N
  15. id(i)=i;
  16. end
  17.  
  18. for x = 2:XX-1
  19. for y = 2:YY-1
  20. X=image(x,y);
  21. if X~=0
  22. sasiedzi=[image(x-1,y-1) image(x-1,y) image(x-1, y+1) image(x,y-1)];
  23. suma = sum(sasiedzi);
  24. if suma==0
  25. image(x,y)=L;
  26. L=L+1;
  27. elseif suma>0
  28. sasiedziBezZer=nonzeros(sasiedzi);
  29. minimum=min(sasiedziBezZer);
  30. maksimum=max(sasiedziBezZer);
  31. id = union(minimum, maksimum, id);
  32. image(x,y)=minimum;
  33. end
  34. end
  35. end
  36. end
  37.  
  38. for i = 1:N
  39. lut(i) = root(i,id);
  40. end
  41.  
  42. for x = 2:XX-1
  43. for y = 2:YY-1
  44. X=image(x,y);
  45. if X~=0
  46. image(x,y) = root(image(x,y),id);
  47. end
  48. end
  49. end
  50.  
  51. subplot(1,2,2);
  52. % imshow(image);
  53. imshow(label2rgb(image));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement