i am also solving a similar problem in which i need to draw a circle and make every pixel outside that circle to a same value (o or 1 doesn't matter). Any suggestions on ? Thanks in Advance

回答 (2 件)

Geoff Hayes
Geoff Hayes 2015 年 9 月 6 日

0 投票

gill11a - if your image is given by myImage then you could do something like the following to colour every pixel outside of the circle to be the same colour. Suppose that (a,b) is the centre of the circle with radius r. Then
function plotcircle(a,b,r)
close all;
% create a simple 100x200 image of random pixels
nrows = 100;
ncols = 200;
myImg = randi(255,nrows,ncols,3);
% iterate over each pixel and determine if it is outside the circle or not
for x=1:ncols
for y=1:nrows
if (x-a)^2 + (y-b)^2 > r^2
% pixel is outside of the circle, so colour it blue
myImg(y,x,:) = [0 0 255];
end
end
end
% display the image
image(myImg/255);
axis equal
Then you can call the above function as
plotcircle(50,100,25)
plotcircle(100,50,40)
Try the above and see what happens!

1 件のコメント

bhagyashri kapre
bhagyashri kapre 2017 年 1 月 19 日
thank you Geoff Hayes,This code is use full in my project

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

Image Analyst
Image Analyst 2015 年 9 月 6 日

0 投票

Also see my attached demos on masking with a circle.

2 件のコメント

gill11a
gill11a 2015 年 9 月 6 日
編集済み: Image Analyst 2015 年 9 月 6 日
Thanks for the prompt response. I think i forgot to mention one very important aspect of the problem: I do not know the radius of the circle i wish to crop. For eg. in the picture i attached, i want the program to identify the circles themselves, and then follow the procedure you described in your link.
Image Analyst
Image Analyst 2015 年 9 月 6 日
  1. Take any of the color channels.
  2. Take the middle row of the image.
  3. Call diff() to see where the value changes.
  4. Knowing the middle is at (number of columns)/2, compute radius.

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

カテゴリ

ヘルプ センター および File Exchange で 2-D and 3-D Plots についてさらに検索

質問済み:

2015 年 9 月 6 日

編集済み:

2017 年 1 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by