這裏是另一個建議:
- 刪除所有的背景
- 假定在數據的雙峯分佈(除去零之後)這個「行」的結果,發現下模式。
- 假設線的值總是比背景下,應用邏輯掩碼設置爲零的最小+ 2nd_mode所有值以上,如在下面的圖中證實(在紅色圓圈):
這裏是它如何工作的:
A = Slant(any(Slant,2),:); % save in A only the nonzero data
現在我們有A
,看起來像這樣:
[y,x] = findpeaks(histcounts(A)); % find all the mode in the histogram of A
sorted_x = sortrows([x.' y.'],-2); % sort them by their hight in decendet order
mA = A<min(A(:))+sorted_x(2,1); % mask all values above the second mode
result = A.*mA; % apply the mask on A
而我們得到的result
:
所得線裏面出現一些漏洞,所以你可能想從插值結果整條生產線。這可以用簡單的數學上做索引:
[y1,x1] = find(mA,1); % find the first nonzero row
[y2,x2] = find(mA,1,'last'); % find the last nonzero row
m = (y1-y2)/(x1-x2); % the line slope
n = y1-m*x1; % the intercept
f_line = @(x) m.*x+n; % the line function
所以我們得到了一個線功能f_line
像這樣(在下面紅色):
現在,我們想使這條線較粗,就像數據中的直線一樣,所以我們採用厚度模式(通過計算每列中的值,您可能需要改爲max
),並將該線的「一半」擴展到兩邊:
thick = mode(sum(mA)); % mode thickness of the line
tmp = (1:thick)-ceil(thick/2); % helper vector for expanding
rows = bsxfun(@plus,tmp.',floor(f_line(1:size(A,2)))); % all the rows for each coloumn
rows(rows<1) = 1; % make sure to not get out of range
rows(rows>size(A,1)) = size(A,1); % make sure to not get out of range
inds = sub2ind(size(A),rows,repmat(1:size(A,2),thick,1)); % convert to linear indecies
mA(inds) = 1; % add the interpolation to the mask
result = A.*mA; % apply the mask on A
現在result
看起來是這樣的:
來源
2017-06-12 21:12:42
EBH
是矩陣非零隨處可見的圖像? – flawr
矩陣在彩色區域中不爲零。除此之外,它的值爲零。 – Sack11
爲什麼你用這麼大的矩陣有太多的條目,不添加任何東西?這條線有什麼特性可以區分它和其他部分?沒有任何關於你期望的結構和信息的知識,這似乎是不可能解決的。 – flawr