lecture6 -...

Post on 28-Jul-2020

6 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

I = imread('circuit.tif');BW1 = edge(I,'prewitt');BW2 = edge(I,'canny');BW3 = edge(I,'sobel');%figure, subplot(2,2,1)figure, imshow(I)%subplot(2,2,1)figure, imshow(BW1)figure, imshow(BW2)figure, imshow(BW3)

I = imread('circuit.tif');BW = edge(I,'canny');figure, imshow(I)figure, imshow(BW)[H,T,R] = hough(BW,'RhoResolution',50,'ThetaResolut ion',50);[H,T,R] = hough(BW,'RhoResolution',0.5,'ThetaResolu tion',0.5);figure, subplot(2,1,1);imshow(I);subplot(2,1,2);imshow(imadjust(mat2gray(H)),'XData',T,'YData',R,'InitialMagnification','fi t');axis on, axis normal, hold on;

I = imread('circuit.tif');BW = edge(I,'canny');figure, imshow(I)figure, imshow(BW)I = imread('circuit.tif');BW = edge(imrotate(I,50,'crop'),'canny');[H,T,R] = hough(BW);P = houghpeaks(H,2);figure, subplot(2,1,1);imshow(I);subplot(2,1,2);imshow(H,[],'XData',T,'YData',R,'InitialMagnificati on','fit');xlabel('\theta'), ylabel('\rho');axis on, axis normal, hold on;plot(T(P(:,2)),R(P(:,1)),'s','color','white');

close allI = imread('circuit.tif');rotI = imrotate(I,33,'crop');BW = edge(rotI,'canny');figure, subplot(2,3,1);imshow(I)subplot(2,3,2);[H,T,R] = hough(BW);imshow(BW)subplot(2,3,[4 5 6]);imshow(H,[],'XData',T,'YData',R,'InitialMagnificati on','fit');xlabel('\theta'), ylabel('\rho');axis on, axis normal, hold on;P = houghpeaks(H,10,'threshold',ceil(0.5*max(H(:)) ));x = T(P(:,2)); y = R(P(:,1));plot(x,y,'s','color','white');subplot(2,3,3);% Find lines and plot themlines = houghlines(BW,T,R,P,'FillGap',5,'MinLength' ,7);imshow(rotI), hold onmax_len = 0;for k = 1:length(lines) xy = [lines(k).point1; lines(k).point2]; plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green '); % plot beginnings and ends of lines plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','y ellow'); plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','r ed');

% determine the endpoints of the longest line seg ment len = norm(lines(k).point1 - lines(k).point2); if ( len > max_len) max_len = len; xy_long = xy; endend

% highlight the longest line segmentplot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color ','cyan');

top related