按顺时针方向汇总所有交点

Summarize all intersection points by clockwise direction

这是我的一个程序,我已经 了解如何在我的图像上找到圆圈的交点,有人已经给出了答案(谢谢),我还有另一个问题...

a = imread('001_4.bmp');
I2 = imcrop(a,[90 5 93 180]);
[i,j]=size(I2);    

x_hist=sum(I2,1);
y_hist=(sum(I2,2))';

x=1:j ; y=1:i;
centx=sum(x.*x_hist)/sum(x_hist);
centy=sum(y.*y_hist)/sum(y_hist);

BW = edge(I2,'Canny',0.5);
bw2 = imcomplement(BW);
circle = int32([centx,centy,40]);%<<----------
shapeInserter = vision.ShapeInserter('Fill',false);
release(shapeInserter);
set(shapeInserter,'Shape','Circles');
% construct binary image of circle only
bwCircle = step(shapeInserter,true(size(bw2)),circle); 
% find the indexes of the intersection between the binary image and the circle
[i, j] = find ((bw2 | bwCircle) == 0);     
figure 
imshow(bw2 & bwCircle) % plot the combination of both images
hold on
plot(j, i, 'r*') % plot the intersection points
K = step(shapeInserter,bw2,circle);

[n,m]=size(i);
d=0;
k=1;
while (k < n)
    d = d + sqrt((i(k+1)-i(k)).^2 + (j(k+1)-j(k)).^2);
    k = k+1;        
end

问:如何按顺时针方向计算所有现有交点值(红色*)?

不确定,但我认为您的老师的意思与上一个问题中给出的答案有所不同,因为

  • CW方向可以是提示,不是附加问题
  • 我没有看到应该画圆的线索;因为小半径圆是块状的,简单的 bw_circle & bw_edges 可能不起作用。有关详细信息,请参阅 "Steve on image processing" 博客,"Intersecting curves that don't intersect"[1]
  • 可能是你的老师年纪大了,想要 Pascal-stile 的答案。

如果我的假设是正确的,下面的代码应该是正确的

img = zeros(7,7); %just sample image, edges == 1
img(:,4) = 1; img(sub2ind(size(img),1:7,1:7)) = 1;
ccx = 4; % Please notice: x is for columns, y is for rows
ccy = 3;
rad = 2;
theta = [(pi/2):-0.01:(-3*pi/2)]; 
% while plotting it will appear CCW, for visual CW and de-facto CCW use
% 0:0.01:2*pi
cx = rad * cos(theta) + ccx; % gives slightly different data as for 
cy = rad * sin(theta) + ccy; % (x-xc)^2 + (y-yc)^2 == rad^2 [2]
ccoord=[cy;cx]'; % Once again: x is for columns, y is for rows
[ccoord, rem_idx, ~] =unique(round(ccoord),'rows');
cx = ccoord(:,2); 
cy = ccoord(:,1);
circ = zeros(size(img)); circ(sub2ind(size(img),cy,cx))=1;
cross_sum = 0; 
figure, imshow(img | circ,'initialmagnification',5000)
hold on,
h = [];
for un_ang = 1:length(cx),
    tmp_val= img(cy(un_ang),cx(un_ang));
    if  tmp_val == 1 %the point belongs to edge of interest
        cross_sum = cross_sum + tmp_val;
        h = plot(cx(un_ang),cy(un_ang),'ro');
        pause,
        set(h,'marker','x')
    end
end
hold off

[1] https://blogs.mathworks.com/steve/2016/04/12/intersecting-curves-that-dont-intersect/

[2] http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F