How to convert arc circle plot into binary circle?

 採用された回答

KSSV
KSSV 2021 年 6 月 17 日

0 投票

R = 1;
th = linspace(0,2*pi,1000) ;
x = R*cos(th) ; y = R*sin(th) ;
xi = linspace(-2,2,100) ;
yi = linspace(-2,2,100) ;
[X,Y] = meshgrid(xi,yi) ;
Z = zeros(100) ;
idx = knnsearch([X(:) Y(:)],[x' y']) ;
Z(idx) = 1 ;
imagesc(Z)

3 件のコメント

afiq rauf
afiq rauf 2021 年 6 月 17 日
thank you, and may i know how can i remove the arc that i have shown in the first picture?
KSSV
KSSV 2021 年 6 月 17 日
Remove the arc?
Walter Roberson
Walter Roberson 2021 年 6 月 19 日
Change
th = linspace(0,2*pi,1000) ;
to only have the range of angles that you want the arc to cover.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 6 月 19 日

0 投票

But for your purpose, instead of using plot(), multiply the coordinates by the resolution you want, and round() them, and then subtract off the minimum x and y . Now you have matrix coordinates.
resolution = 25;
th = linspace(0, 7*pi/9, 500);
r = 5;
xc = 3;
yc = 7;
[x,y] = pol2cart(th, r);
x = x + xc;
y = y + yc;
%the above are data coordinates. Make them into array coordinates.
buffer = 5;
xm = round(x * resolution);
ym = round(y * resolution);
xmin = min(xm);
ymin = min(ym);
xmax = max(xm);
ymax = max(ym);
xmc = xm - xmin + 1 + buffer;
ymc = ym - ymin + 1 + buffer;
arc_image = accumarray([ymc(:), xmc(:)], 1);
imshow(arc_image)

カテゴリ

ヘルプ センター および File ExchangePolar Plots についてさらに検索

タグ

質問済み:

2021 年 6 月 17 日

回答済み:

2021 年 6 月 19 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by