如何在圆角中找到值的位置?

时间:2017-05-06 18:20:17

标签: matlab image-processing

Matrix of example

正如您在照片中看到的那样,我只想在圆圈的末尾找到值的位置。我的意思是(1,5),(2,4),(3,3),(4,4),(5,5),(4,6),(3,7)这些点在矩阵。我怎么能用一个循环呢?

1 个答案:

答案 0 :(得分:1)

您可以使用bwboundaries单行进行此操作:

% generate binary circles image
[xg,yg] = meshgrid(1:50);
BW = (xg - 10).^2 + (yg - 20).^2 <= 7^2;
BW = BW | ( (xg - 20).^2 + (yg - 40).^2 <= 3^2) ;
BW = BW | ( (xg - 40).^2 + (yg - 10).^2 <= 2^2) ;
% find boundaries pixels
B = bwboundaries(BW);
% plot image and boundary pixels
imshow(BW,'InitialMagnification','fit')
hold on;
for ii = 1:numel(B)
    x = B{ii}(:,2);
    y = B{ii}(:,1);
    plot(x,y,'.','MarkerSize',15)
end

enter image description here