How to define the surface line of a wave? Hought Transform on not straight lines and interpolation for mising parts.

1 次查看(过去 30 天)
Hi Matlab Friends,
I have following problem that I hope to get help with:
My goal is to film flowing water through a window and detect the water surface line. I attached the original image and the segmented image of the water: As you can see, there is some serious reflection happening, which is segmented as well. Additionally, one party of the sidewall is not see-through resulting in missing parts of the wave.
Ho do I define only the surface as a not-straight line and maybe interpolate the missing part?
  • Is there a method for Hough transformation to fit a curved line?
  • A second idea would be to get the coordinates of the edges by bwboundaries() and use polynomial curvefitting. However, the whole water body gets detected creating a round-ish object and I don't know to extract only the values of the surface line. The data I have so far is the cell array of coordinates of the red line, surrounding the wave:
wave_coordinates = bwboundaries(BW);
xy = cell2mat(wave_coordinates);
waveX = xy(:,1); %20287x1 double
waveY = xy(:,2); %20287x1 double
I am curious for your solution approaches!
  1 个评论
Hannah
Hannah 2024-6-3
A first attempt of mine would be
wave_coordinates = bwboundaries(BW);
xy = cell2mat(wave_coordinates);
%create array with y values
waveY = xy(:,1);
%create array with y values
waveX = xy(:,2);
%find edge points (where x is min and max)
[edge1 idx1] = min(waveX)
[edge2 idx2] = max(waveX)
%find all points that are above the right edge point
idx_upperLine = waveY >= waveY(idx1);
%create array with x and y coordinates of all point above the edge point (which is hopefully the upper Line)
surfaceX = nonzeros(waveX(idx_upperLine));
surfaceY = nonzeros(waveY(idx_upperLine));

请先登录,再进行评论。

回答(1 个)

Kothuri
Kothuri 2024-6-21
Hi Hannah,
Traditional line detection methods like the Hough transform are typically used for straight line detection, may not be directly applied for curved line detection. Since the water surface is not a straight line, polynomial curve fitting, or spline fitting could be more appropriate.
You can use MATLAB's polyfit function to fit a polynomial to fit the water surface line is within a certain region of the image.
For e.g:
% Assuming waveX and waveY are the coordinates and you have filtered them to focus on the water surface
p = polyfit(waveX, waveY, degree); % Choose an appropriate degree
fitY = polyval(p, waveX);
plot(waveX, fitY, 'r-', 'LineWidth', 2); % This plots the fitted curve
You can refer the below link for more info on polyfit
You can also try Spline fitting using MATLAB fit function for a more flexible fit that can better adapt to the curvature of the water surface.
For e.g:
fitType = 'smoothingspline'; % This type of spline allows for smoothing which might be necessary for noisy data
fitOptions = fitoptions('Method', 'SmoothingSpline', 'SmoothingParam', 0.5); % Adjust the smoothing parameter as needed
curveFit = fit(waveX, waveY, fitType, fitOptions);
plot(curveFit, waveX, waveY); % This plots the fitted curve along with the original points

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by