% clusters.m % function cb = clusters(input,ref,maxIt) % clusters(randn(2,400)/sqrt(12),randn(2,1)/sqrt(12)); % 17.01.2003, Jens Ahrensfeld function [cb, idx, output] =clusters_ransac(input,max_distance,move_thresh) cl_count = 0; [nDim, nData] = size(input); points_remain = input; while length(points_remain) > 0, [nDim,nRem] = size(points_remain); new_idx = round(rand(1,1)*(nRem-1))+1; ref = points_remain(:,new_idx); ref_last = zeros(nDim,1); d_max = 2*move_thresh; while d_max > move_thresh d = sqrt(sum((points_remain-repmat(ref,1,nRem)).^2)); % Calc distances between references and input points_assigned_idx = find(d <= max_distance); num_assigned = length(points_assigned_idx); if (num_assigned > 0); ref = mean(points_remain(:,points_assigned_idx),2); d_max = max(sqrt(sum((ref_last-ref).^2))); ref_last = ref; else break; end; end; cl_count = cl_count +1; output{cl_count} = points_remain(:,points_assigned_idx); idx{cl_count} = points_assigned_idx; points_remain(:,points_assigned_idx) = []; cb(:,cl_count) = ref; end;