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.

43 lines
1.5 KiB
Matlab

function [H,W]=hough_lines_dim(I,rhoResolution,thetaResolution,W)
%determine how big the weight matrix and voting space will be
[H,T,R] = hough(zeros(size(I)),'RhoResolution',rhoResolution,'ThetaResolution',thetaResolution);
if nargin<4 || isempty(W)
%define weights of prediction neurons
[a,b]=size(I);
if 4*length(T)*length(R)*a*b>8e9 %threshold should depend on available system memory (but MATLAB's memory function does not work in Linux), so is set to 8GB which may not be appropriate!
W=sparse(length(T)*length(R),a*b);
disp('WARNING hough_lines_dim.m: using sparse datatype for W as it is large - this will result in slower processing');
else
W=zeros(length(T)*length(R),a*b,'single');
end
k=0;
for y=1:b
for x=1:a
k=k+1;
Itmp=zeros(size(I));
Itmp(x,y)=1;
H=hough(Itmp,'RhoResolution',rhoResolution,'ThetaResolution',thetaResolution);
%H=conv2(H,gauss2D(0.5),'same'); %spread
%set Hough output as weights fanning out from one input pixel
W(:,k)=H(:);
end
end
end
[n,m]=size(W);
%ignore inputs which are zero and the corresponding weights to improve speed
X=I(:);
incX=find(I(:)>0);
x=X(incX);
Wreduced=W(:,incX);
%ignore neurons with zero weights to improve speed
inc=find(sum(W,2)>0);
%apply PC/BC-DIM to process the inputs
[yinc]=dim_activation(single(full(Wreduced(inc,:))),x);
%re-insert the zero activations for neurons with zero weights
y=zeros(n,1);
y(inc)=yinc;
H=reshape(y,length(R),length(T));