How to get data from a circular line on a 2D array in the anti-clockwise direction?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I need to extract data from a circular line (with defined radius and origin) on a 2D array (captured by a CCD with 1024*1024 pixels), and arrange the extracted data in the anti-clockwise direction to be a 1D array. How can I do this?
Two problems need to be emphasized:
1) The pixels along the circular line should be continuous (no missing pixels);
2) Because the pixel number (1024) is even, the origin is biased if (512,512) or (513,513) is chosen as the origin. How to fix this problem without interpolating the pixel number to an odd number?
2 commentaires
Matt J
le 28 Mar 2023
Modifié(e) : Matt J
le 28 Mar 2023
How to fix this problem without interpolating the pixel number to an odd number?
Are you implying you want to do the whole thing without any interpolation? Even if the image grid dimensions were odd, the pixel locations on the circle circumference will not, in general, be in integer locations. So, interpolation would have to be used.
If you accept that interpolation must be used (as I think you must), how do you wish to define the sampling distance along the circular arc?
Réponse acceptée
Joe Vinciguerra
le 28 Mar 2023
Modifié(e) : Joe Vinciguerra
le 28 Mar 2023
sz = 1024; % CCD array size
A = peaks(sz); % some data from the CCD
x0 = 512; % known origin X
y0 = 512; % known origin Y
r = 100; % known radius
% this is what all the 2D data looks like
figure
contourf(A, 'LineStyle', 'none')
axis equal; hold on; grid on;
dTheta = atand(1/r); % calculate the smallest anglular step between pixels
theta = 0 : dTheta : 360-dTheta; % create an array of angles at which to find pixels
% convert from polar to cartesian, and round to the nearest pixel
x = round(x0 + r*cosd(theta));
y = round(y0 + r*sind(theta));
% remove duplicated pixels
[C, ia, ic] = unique([x',y'], "rows", "stable");
x = x(ia);
y = y(ia);
% a plot of our calculated circle over the CCD data
% zoom in if you want to see which pixels we are indexing
plot(x, y,'Color', 'red', 'Marker', '.', 'LineStyle', 'none')
% extract the pixle data for each point along the cicle
indx = sub2ind([sz sz], x, y);
B = A(indx);
% here is a plot of the extracted data
figure
plot(B, 'Color', 'red')
3 commentaires
Joe Vinciguerra
le 28 Mar 2023
Glad to hear. I edited a few minutes ago to add the part about removing duplicates (which sounds important for you application) so make sure you've got that as well. Cheers!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numeric Types dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!