How to Create Graded lines inside the binary circle mask?

1 回表示 (過去 30 日間)
fred bnm
fred bnm 2018 年 5 月 21 日
編集済み: fred bnm 2018 年 5 月 22 日
I have a binary circle mask. and i need create new binary mask from that with Graded lines inside the circle.Degrees is 45,90,135,180. please guide me.
clc; clear;
%%create circle mask
mask = zeros(400,600);
position = [200,300];
cx = position(1);
cy = position(2);
r = 50;
[ix,iy] = size(mask);
[x,y]=meshgrid(-(cx-1):(ix-cx),-(cy-1):(iy-cy));
c_mask=((x.^2+y.^2)<=r^2)';
figure,imshow(c_mask)
%%Create Graded lines inside the circle.
%find center of circle
BW = c_mask;
prob = regionprops(BW,'centroid');
center = prob.Centroid;
figure, imshow(BW)
hold on
plot(center(1),center(2),'rx','MarkerSize',18,'LineWidth',2);

回答 (1 件)

KSSV
KSSV 2018 年 5 月 21 日
YOu decide the angles needed, and use this:
th = [45,90,135,180] ;
x = center(1)+r*cos(th) ;
y = center(2)+r*sin(th) ;
for i = 1:length(th)
plot([center(1) x(i)],[center(2) y(i)],'r')
end
Note that, to draw line, loop is not required.
  3 件のコメント
KSSV
KSSV 2018 年 5 月 21 日
Not clear.....can you elaborate?
fred bnm
fred bnm 2018 年 5 月 21 日
i want create new mask using imwrite. but this code just plot.

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

カテゴリ

Help Center および File ExchangeAuthor Block Masks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by