在知道直线的中心点和斜率的情况下找到图像上的坐标 [英] Finding the coordinates on the image knowing the center point and slope of a line

查看:101
本文介绍了在知道直线的中心点和斜率的情况下找到图像上的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我找到所附图像中标有绿点的点的坐标.对于图像,线的斜率是已知的,而中心的坐标是已知的.我想在MATLAB中编写代码.请给我同样的想法.
图像由坐标已知的中心点组成,并且在知道穿过中心点的线的斜率的情况下确定绿点坐标.

Please help me in finding the coordinates of the point marked with green dots in the attached image. The slope of the line is known and the coordinates of the center are known for an image. I want to write a code in MATLAB. Please give me ideas for the same.
The image consists of the center points whose coordinates are known, and green dots coordinates are to be determined knowing the slope of the line passing through the center point.

推荐答案

我创建了通过中心坐标并具有所需斜率的坐标矢量.
我曾经通过极坐标来创建X,Y坐标向量.
找到坐标后,我搜索了曲线上的绿点.
我的解决方案不是那么容易理解(不是最优雅)...

I created vector of coordinates that passes center coordinate, and have the desired slope.
I used went through polar coordinates to create X, Y coordinates vectors.
After finding the coordinates, I searched the green dots on the curve.
My solution is not so simple for understanding (not most elegant)...

这是我的代码:

%Input image (for testing).
I = imread('cameraman.tif');
I = cat(3, I, I, I); %Make I it "color" image where (R = G = B).

center = [100, 100];
slope = 1.5;

%Mark the center point with red (for debugging).
I(center(1)-1:center(1)+1, center(2)-1:center(2)+1, 1) = 255;

%Put green dots (for debugging).
x0 = 123;y0 = 65;
x1 = 12;y1 = 232;
I(y0-1:y0+1, x0-1:x0+1, 2) = 255;I(y0, x0, 1) = 0;I(y0, x0, 3) = 0;
I(y1-1:y1+1, x1-1:x1+1, 2) = 255;I(y1, x1, 1) = 0;I(y1, x1, 3) = 0;

%    #
% 1.5#   #
%    #  #
%    # #
%    ## alpha
%    ############
%        1

alpha = -atan2(slope, 1);

%Create vector of "radius" (distance from the center).
r = -norm(size(I))/2:0.2:norm(size(I))/2;

%Each (x,y) coordinate is on the line passing through center point
x = r*cos(alpha) + center(2);
y = r*sin(alpha) + center(1);

%Remove x and y outsize image boundaries from x, y arrays.
X = x;Y = y;
X((x < 1) | (x > size(I,2)) | (y < 1) | (y > size(I,1))) = [];
Y((x < 1) | (x > size(I,2)) | (y < 1) | (y > size(I,1))) = [];

%Round X and Y (to be legal pixel coordinates). 
X = round(X);
Y = round(Y);

R = zeros(size(X)) + 1; %Coordinate of 1'rd plane (red channel).
G = zeros(size(X)) + 2; %Coordinate of 2'rd plane (green channel).
B = zeros(size(X)) + 3; %Coordinate of 3'rd plane (blue channel).

%V gets values of pixels channel pixels in the curve.
rV = I(sub2ind(size(I), Y, X, R)); %Red channel values.
gV = I(sub2ind(size(I), Y, X, G)); %Green channel values.
bV = I(sub2ind(size(I), Y, X, B)); %Blue channel values.

%Find green dots where r, g, b = 255.
V = (rV == 0) & (gV == 255) & (bV == 0);

%Mark X,Y coordinates with blue color (for debugging).
I(sub2ind(size(I), Y, X, B)) = 255;

figure;imshow(I)

v0 = find(V, 1, 'last');
v1 = find(V, 1);
greenDot0 = [Y(v0), X(v0)]
greenDot1 = [Y(v1), X(v1)]

结果图片(用于测试):

Result image (used for testing):

这篇关于在知道直线的中心点和斜率的情况下找到图像上的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆