You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
2.8 KiB
Matlab
114 lines
2.8 KiB
Matlab
function test_hough_lines(testCase,threshold)
|
|
if nargin<1 || isempty(testCase) || testCase<0
|
|
testCase=1
|
|
end
|
|
if nargin<2 || isempty(threshold) || threshold<0
|
|
threshold=12
|
|
end
|
|
|
|
method{1}='Hough';method{2}='PC/BC-DIM';
|
|
|
|
%CREATE TEST IMAGE
|
|
[I,rhoResolution,thetaResolution,theta_rho_true]=choose_test(testCase);
|
|
[a,b]=size(I);
|
|
figured(1),clf
|
|
imagesc(I),cmap=colormap('gray');cmap=1-cmap;colormap(cmap);
|
|
axis('equal','tight')
|
|
set(gca,'XTick',[],'YTick',[]);
|
|
if testCase<4, papersize=[5 5]; else, papersize=[9 9]; end
|
|
set(gcf,'PaperSize',papersize,'PaperPosition',[0 0 papersize]);
|
|
drawnow
|
|
|
|
%APPLY METHODS
|
|
[param{1},param{2}]=hough_lines_compare_methods(I,rhoResolution,thetaResolution);
|
|
|
|
%display detected lines
|
|
for m=1:length(method)
|
|
disp(method{m});
|
|
|
|
%draw original image
|
|
figured(3+m),clf,
|
|
imagesc(I), hold on, axis('equal','tight'),
|
|
set(gca,'FontSize',12);cmap=colormap('gray');cmap=1-cmap;colormap(cmap);
|
|
axis([1,b,1,a])
|
|
set(gca,'XTick',[],'YTick',[]);
|
|
title(method{m})
|
|
drawnow;
|
|
set(gcf,'PaperSize',papersize,'PaperPosition',[0 0 papersize]);
|
|
|
|
%select accumulator array values that exceed threshold
|
|
index=find(param{m}(3,:)>threshold);
|
|
coords=param{m}(1:2,index);
|
|
amplitude=param{m}(3,index);
|
|
|
|
%plot each line corresponding to the selected accumulator locations
|
|
for l=1:length(index)
|
|
[x,y]=convert_polar_to_cartesian(coords(1,l),coords(2,l),sqrt(a^2+b^2));
|
|
plot(x+1,y+1,'g','LineWidth',2)
|
|
end
|
|
|
|
%place results in order of number of votes
|
|
[~,order]=sort(amplitude,'descend');
|
|
coords=coords(:,order);
|
|
amplitude=amplitude(order);
|
|
|
|
disp(' * amplitude:');
|
|
disp(amplitude);
|
|
disp(' * theta,rho coords:');
|
|
disp(coords);
|
|
|
|
if ~isempty(theta_rho_true)
|
|
stats=lines_detection_accuracy([0,0,0],coords,theta_rho_true)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
function [I,rhoResolution,thetaResolution,params_true]=choose_test(testCase)
|
|
params_true=[];
|
|
|
|
%create image used in first 3 test cases
|
|
sz=21;
|
|
Im=zeros(sz,sz);
|
|
Im(1:sz+1:sz^2)=1; Im(10,:)=1;
|
|
for i=1:sz, Im(sz-floor((i-1)/2),i)=1; end
|
|
|
|
%default accumulator array resolutions
|
|
rhoResolution=1;
|
|
thetaResolution=5;
|
|
|
|
switch testCase
|
|
|
|
case 1
|
|
I=Im;
|
|
|
|
case 2
|
|
I=Im;
|
|
thetaResolution=4;
|
|
|
|
case 3
|
|
I=Im;
|
|
rhoResolution=2;
|
|
|
|
case 4
|
|
[I,params_true]=image_dot_lines(150,0);
|
|
|
|
case 5
|
|
[I,params_true]=image_dot_lines(150,0.01);
|
|
|
|
case 6
|
|
[I,params_true]=image_dot_lines(150,0,0,[1,1]);
|
|
rhoResolution=5;
|
|
thetaResolution=5;
|
|
|
|
case 7
|
|
I=im2single(rgb2gray(imread('../Data/Images/football.jpg')));
|
|
%I=im2single(imread('../Data/Images/pentagon.png'));
|
|
|
|
I=edge(I,'canny');
|
|
%I=sqrt(conv2(I,[1,0,-1],'same').^2+conv2(I,[1,0,-1]','same').^2+conv2(I,[1,0,0;0,0,0;0,0,-1],'same').^2+conv2(I,[0,0,1;0,0,0;-1,0,0],'same').^2)./sqrt(2); I(I<0.25)=0;
|
|
thetaResolution=1;
|
|
end
|
|
|