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.
26 lines
1.0 KiB
26 lines
1.0 KiB
6 years ago
|
function nCutValue = calculateNcut (anAffinityMat , clusterIdx)
|
||
|
%Implementation the NCut metric calculation
|
||
|
% Usage nCutValue = calculateNcut (anAffinityMat , clusterIdx), where:
|
||
|
% Inputs
|
||
|
% - anAffinityMat is a rectagular, symmetrical affinity matrix
|
||
|
% representation of an image
|
||
|
% - clusterIdx is a vector storing the cluster Id of each node
|
||
|
% Output
|
||
|
% - nCutValue is a vector storing the cluster Id of each node
|
||
|
|
||
|
% Gets the unique cluster IDs
|
||
|
clusterIds = unique(clusterIdx);
|
||
|
if size(clusterIds, 1) ~= 2
|
||
|
error('Too many different clusters! Number of clusters should be two');
|
||
|
end
|
||
|
|
||
|
clusterOneIndices = (clusterIdx == clusterIds(1));
|
||
|
clusterTwoIndices = (clusterIdx == clusterIds(2));
|
||
|
|
||
|
nCutValue = 2 - ...
|
||
|
(sum(sum(anAffinityMat(clusterOneIndices, clusterOneIndices'))) / ...
|
||
|
sum(sum(anAffinityMat(clusterOneIndices, :))) + ...
|
||
|
sum(sum(anAffinityMat(clusterTwoIndices, clusterTwoIndices'))) / ...
|
||
|
sum(sum(anAffinityMat(clusterTwoIndices, :))));
|
||
|
end
|