You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
693 B
19 lines
693 B
function clusterIdx = myNCuts (anAffinityMat, k)
|
|
%Implementation of the N-cuts algorithm
|
|
% Usage clusterIdx = myNCuts (anAffinityMat, k), where:
|
|
% Inputs
|
|
% - anAffinityMat is a rectagular, symmetrical affinity matrix
|
|
% representation of an image
|
|
% - k is the desired number of clusters
|
|
% Output
|
|
% - clusterIdx is a vector storing the cluster Id of each node
|
|
|
|
if ~issymmetric(anAffinityMat)
|
|
error('The affinity matrix provided is not symmetric.');
|
|
end
|
|
|
|
D = diag(sum(anAffinityMat, 2));
|
|
L = D - anAffinityMat;
|
|
[eigenvectorsMatrix, ~] = eigs(double(L), double(D), k, 'sm');
|
|
clusterIdx = kmeans(eigenvectorsMatrix, k);
|
|
end
|
|
|