フィルターのクリア

How do I obtain a cell array containing the pixel coordinates of the area inside a circle?

2 ビュー (過去 30 日間)
Hi, I know that a similar question has been asked here https://www.mathworks.com/matlabcentral/answers/167735-how-to-determine-the-position-of-points-which-belong-to-a-circle. I have implemented the code shown in the above link inside the program attached. I want to obtain a cell array that contains all the pixel coordinates that belong to a circle (where radius and centroid is known) but it returns an entirely empty cell array (logical error). I have attached the code below with hope that someone will tell me what I did wrong. I'm not very experienced with Matlab. I also have a feeling that there is a more elegant way of doing this other than what you see in my code. Any help would be appreciated.
  1 件のコメント
KSSV
KSSV 2018 年 5 月 31 日
Don't attach your code as an image snippet. YOu have to copy paste the code, so that users can read and help you.

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

採用された回答

KSSV
KSSV 2018 年 5 月 31 日
You can use inbuilt function inpolygon to get the points lying inside the circle. Check the below example code:
I = imread('peppers.png') ;
[m,n,p] = size(I) ;
% circle
C = [100 200] ;
R = 50 ;
% plot circle
th = linspace(0,2*pi) ;
xc = C(1)+R*cos(th) ;
yc = C(2)+R*sin(th) ;
imshow(I)
hold on
plot(xc,yc)
% get points inside the circle
[X,Y] = meshgrid(1:n,1:m) ;
idx = inpolygon(X(:),Y(:),xc,yc) ;
plot(X(idx),Y(idx),'.k')
% get the pixels
iwant = zeros(nnz(idx),1,p) ;
for i = 1:p
T = I(:,:,i) ;
iwant(:,:,i) = T(idx) ;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by