How to get data from a circular line on a 2D array in the anti-clockwise direction?

3 views (last 30 days)
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 Comments
Matt J
Matt J on 28 Mar 2023
Edited: Matt J on 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?
Jingtao
Jingtao on 28 Mar 2023
I want to get the raw data on the pixels instead of the interpolated data. If I disregard the problem of origin bias, is it easier to do the data transform? For instance, define (512,512) as the origin and 100 as the radius. If a pixel with the distance to the circular arc smaller than a tolerance (like 0.5 pixels), extract the data on the pixel and finally arrange all the data in a 1D array? Actually, I am confused with the detail. Appreciate if I could get your assistance.

Sign in to comment.

Accepted Answer

Joe Vinciguerra
Joe Vinciguerra on 28 Mar 2023
Edited: Joe Vinciguerra on 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 Comments
Joe Vinciguerra
Joe Vinciguerra on 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!

Sign in to comment.

More Answers (0)

Categories

Find more on Numeric Types in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!