Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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 commentaire
KSSV
KSSV le 31 Mai 2018
Don't attach your code as an image snippet. YOu have to copy paste the code, so that users can read and help you.

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 31 Mai 2018
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

Plus de réponses (0)

Produits


Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by