szymcio10

lab 15 - poc

Jul 5th, 2020
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.21 KB | None | 0 0
  1. %1
  2. close all;
  3. clear all;
  4.  
  5. obraz = zeros(11,11);
  6. obraz(1,1) = 1;
  7. obraz(2,2) = 1;
  8. obraz(3,2) = 1;
  9. obraz(3,6) =1;
  10.  
  11. [H,theta,rho] = hough(obraz,'Theta',0.1,'RhoResolution',0.5)
  12.  
  13. figure(1)
  14. subplot(1,2,1)
  15. imshow(H,[]);
  16.  
  17. subplot(1,2,2)
  18. imshow(obraz,[]);
  19. %2
  20. close all;
  21. clear all;
  22.  
  23. img = imread('kwadraty.tif');
  24. img_sobel = imgradient(img);
  25.  
  26. [H,theta,rho] = hough(img_sobel)
  27. P = houghpeaks(H,8);
  28.  
  29. figure(1)
  30. subplot(1,3,1)
  31. imshow(img);
  32. subplot(1,3,2)
  33. imshow(img_sobel,[]);
  34. subplot(1,3,3)
  35. imshow(H,[]);
  36.  
  37. lines = houghlines(img_sobel,theta,rho,P,'FillGap',5,'MinLength',7);
  38. figure, imshow(img), hold on
  39. max_len = 0;
  40. for k = 1:length(lines)
  41.   xy = [lines(k).point1; lines(k).point2];
  42.   plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
  43.  
  44.   % Plot beginnings and ends of lines
  45.   plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
  46.   plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
  47.  
  48.   % Determine the endpoints of the longest line segment
  49.   len = norm(lines(k).point1 - lines(k).point2);
  50.   if ( len > max_len)
  51.       max_len = len;
  52.       xy_long = xy;
  53.   end
  54. end
  55. %3
  56. close all;
  57. clear all;
  58.  
  59. imgLab = imread('lab112.bmp');
  60.  
  61. imgLab = im2bw(imgLab, 0.2);
  62. imgLab = imdilate(imgLab, ones(3,10));
  63. imgGra = imgradient(imgLab)
  64.  
  65. [H,theta,rho] = hough(imgGra)
  66. P = houghpeaks(H,8);
  67.  
  68. figure(1)
  69. subplot(1,3,1)
  70. imshow(imgLab);
  71. subplot(1,3,2)
  72. imshow(imgGra,[]);
  73. subplot(1,3,3)
  74. imshow(H,[]);
  75.  
  76. lines = houghlines(imgLab,theta,rho,P,'FillGap',5,'MinLength',7);
  77. figure, imshow(imgLab), hold on
  78. max_len = 0;
  79. for k = 1:length(lines)
  80.   xy = [lines(k).point1; lines(k).point2];
  81.   plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
  82.  
  83.   % Plot beginnings and ends of lines
  84.   plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
  85.   plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
  86.  
  87.   % Determine the endpoints of the longest line segment
  88.   len = norm(lines(k).point1 - lines(k).point2);
  89.   if ( len > max_len)
  90.       max_len = len;
  91.       xy_long = xy;
  92.   end
  93. end
  94. %4
  95. close all;
  96. clear all;
  97.  
  98. obraz = zeros(11, 11);
  99. obraz(1,1) = 1;
  100. obraz(2,2) = 1;
  101. obraz(3,2) = 1;
  102. obraz(3,6) = 1;
  103.  
  104. H = houghAB(obraz);
  105.  
  106. figure(1);
  107.  
  108. subplot(2,1,1);
  109. imshow(obraz);
  110.  
  111. subplot(2,1,2);
  112. imshow(H, []);
Advertisement
Add Comment
Please, Sign In to add comment