# this is sent the roi info and the distances from that point to all of the other points from the template #$index pulls in the roi info, @deltas then pulls in the distances. #if there is a match from a point in the region in question and the region it is testing against, it stops testing against that region and increments its success, if it has 4 successes, it stops checking that point. If at the end it does not have 4 successes it splices that point….. again untested. sub filter1 { my $i = $j = $k = 0; my $index = shift; my @deltas = @_; foreach my $testreg (@{$p[$index]}) { my ($testX,$testY) = @$testreg; foreach my $region (@p) { do { if ($i == $index) {$i++} else { $k = 0; foreach my $points(@{$region}) { do { my ($X,$Y) = @$points; my $distance = sqrt(abs(($testX - $X)**2 + ($testY - $Y)**2)); if (($deltas[$i] - $precision) <= $distance) && ($deltas[$i] + $precision) >= $distance)){ $k++; $j++; } } unless ($k == 1); } } } unless ($j == 4); } if ($j < 4) { splice (@{$p[$index]},$i,1); } else { $i++; } } }