我有一个带有白点的二值图像:

我想用一个大小相同的矩形来表示每个白点,如果可能的话,用相同的方向。有什么功能可以做到吗?我可以用RP检测每一个点:

发布于 2017-04-08 01:07:46
我将计算最小的Feret直径(最短投影)与相应的角度,以及垂直投影。通常对应于最小的边框。
有关计算渡口直径的MATLAB代码,请参阅此处:http://www.crisluengo.net/archives/408
发布于 2017-04-07 16:38:24
您可以尝试使用regionprops,如下所示:
I = imread('tHZhy.png');
stats = regionprops(I, 'centroid', 'Orientation', 'MajorAxisLength','MinorAxisLength', 'BoundingBox');
figure
imshow(I)
hold on
for i=1:length(stats)
xc = stats(i).Centroid;
ma = stats(i).MajorAxisLength/2;
mi = stats(i).MinorAxisLength/2;
theta = -deg2rad(stats(i).Orientation);
dx = [-ma -mi; ma -mi; ma mi; -ma mi; -ma -mi];
R = [cos(theta) -sin(theta); sin(theta) cos(theta)]; % rotation matrix
x = xc + dx*R';
plot(xc(1), xc(2), 'g*');
plot(x(:, 1), x(:, 2), 'g');
end请注意,结果并不完美,特别是对于方形对象。因此,其原因是当它沿着对角线方向时,主要维度是最大的。

https://stackoverflow.com/questions/43280802
复制相似问题