How do I obtain a cell array containing the pixel coordinates of the area inside a circle?
1 次查看(过去 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
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
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!