How to get data from a circular line on a 2D array in the anti-clockwise direction?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Matt J
2023-3-28
编辑:Matt J
2023-3-28
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?
采纳的回答
Joe Vinciguerra
2023-3-28
编辑:Joe Vinciguerra
2023-3-28
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 个评论
Joe Vinciguerra
2023-3-28
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!