2016-08-12 107 views
-3

請幫助我找到附加圖像中用綠色點標記的點的座標。線的斜率是已知的,並且中心的座標對於圖像是已知的。我想在MATLAB中編寫代碼。請給我同樣的想法。
圖像由座標已知的中心點組成,並且知道通過中心點的直線的斜率確定綠點座標。找到圖像上的座標,知道一條線的中心點和斜率

+0

你的意思是你的輸入是一個圖像,你想使用圖像處理技術來獲得座標? –

+0

嗨prashanth,請寫一個[最小,完整和可驗證的例子](http://stackoverflow.com/help/mcve) – obchardon

回答

0

我創建了通過中心座標的座標矢量,並具有所需的斜率。
我用過極座標來創建X,Y座標向量。
找到座標後,我搜索曲線上的綠色圓點。
我的解決方案是不理解(不是最優雅的)那麼簡單......

這裏是我的代碼:

%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)] 

結果圖像(用於測試):
enter image description here

1

如果中心點是已知的,我認爲,沒有必要做圖像處理。 你需要的是一個線性方程。

y = tan(slope) * x 

然後你只需簡單地找到x1x2,因爲y1y2也從照片聞名。

+0

實際上斜率已經是角度的切線。所以'y = slope * x' –

相關問題