我有一个2边的图像
如果我然后使用下面的代码绘制边的边界:
imshow(I);坚持,稍等; [B,L,N] = bwboundaries(I);对于k = 1:长度(B), boundary = B {k}; BL =大小(边界)…
不是你问题的完整答案,而是我想出的一个想法。您可以检查边界的所有点是否与图像边界“接近”,然后找到最小值/最大值 (x, y) 价值,这将描述你感兴趣的那些“目的”。
(x, y)
B = bwboundaries(img); % Threshold for "closeness" to an image border. thrNear = 5; for k = 1:numel(B) b = B{k}; nearTop = b(:, 1) < thrNear; nearBottom = b(:, 1) > (size(img, 1) - thrNear); nearLeft = b(:, 2) < thrNear; nearRight = b(:, 2) > (size(img, 2) - thrNear); closeToTop = b(nearTop, :) closeToBottom = b(nearBottom, :) closeToLeft = b(nearLeft, :) closeToRight = b(nearRight, :) end
例如,对于原始图像中的正确形状,您将获得:
closeToTop = [](0x2) closeToBottom = [](0x2) closeToLeft = [](0x2) closeToRight = 79 283 79 284 79 285 79 286 79 287 80 287 81 287 81 286 81 285 81 284 81 283 215 283 215 284 215 285 215 286 215 287 216 287 217 287 217 286 217 285 217 284 217 283
现在,尽力而为 x 价值(287),找到合适的(非相邻的) y 价值观(79-81对215-217)。对每个图像边框重复此操作。
x
y
我希望,你明白我的想法。说实话,我不想完全实现,但如果我的描述不够准确,请不要犹豫。