Drawing a Cirlce on an Image using viscircles()

7 ビュー (過去 30 日間)
Ash4Matlab
Ash4Matlab 2020 年 6 月 11 日
コメント済み: KSSV 2020 年 6 月 12 日
Dear all,
I am trying to put a circle at the center of an image using the folowing code.
clear;clc;
Image = imread('cameraman.tif');
M = 128; % cirlce array length
D = 0.5; % diameter
Pupil = (-fix(M/2):fix((M-1)/2));
figure(1)
imshow(Image)
viscircles([xPupil' xPupil'],D/2.*ones(M,1))
But it looks a pipe from the left corner of the image. I am using 2019a version of Matlab.
I would aprreciate if someone can fix this issue.
Thanks in advance.

回答 (1 件)

KSSV
KSSV 2020 年 6 月 11 日
You can draw circle using the below code if center C and radius R of the circle are known.
C = rand(1,2) ; % center of cricle
R = 1. ; % radius of the circle
m = 100 ;
th = linspace(0,2*pi,m) ;
x = C(1)+R*cos(th);
y = C(2)+R*sin(th) ;
plot(x,y)
  2 件のコメント
Ash4Matlab
Ash4Matlab 2020 年 6 月 12 日
Hello KSSV,
Thanks for the answer.
Actually I wanted to apply a circular mask on an image and depict that circle (or mask) on the image. For which as far as I know, viscirlces() shouLd work, but I am unable to put the image and the circle togather.
KSSV
KSSV 2020 年 6 月 12 日
Why not use the above code, provide center and radius, you can plot circle on the image. To draw a mask, get the indices lying inside the circle using inpolygon and make those indices zero.

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

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by