필터 지우기
필터 지우기

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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by