Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fs=imread('t2.jpg');
- i=rgb2gray(fs);
- %i=imread('text.png');
- rot=imrotate(i,33,'crop');
- imshow(rot)
- bw=edge(rot,'canny');
- hold on
- imshow(bw)
- %Compute the Hough transform of the binary image returned by edge.
- [h,theta,rho] = hough(bw);
- % display h returned by hough trans
- %Find the peaks in the Hough transform matrix, H, using the houghpeaks function.
- p=houghpeaks(h,7,'threshold',ceil(0.3*max(h(:))));
- %Superimpose a plot on the image of the transform that identifies the peaks.
- x = theta(p(:,2));
- y = rho(p(:,1));
- plot(x,y,'s','color','black');
- %Find lines in the image using the houghlines function.
- lines = houghlines(bw,theta,rho,p,'FillGap',5,'MinLength',7);
- %Create a plot that displays the original image with the lines superimposed on it.
- figure, imshow(rot), hold on
- max_len = 0;
- for k = 1:length(lines)
- xy = [lines(k).point1; lines(k).point2];
- plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','cyan');
- % Plot beginnings and ends of lines
- plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
- plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
- % Determine the endpoints of the longest line segment
- len = norm(lines(k).point1 - lines(k).point2);
- if ( len > max_len)
- max_len = len;
- xy_long = xy;
- end
- end
- % highlight the longest line segment
- %plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement