Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. [I0,map]=imread('lines','bmp');
  2. colormap(map);
  3. I0=double(I0); %increasing of calculation precision
  4. [row col deep]=size(I0); %acquisition of the input image size
  5.  
  6. %gray-level image creation
  7. IG0=I0;
  8. %conversion to grayscale
  9. IG0(:,:,1)=(I0(:,:,1)+I0(:,:,2)+I0(:,:,3))/3;
  10. IG0(:,:,2)=IG0(:,:,1);
  11. IG0(:,:,3)=IG0(:,:,1);
  12.  
  13. %Accumulator
  14. max_ro=floor((sqrt(row*row+col*col))/2);
  15. min_ro=-max_ro;
  16. rozmiar_aku=max_ro-min_ro;
  17. max_alfa=180;
  18. A=zeros(rozmiar_aku,max_alfa);
  19.  
  20. %Hough transform
  21. for x=1:col
  22. for y=1:row
  23. if IG0(row-y+1,x,1)==0
  24. for ro=min_ro:max_ro
  25. for alfa=1:max_alfa
  26. alf=pi*alfa/180.0;
  27. %if ro==round(x.*cos(alf)+y.*sin(alf))
  28. if ro==round((x+(-col/2)).*cos(alf)+(y+(-row/2)).*sin(alf))
  29. A(max_ro-ro+1,alfa)= A(max_ro-ro+1,alfa)+1;
  30. end;
  31. end;
  32. end;
  33. end; %if
  34. end;
  35. end;
  36.  
  37.  
  38. %Accumulator
  39. IA=double(zeros(rozmiar_aku,max_alfa,3));
  40. IA(:,:,1)=A;
  41. minIA=min(min(IA(:,:,1)));
  42. maxIA=max(max(IA(:,:,1)));
  43. IA(:,:,1)=255*(IA(:,:,1)-minIA)/(maxIA-minIA);
  44. IA(:,:,2)=IA(:,:,1);
  45. IA(:,:,3)=IA(:,:,1);
  46.  
  47.  
  48. %Lines
  49. IG1=IG0;
  50. for ilosc_prostych=1:5
  51. max_lokalne=max(max(A));
  52. for x=1:col
  53. for y=1:row
  54. if I0(row-y+1,x,1)==0
  55. for ro=min_ro:max_ro
  56. for alfa=1:max_alfa
  57. alf=pi*alfa/180.0;
  58. if A(max_ro+1-round((x+(-col/2)).*cos(alf)+(y+(-row/2)).*sin(alf)),alfa)== max_lokalne
  59. IG1(y,x,1)=(50*ilosc_prostych);
  60. IG1(y,x,2)=(10*ilosc_prostych);
  61. IG1(y,x,3)=(2*ilosc_prostych);
  62. %A(max_ro+1-round((x+(-col/2)).*cos(alf)+(y+(-row/2)).*sin(alf)),alfa)=0;
  63. end;
  64. end;
  65. end;
  66. end; %if
  67. end;
  68. end;
  69. end;
  70.  
  71.  
  72. % OUTPUT FIGURES
  73.  
  74. %input grayscale image
  75. IG0=uint8(IG0);
  76. figure(1);
  77. image(IG0);
  78. title('INPUT IMAGE');
  79.  
  80. %Accumulator
  81. IA=uint8(IA);
  82. figure(2);
  83. image(IA);
  84. title('ACCUMULATOR');
  85.  
  86. %Accumulator - 3D
  87. figure(3);
  88. surf(A);
  89. title('ACCUMULATOR - 3D');
  90.  
  91. %input grayscale image with color lines
  92. IG1=uint8(IG1);
  93. figure(4);
  94. image(IG1);
  95. title('DETECTED LINES');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement