How can I track the boundary
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm going to track the boundary line ,but my photo was not very clearly about some of the point(missing point),how can i set the missing point to NaN and replace
to Proximity value,to make the line complete ,thanks
fclose all; close all; clear all; clf; clc;
cd 'C:\Users\User\Documents\MATLAB\test1\carmer1\photo1'
a=imread('img350.png');
i2=im2double(a);
ihd=rgb2gray(i2);
cd 'C:\Users\User\Documents\MATLAB\test1\carmer1\mavg1'
b=imread('imavg1.png');
b=im2double(b);
c=ihd-b;
msim_crop = imadjust(c,[0 0.1],[0 1],1.);
msim_crop = uint8(msim_crop);
bw0 = im2bw( msim_crop,graythresh(msim_crop).*0.01 );%0.12
windsz = 7; %4
H2 = fspecial('average',windsz); )
averaged_bw1 = imfilter(bw0,H2,'replicate');
the photo will look like this

so how can i just track the white boundary only like

채택된 답변
Image Analyst
2020년 6월 29일
If you want to find the light blue boundary on the left, I'd scan row by row using find() to find the leftmost white pixel. Then I'd fit a sliding quadratic to it with sgolayfilt(). Then I'd subtract the fit from the actual to find the distance. Distances that are greater than some amount, I'd discard. You might be able to use rmoutliers() for that. Give it a try. Here's a start
[rows, columns] = size(binaryImage);
leftColumns = columns * ones(rows, 1);
for row = 1 : rows
thisRow = binaryImage(row, :);
col = find(thisRow, 1, 'first')
if ~isempty(col)
leftColumns(row) = col;
end
end
smoothedColumns = sgolayfilt(leftColumns, 21, 2);
diffs = abs(smoothedColumns - leftColumns);
plot(diffs, 'b-', 'LineWidth', 2);
etc.
댓글 수: 3
Image Analyst
2020년 6월 29일
Sorry - I reversed the polynomial order and window width. It should be sgolayfilt(leftColumns, 2, 21) or some other number than 21. A bigger number gives more smoothing.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!