'How to filter similar line with similar angle and distance?
I have to filter similar line with similar theta difference < pi/180*4 and rho difference < 4. My code and test code are as follows, but function is too long and complex, how to improve it?
test code
nAngle=[0;pi/4;pi/4-pi/180*5;pi/180*2];
nDistance = [100;100;98;100];
[isDuplicate,lineLeft] = check_similar_line(nAngle,nDistance)
result
isDuplicate =
logical
1
lineLeft =
2 3 4
function code
function [isDuplicate,lineLeft] = check_similar_line(nAngle,nDistance)
%UNTITLED21 delete duplicate line angle < pi/180*4 and distance to
%original<4
size = length(nAngle);
angleDifference = abs(triu(bsxfun(@minus,nAngle,nAngle'),-1)) + tril(inf(size,size));
distanceDifference = abs(triu(bsxfun(@minus,nDistance,nDistance'),-1)) + tril(inf(size,size));
angleIndex = find(angleDifference<pi/180*4);
distanceIndex = find(distanceDifference(angleIndex) < 4);
finalIndex = angleIndex(distanceIndex);
[left,~] = ind2sub([size,size],finalIndex);
lineLeft = setdiff(1:size,left);
isDuplicate = ~isempty(finalIndex);
end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|