Filter löschen
Filter löschen

Get data within circular ROI

29 Ansichten (letzte 30 Tage)
D F
D F am 2 Sep. 2019
Kommentiert: D F am 2 Sep. 2019
Hi,
I have a 2D mesh of datapoints (200x200 coordinates) that I've called plot_data. I have drawn a circular ROI on the mesh and want to extract all the coordinates within this circle.
The circle has been drawn as the following, where x and y are the coordinates that I've extracted for the line that is the circle:-
theta = linspace(0,360);
radius = 20 %circle radius
centre = [100,100] %circle centre
y = radius*sind(theta)+centre(2);
x = radius*cosd(theta)+centre(1);
c = plot(x,y,'k'); %draw circle
How would I get all the datapoints within this circle please?
Thanks!

Akzeptierte Antwort

Rik
Rik am 2 Sep. 2019
This code also works for non-integer positions and radii.
data=rand(200,200); %generate example data
radius = 20; %circle radius
centre = [100,100]; %circle centre
[X,Y]=ndgrid(1:size(data,1),1:size(data,2));
X=X-centre(1);Y=Y-centre(2);%shift coordinate grid
L=sqrt(X.^2+Y.^2)<=radius;
data_within_circle = data(L);
  1 Kommentar
D F
D F am 2 Sep. 2019
That's worked great - thanks for the help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by