Not enough input arguments.
1 view (last 30 days)
Show older comments
Pls can any one help... below is the code.
function [ lines ] = findlines( imge,map,theta,rho,minLen,maxLineNum,maxPeakNum,resol,maxGap )
theta,rho,point1([row,col]),point2.
img=imread('mpg.png');
imge = edge(img);
%[map theta rho] = hough1(imge,[]);
[pri pti] = findpeaks(map,minLen,maxPeakNum,resol);
peakNum = length(pri);
prho = rho(pri); % peak points
pthe = theta(pti)*pi/180;
rhoThres = abs(rho(2)-rho(1))/2;
fitPts = cell(1,peakNum);
fitPtsNum = zeros(1,peakNum);
for p = 1:peakNum
% store points which are on the lines
fitPts{p} = zeros(2,ceil(map(pri(p),pti(p))*1.2));
end
[Y X] = find(imge);
X = X-1; % The origin is the bottom-left corner.
M = size(imge,1);
Y = M-Y;
% find the points that's on the selected lines
for p = 1:length(X)
rho1 = X(p)*sin(pthe)+Y(p)*cos(pthe);
isOnPeak = find(abs(rho1-prho)<=rhoThres);
fitPtsNum(isOnPeak) = fitPtsNum(isOnPeak)+1;
for q = isOnPeak
fitPts{q}(:,fitPtsNum(q)) = [X(p);Y(p)];
end
end
% track the points on each line, find the start points and the end points,
lines = [];
tempLine = struct;
for p = 1:peakNum
t1 = [-cos(pthe(p)),sin(pthe(p))]; % the unit directional vector of the line
dist1 = t1*fitPts{p}(:,1:fitPtsNum(p)); % dist along the line
[ordDist ordIdx] = sort(dist1,'ascend');
ordPts = fitPts{p}(:,ordIdx);
% handle with the gaps
dist2 = diff(ordDist); % dist with each other
gapPos = [0 find(dist2>maxGap) length(ordDist)];
lineLen = diff(gapPos);
for q = find(lineLen>=minLen)
tempLine.theta = pthe(p);
tempLine.rho = prho(p);
tempLine.point1 = [M-ordPts(2,gapPos(q)+1),ordPts(1,gapPos(q)+1)+1];
tempLine.point2 = [M-ordPts(2,gapPos(q+1)),ordPts(1,gapPos(q+1))+1];
lines = [lines,tempLine];
if length(lines) == maxLineNum, break; end
end
if length(lines) == maxLineNum, break; end
end
end
function [rows cols] = findpeaks(map,minLen,maxPeakNum,resol)
% Find the at most maxLinNum points that's no less than minLen in map, meanwhile not
% 8-adjacent to each other, in MAP. Rows and cols are returned.
if max(max(map)) < minLen, return; end
rows = zeros(1,maxPeakNum);
cols = rows;
sz = size(map);
sup = ceil(sz/resol);
for p = 1:maxPeakNum
[V,I] = max(map(:));
if V<minLen
rows = rows(1:p-1);
cols = cols(1:p-1);
break;
end
[rows(p),cols(p)] = ind2sub(sz,I);
% non-maximal suppression
left = max(1,cols(p)-sup(2));
lr = min(sup(2)*2+1,sz(2)-left);
up = max(1,rows(p)-sup(1));
ud = min(sup(1)*2+1,sz(1)-up);
map(up:up+ud,left:left+lr) = 0;
end
if max(max(map)) < minLen, return; end
map(map<minLen) = 0;
mapMax = ordfilt2(map,25,ones(5));
mapPeak = (mapMax == map) & map; % non-maximal suppression
pt = find(mapPeak);
pv = map(pt);
[pvo,idx] = sort(pv,'descend');
pt = pt(idx);
if length(pvo) > maxPeakNum, pt = pt(1:maxPeakNum); end
[rows cols] = ind2sub(size(map),pt);
end
1 Comment
dpb
on 20 Jul 2013
First, format the code so is legible--use Code button or read help on markup syntax.
Second, provide the actual error message and the line on which it occurred; in all likelihood that piece of code will be all that's necessary but a little pertinent context around it can't hurt
Third, the error says you called some function that is expecting some specific number of arguments but passed fewer than that to it. Use
help thatfunction
to see the syntax for it and compare to you usage and you can probably fix it yourself quicker than here.
Answers (1)
per isakson
on 20 Jul 2013
The line
theta,rho,point1([row,col]),point2.
is a suspect
Set
>> dbstop if error
or set a breakpoint in the function before you call it.
Here are some links on debugging in Matlab
1 Comment
dpb
on 21 Jul 2013
Indeed. The editor certainly ought to flag this... Looks like an inadvertent ctrl-V pasted a line from the command window into the file (or at least the posting if not the actual file since doesn't look like should ever get far enough to get to the problem error it this were the actual function code...unless, of course, it's the call to this routine from the caller that's the problem.
That's the problem with not posting the actual error text and context--we're left guessing as to what the precise actual symptoms and location really were...
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!