2017-03-18 39 views
1

中間的直線方程,我想安裝一個進線方程來描述它。如何提取,適合在我所檢測到的線輪廓的粗線輪廓

我試圖最小二乘擬合,但由於透視失真,該線的一端是較厚和在一端與漂移因而線方程的一側。

我已經使用張-孫減薄方法還考慮,但這樣的算法似乎過殺一個簡單的線

enter image description here enter image description here

+3

你嘗試skeletoning行?所以它最多隻有一個像素寬度。 – Ozcan

+0

是否有一些非迭代方法提取骨架?鄭suen似乎有點矯枉過正 – Alvar

+0

你能提供一行樣本圖片嗎? – Ozcan

回答

3

一個簡單而有效的方法是計算第一principal component線上的點數。這是在MATLAB代碼:

% Read image 
im = imread('https://i.stack.imgur.com/pJ5Si.png'); 

% Binarize image and extract indices of line pixels 
imbw = imbinarize(rgb2gray(im), 'global'); % Threshold with Otsu's method 
[y, x] = ind2sub(size(imbw), find(imbw)); % Get indices of line pixels 

% Extract first principal component 
C = cov(x, y);        % Compute covariance of x and y 
coeff = pcacov(C);       % Compute eigenvectors of C 
vector_xy = [coeff(1,1), coeff(2,1)];  % Get fist principal component 

% Plot 
figure; imshow(im); hold on 
xx = vector_xy(1) * [-1 1] * size(imbw,2) + mean(x(:)); 
yy = vector_xy(2) * [-1 1] * size(imbw,2) + mean(y(:)); 
plot(xx,yy,'c','LineWidth',2) 
axis on, legend('Principal Axis','Location','NorthWest') 

enter image description here

您可以獲得線性方程y = a*x + b的係數與

a = vector_xy(2)/vector_xy(1); 
b = mean(y(:)) - a * mean(x(:)); 
+0

將ICA性能更好非正交方向? – Alvar

+0

這很可能。我想你必須嘗試一下。您也可以嘗試通過形態濾波去除噪音。 – Richard