前段时间有会友发过求瓷砖图片分类的帖子,我看这是一个演示hausdorf距离的好例子,所以就发到这里来了。
hausdorf 距离的介绍请参考如下文献:
[1] D. P. Huttenlocher, G. A. Klanderman, and W. J.
Rucklidge, “Comparing images using the Hausdorff
distance”, IEEE Trans. PAMI, vol. 15, pp. 850-
863, 1993.
[2] Marie-Pierre Dubisson and A.K.Jain. A modified hausdorff distance for
object matching
这里用的是文献[2] modified hausdorff distance.
核心函数:
function d = m_hd(im1, im2)
%Effect: compute the modified haussdorff distance between 2 bw image 'im1'
% and 'im2'
%inputs:
%im1, im2: bw image with the size
%outputs:
%d: the modified haussdorff distance between 'im1' & 'im2'
%Author: Su dongcai at 2012/1/11
%Email: suntree4152@gmail.com, qq:272973536
%reference:
%[1] D. P. Huttenlocher, G. A. Klanderman, and W. J.
% Rucklidge, “Comparing images using the Hausdorff
% distance”, IEEE Trans. PAMI, vol. 15, pp. 850-
% 863, 1993.
%[2] Marie-Pierre Dubisson and A.K.Jain. A modified hausdorff distance for
% object matching
%0. check inputs:
im_sz1 = size(im1); im_sz2 = size(im2);
if(sum(abs(im_sz1-im_sz2))~=0)
error('im1 and im2 must with the same size');
end
dist_im1 = bwdist(im1); dist_im2 = bwdist(im2);
pidx_im1 = find(im1); pidx_im2 = find(im2);
%eq.(6) in [2]
d12 = mean(dist_im1(pidx_im2));
d21 = mean(dist_im2(pidx_im1));
%eq.(8) in [2]
d = max(d12, d21);
结果演示:
splice_alltiles('.\tileImgs', '.\', 'splicedTiles_sort',100, 10, 10, [1:100]);
得到原始未分类图片:
[sort_idx, num_indv] = sortImgs('.\tileImgs', 100, 1.5);
splice_alltiles('.\tileImgs', '.\', 'splicedTiles_sort',100, 10, 10, sort_idx);
得到分类图片:
[local]2[/local]
num_indv =
21 14 12 11 2 2 10 12 4 1 1 3 3 1 3
表示按列优先顺序(从上往下,从左往右),前21块砖为1类, 紧接着的14块砖为另一类,以此类推。