这是我用于边界框的代码
propied = regionprops(L,'Area','BoundingBox','MajorAxisLength');
多个边界框,以便循环使用
`for n=1:size(propied,1)`
we need to find minima and maxima for those
whose major axis length less than 28
there are too many bounding boxes
`if (propied(n).MajorAxisLength < 28)`
to get the bounding box of non-zero elements
and i am using 2 D image
`[y,x] = ind2sub(size(L), find(L));`
`coord = [x, y];`
`mc = min(coord)-0.5;`
`Mc = max(coord)+0.5;`
`end`
`end`
答案 0 :(得分:0)
您正在处理阿拉伯语脚本并尝试将Tashkil (Diacritics)与其相关字母ligature相关联。)
您假设adiacritic标记的'MajorAxisLength'
属性小于28像素,并且您希望将这些蒙版与不具有变音符号的主要字母的掩码相关联。
首先,让我们创建两个面具:一个用于装饰,一个用于主要字母
鉴于此输入图像BW
L = bwlabel( BW ); % label each component in the text
st = regionprops( BW, 'MajorAxisLength', 'PixelIdxList', 'Centroid' );
diac = [ st(:).MajorAxisLength ] < 28; % this is your threshold, it is not very good.
DM = zeros( size(BW) );
DM( vertcat( st(diac).PixelIdxList ) ) = 1; % mask for diacritics
LM = zeros( size(BW) );
LM( vertcat( st(~diac).PixelIdxList ) ) = 1; % mask for letters body
现在我们将使用每个变音符号的质心来定位最接近结扎的像素
[y x] = find( LM ); % coordinates of all ligature pixels
dc = vertcat( st(diac).Centroid ); % centroids of all diacritics
dst = sum( bsxfun( @minus, cat( 3, x, y), permute( dc, [3 1 2] ) ).^2, 3 ); % distance
[mn mi] = min( dst, [], 1 ); % closest LM pixel to each centroid
ll = L( sub2ind( size(L), y(mi), x(mi) ) ); % get the label of the closest ligature
可视化匹配结果
ac = vertcat( st(:).Centroid ); % all centroids
figure;
imagesc( DM + 2*LM );axis image;
hold on;
plot( [dc(:,1)'; ac(ll,1)'], [dc(:,2)';ac(ll,2)'], 'r');
colormap hot
请注意,
在'MajorAxisLength'
上使用阈值似乎并不能很好地识别变音符号,您可能需要考虑不同的阈值,或者改为对'Area'
属性进行阈值处理。