필터 지우기
필터 지우기

Finding coordinates of point(s) that are specific distance(s) away on a slanted straight line

조회 수: 3 (최근 30일)
Hello, I am a physician trying to locate points of interest on medical images. My problem boils down to the following:
I have an image with 7 points of interest that I need to identify on my image. The 7 points lie in a slanted straight line like so:
I could take advantage of image properties to find the coordinates of point A and C. d1, d2, and d3 are all known values. What script should I run to find the coordinates of the 2 crosses d1 distance from A? And similarly, how do I find the coordinates for B, and the 2 coordinates d3 distance from that?
Thank you so much for your help!
  댓글 수: 1
Star Strider
Star Strider 2016년 8월 20일
Do you have any recommendations for radiology text or reference books relevant to both clinical and technical perspectives? (I’d appreciate Author-Title-ISBN so I know I’m getting the correct ones.) I’ve been looking for a while, but haven’t found any that seem to cover what I want. You’re the perfect person to ask!

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

채택된 답변

Star Strider
Star Strider 2016년 8월 20일
Not a function, but a short bit of code:
A = [5 10]; % Create Data
C = [7 15]; % Create Data
d1 = 2.1;
d2 = 3.8;
d3 = 1.5;
x = [A(1); C(1)]; % Define Independent Variables
y = [A(2); C(2)]; % Define Dependent Variables
P = [ones(size(x(:))) x(:)]\y(:); % Calculate Intercept, Slope For Line
phi = atan2(diff(y), diff(x)); % Slope Angle (rad)
LineDist = @(V,d,phi) [V(1)+d*cos(phi) V(2)+d*sin(phi); V(1)-d*cos(phi) V(2)-d*sin(phi)];
d1X = LineDist(A,d1,phi); % ‘d1’ Coordinates
B = LineDist(C,d2,phi); % ‘B’ Coordinates
d3X = LineDist(B(1,:),d3,phi); % ‘d3’ Coordinates
xv = linspace(min(x)-3, max(x)+3); % X-Vector For Plot
yv = [ones(size(xv(:))) xv(:)]*P; % Y-Vector For Plot
figure(1)
plot(xv, yv)
hold on
plot(x, y, 'ok', 'MarkerFaceColor','k')
plot(d1X(1,1), d1X(1,2), 'xr')
plot(d1X(2,1), d1X(2,2), 'xr')
plot(B(1,1), B(1,2), 'xk')
plot(d3X(1,1), d3X(1,2), 'xr')
plot(d3X(2,1), d3X(2,2), 'xr')
hold off
grid
text(A(1)+0.1,A(2), 'A', 'HorizontalAlignment','left')
text(B(1,1)+0.1,B(1,2), 'B', 'HorizontalAlignment','left')
text(C(1)+0.1,C(2), 'C', 'HorizontalAlignment','left')
text(d1X(:,1)+0.1,d1X(:,2), 'd1', 'HorizontalAlignment','left')
text(d3X(:,1)+0.1,d3X(:,2), 'd3', 'HorizontalAlignment','left')
The plot:
Board-Certified Internist here, with M.Sc. in Biomedical Engineering!
  댓글 수: 8
Image Analyst
Image Analyst 2016년 8월 20일
"a line orthogonal to a given line (in a plane) has a slope (not the angle of the slope) that is the negative of that of the given line" <== it's slope is actually -1/slope, the negative inverse.
Star Strider
Star Strider 2016년 8월 20일
The ‘phi±(pi/2)’ idea works. It’s necessary to use axis equal on the plot to see it correctly.
Adding the off-line distance ‘d4’ and calculating the perpendicular line at ‘C’ as the ‘PrpC’ coordinate matrix (plotted in green here), the complete code becomes:
A = [5 10]; % Create Data
C = [7 15]; % Create Data
d1 = 2.1;
d2 = 3.8;
d3 = 1.5;
x = [A(1); C(1)]; % Define Independent Variables
y = [A(2); C(2)]; % Define Dependent Variables
P = [ones(size(x(:))) x(:)]\y(:); % Calculate Intercept, Slope For Line
phi = atan2(diff(y), diff(x)); % Slope Angle (rad)
LineDist = @(V,d,phi) [V(1)+d*cos(phi) V(2)+d*sin(phi); V(1)-d*cos(phi) V(2)-d*sin(phi)];
d1X = LineDist(A,d1,phi); % ‘d1’ Coordinates
B = LineDist(C,d2,phi); % ‘B’ Coordinates
d3X = LineDist(B(1,:),d3,phi); % ‘d3’ Coordinates
d4 = 5;
PrpC = LineDist(C,d4,phi+pi/2);
xv = linspace(min(x)-3, max(x)+3); % X-Vector For Plot
yv = [ones(size(xv(:))) xv(:)]*P; % Y-Vector For Plot
figure(1)
plot(xv, yv)
hold on
plot(x, y, 'ok', 'MarkerFaceColor','k')
plot(d1X(1,1), d1X(1,2), 'xr')
plot(d1X(2,1), d1X(2,2), 'xr')
plot(B(1,1), B(1,2), 'xk')
plot(d3X(1,1), d3X(1,2), 'xr')
plot(d3X(2,1), d3X(2,2), 'xr')
plot(PrpC(:,1)', PrpC(:,2)', 'p-g')
hold off
grid
text(A(1)+0.1,A(2), 'A', 'HorizontalAlignment','left')
text(B(1,1)+0.1,B(1,2), 'B', 'HorizontalAlignment','left')
text(C(1)+0.1,C(2), 'C', 'HorizontalAlignment','left')
text(d1X(:,1)+0.1,d1X(:,2), 'd1', 'HorizontalAlignment','left')
text(d3X(:,1)+0.1,d3X(:,2), 'd3', 'HorizontalAlignment','left')
text(PrpC(:,1)+0.1,PrpC(:,2), 'd4', 'VerticalAlignment','bottom')
axis equal
with the plot:

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

추가 답변 (1개)

Image Analyst
Image Analyst 2016년 8월 20일
Knowing points A and C, the equation of the line is
slope = (yc-ya) / (xc - xa);
y = slope * (x - xa) + ya;
To get the x for the left and right d1 point from A
angle = atan(slope);
xd1Left = xa - d1 * cos(angle);
xd1Right = xa + d1 * cos(angle);
To get point B from known point C
xb = xc + d2 * cos(angle);
To get the d3 points
xd3Left = xc + (d2-d3) * cos(angle);
xd3Right = xc + (d2+d3) * cos(angle);
To get the y values for any of those x values, plug them in for x in the formula for the line:
y = slope * (x - xa) + ya;

카테고리

Help CenterFile Exchange에서 Voronoi Diagram에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by