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.

119 lines
4.3 KiB
Matlab

function accuracy_hough_lines(imNoise)
method{1}='Hough';method{2}='PC/BC-DIM';
numTest=250;
rhoResolutionStd=4;
rhoResolutionVar=[1,2,4,8];
thetaResolutionStd=5;
thetaResolutionVar=[2.5,4,6,7.5];
imSize=150;
if nargin<1 || isempty(imNoise)
imNoise=0
end
pxRemove=2/3;
%vary the resolution of the parameter space
k=0;
for rhoResolution=rhoResolutionVar
k=k+1;
W=[];
%generate images and perform hough transform
disp(['Processing Images (',int2str(numTest),')'])
for i=1:numTest
fprintf(1,'Image %i\n',i);
[I,theta_rho_true{k}{i}]=image_dot_lines(imSize,imNoise,pxRemove,[1,1]); %images have exactly one line
[param{k}{i}{1},param{k}{i}{2},W]=hough_lines_compare_methods(I,rhoResolution,thetaResolutionStd,W);
drawnow;
end
end
%vary the resolution of the parameter space
for thetaResolution=thetaResolutionVar
k=k+1;
W=[];
%generate images and perform hough transform
for i=1:numTest
fprintf(1,'Image %i\n',i);
[I,theta_rho_true{k}{i}]=image_dot_lines(imSize,imNoise,pxRemove,[1,1]); %images have exactly one line
[param{k}{i}{1},param{k}{i}{2},W]=hough_lines_compare_methods(I,rhoResolutionStd,thetaResolution,W);
drawnow;
end
end
%FOR each resolution of the parameter space and EACH METHOD FIND ACCURACY WITH WHICH PARAMETERS OF THE LINE ARE LOCATED
for var=1:k
for m=1:length(method)
disp(' ');
disp(method{m});
dist=[];
for i=1:numTest
%find parameters which have the most votes
[votes,index]=max(param{var}{i}{m}(3,:));
theta_rho_est=param{var}{i}{m}(1:2,index)
%calc distance between estimate and true parameters
dist(:,i)=lines_calc_min_param_distance(theta_rho_est,theta_rho_true{var}{i});
end
%record median distance between estimate and true parameters for this resolution of the parameter space and method
accuracy{m}(var,:)=median(dist');
end
end
%PLOT THE RESULTS
disp(' ');
lineStyle{1}='b-s';lineStyle{2}='r-d';
figured(6),clf
set(gcf,'PaperSize',[18 8],'PaperPosition',[0.25 0.65 17.75 7.5]);
subplot(1,2,1),
for m=1:length(method)
plot(rhoResolutionVar,accuracy{m}(1:length(rhoResolutionVar),1),lineStyle{m},'LineWidth',2,'MarkerSize',8,'MarkerFaceColor',lineStyle{m}(1)), hold on;
end
set(gca,'FontSize',12);
xlabel('radius resolution')
ylabel('error in orientation estimate'),
legend(method,'Location','northwest')
axis([floor(rhoResolutionVar(1)-0.5),ceil(rhoResolutionVar(end)+0.5),0,2.5])
text(rhoResolutionVar(1),0.25,['orientation resolution=',num2str(thetaResolutionStd,2)],'FontSize',12)
subplot(1,2,2),
for m=1:length(method)
plot(thetaResolutionVar,accuracy{m}(1+length(rhoResolutionVar):end,1),lineStyle{m},'LineWidth',2,'MarkerSize',8,'MarkerFaceColor',lineStyle{m}(1)), hold on;
end
set(gca,'FontSize',12);
xlabel('orientation resolution')
%ylabel('error in orientation estimate'),
axis([floor(thetaResolutionVar(1)-0.5),ceil(thetaResolutionVar(end)+0.5),0,2.5])
text(thetaResolutionVar(1),0.25,['radius resolution=',num2str(rhoResolutionStd,2)],'FontSize',12)
figured(7),clf
set(gcf,'PaperSize',[18 8],'PaperPosition',[0.25 0.5 17.75 7.5]);
subplot(1,2,1),
for m=1:length(method)
plot(rhoResolutionVar,accuracy{m}(1:length(rhoResolutionVar),2),lineStyle{m},'LineWidth',2,'MarkerSize',8,'MarkerFaceColor',lineStyle{m}(1)), hold on
end
set(gca,'FontSize',12);
xlabel('radius resolution')
ylabel('error in radius estimate'),
legend(method,'Location','northwest')
axis([floor(rhoResolutionVar(1)-0.5),ceil(rhoResolutionVar(end)+0.5),0,2.5])
text(rhoResolutionVar(1),0.25,['orientation resolution=',num2str(thetaResolutionStd,2)],'FontSize',12)
subplot(1,2,2),
for m=1:length(method)
plot(thetaResolutionVar,accuracy{m}(1+length(rhoResolutionVar):end,2),lineStyle{m},'LineWidth',2,'MarkerSize',8,'MarkerFaceColor',lineStyle{m}(1)), hold on
end
set(gca,'FontSize',12);
xlabel('orientation resolution')
%ylabel('error in radius estimate'),
axis([floor(thetaResolutionVar(1)-0.5),ceil(thetaResolutionVar(end)+0.5),0,2.5])
text(thetaResolutionVar(1),0.25,['radius resolution=',num2str(rhoResolutionStd,2)],'FontSize',12)
function dist=lines_calc_min_param_distance(theta_rhoEst,theta_rhoTrue)
dist(1,:)=min(abs(theta_rhoEst(1)-theta_rhoTrue(1,:)),abs(-theta_rhoEst(1)-theta_rhoTrue(1,:)));
dist(2,:)=min(abs(theta_rhoEst(2)-theta_rhoTrue(2,:)),abs(-theta_rhoEst(2)-theta_rhoTrue(2,:)));
[val,ind]=min(sum(dist))
dist=dist(:,ind)