필터 지우기
필터 지우기

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

조회 수: 1 (최근 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
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?
Jingtao
Jingtao 2023년 3월 28일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Joe Vinciguerra
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
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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by