How to get data from a circular line on a 2D array in the anti-clockwise direction?
2 ビュー (過去 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!