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.
HoughTransform/hough_lines_compare_methods.m

44 lines
1.6 KiB
Matlab

function [param_hough,param_dim,W]=hough_lines_compare_methods(I,rhoResolution,thetaResolution,W)
% Performs the Hough transform for straight lines using two methods. The first
% uses the standard Hough voting method, the second uses the PC/BC-DIM algorithm
% to perform the voting.
if nargin<4, W=[]; end
%apply standard Hough voting method
[H,T,R] = hough(I,'RhoResolution',rhoResolution,'ThetaResolution',thetaResolution);
figured(2),clf, hough_lines_plot_accumulator(H,T,R); title('Hough')
param_hough=hough_find_peaks(H,T,R,1); title('Hough')
%apply PC/BC-DIM method
[H,W]=hough_lines_dim(I,rhoResolution,thetaResolution,W);
figured(3),clf, hough_lines_plot_accumulator(H,T,R); title('PC/BC-DIM')
param_dim=dim_find_peaks(H,T,R,1); title('PC/BC-DIM')
thetaResolution=mean(abs(diff(T)))
rhoResolution=mean(abs(diff(R)))
function hough_lines_plot_accumulator(H,T,R)
imagesc(H'), colorbar
set(gca,'FontSize',12);cmap=colormap('gray');cmap=1-cmap;colormap(cmap);
if max(R)<100
xtoplot=[-20:20:20]; ytoplot=[-45:45:45]; papersize=[10 10];
else
xtoplot=[-120:120:120]; ytoplot=[-60:60:60]; papersize=[28 6];
end
[xticks,yticks]=rescale_axes(axis,xtoplot,ytoplot,R,T);
set(gca,'XTick',xticks,'XTickLabel',xtoplot, 'YTick',yticks,'YTickLabel',ytoplot);
axis('equal','tight');
xlabel('radius');% (\rho)');
ylabel('orientation');% (\theta)');
drawnow
set(gcf,'PaperSize',papersize,'PaperPosition',[0 0 papersize]);
function [xticks,yticks]=rescale_axes(axrange,xtoplot,ytoplot,xrange,yrange)
xticks=axrange(1)+(xtoplot-xrange(1))./(xrange(end)-xrange(1)).*(axrange(2)-axrange(1));
yticks=axrange(3)+(ytoplot-yrange(1))./(yrange(end)-yrange(1)).*(axrange(4)-axrange(3));