我正在尝试将图形割方法应用于我的分割任务中。我在Graph_Cut_Demo找到了一些示例代码。
以下是部分代码:
这让我很困惑。他们为什么要计算协方差矩阵,以及如何使用负对数似然形成数据项?是否有任何关于这些实现的论文或描述可用?
非常感谢。
以下是部分代码:
img = im2double( imread([ImageDir 'cat.jpg']) );
[ny,nx,nc] = size(img);
d = reshape( img, ny*nx, nc );
k = 2; % number of clusters
[l0 c] = kmeans( d, k );
l0 = reshape( l0, ny, nx );
% For each class, the data term Dc measures the distance of
% each pixel value to the class prototype. For simplicity, standard
% Euclidean distance is used. Mahalanobis distance (weighted by class
% covariances) might improve the results in some cases. Note that the
% image intensity values are in the [0,1] interval, which provides
% normalization.
Dc = zeros( ny, nx, k );
for i = 1:k
dif = d - repmat( c(i,:), ny*nx,1 );
Dc(:,:,i) = reshape( sum(dif.^2,2), ny, nx );
end
看起来这种方法使用k-means聚类来初始化图表并获取数据项Dc。然而,我不明白他们如何计算这个数据项。为什么要使用它?
dif = d - repmat( c(i,:), ny*nx,1 );
在评论中提到数据项Dc
测量了每个像素值与类原型之间的距离。什么是类原型,为什么可以通过k-means标签确定?
在另一个实现Graph_Cut_Demo2中使用了
% calculate the data cost per cluster center
Dc = zeros([sz(1:2) k],'single');
for ci=1:k
% use covariance matrix per cluster
icv = inv(cov(d(l0==ci,:)));
dif = d- repmat(c(ci,:), [size(d,1) 1]);
% data cost is minus log likelihood of the pixel to belong to each
% cluster according to its RGB value
Dc(:,:,ci) = reshape(sum((dif*icv).*dif./2,2),sz(1:2));
end
这让我很困惑。他们为什么要计算协方差矩阵,以及如何使用负对数似然形成数据项?是否有任何关于这些实现的论文或描述可用?
非常感谢。