How to identify a thin line in a noisy sideview picture?

40 views (last 30 days)
I have a set of binarized pictures (like the following one) of the water surface in a small portion of flume, taken during a laboratory experiment. The water surface is represented by the thin curved line, but as you can see the picture is "corrupted" by other big white patches representing light reflections on the flume glass walls, that I could not get rid of.
I am working on a script that tries to detect the position of the water surface and fits it with a spline. I tried to remove the extra patches by filtering them by area (i.e. by removing the patches with pixel area lower than a threshold) before fitting the spline; but I am stuck because for many pictures the area of the water surface patch is roughly the same as those of the extra patches, so they are both removed by the filter. Moreover, occasionally the extra patches intersect the surface patch, as is the case in the picture below.
Can you help me figuring out a method to fit a curve to identify the surface, that is as less sensitive as possible to the presence of the extra patches? Thank you.

Answers (2)

Kevin Holly
Kevin Holly on 17 Dec 2025 at 15:48
Here are some ideas to get it closer:
BW = imread("example.png");
% Filter to remove patches (Used Image Region Analyzer App)
CC = bwconncomp(BW);
CC = bwpropfilt(CC,'EulerNumber',[-5, 1]);
CC = bwpropfilt(CC,'Eccentricity',[0.97, 1]);
CC = bwpropfilt(CC,'Orientation',[-1, 75]);
BW = cc2bw(CC);
% trying to remove intersected patches
BW2 = imerode(BW,strel('disk', 4));% erode to eliminate thin curved line to isolate patches
BW2 = imdilate(BW2,strel('disk', 4)); % dilate patches to previous state
imshow(BW-BW2)
%Apply previous filters again to get rid of the left over pixels.
BW = BW-BW2;
CC = bwconncomp(BW);
CC = bwpropfilt(CC,'EulerNumber',[-5, 1]);
CC = bwpropfilt(CC,'Eccentricity',[0.97, 1]);
CC = bwpropfilt(CC,'Orientation',[-1, 75]);
BW = cc2bw(CC);
% could filter area
imshow(BW)
  1 Comment
Lorenzo Melito
Lorenzo Melito on 18 Dec 2025 at 9:14
@Kevin Holly, thank you very much for your help! I didn't know about bwpropfilt. I will try to experiment with it a little bit, especially with the other pictures in the set, for which the definition of the water surface and the amount of extra patches may be different.

Sign in to comment.


Image Analyst
Image Analyst on 18 Dec 2025 at 17:40
It would be better to eliminate the reflections first. I don't know what you tried. Did you try changing the geometry of the camera and light source(s)? Did you try crossed polarizers? Did you try using baffles? How about gaffers tape?
If you tried all that and still have reflections, then it might be that your binarization algorithm is not that great. What did you do to binarize it? Can you attach the original gray scale image so we can look at that?
How smooth is the surface of the liquid? Why are you using a spline? Why not use the actual coordinates? Why are you not fitting something like a cubic or quadratic polynomial to the surface? What are you going to do with the spline after determining it?
Have you tried deep learning on the gray scale image to find the surface line?

Products


Release

R2025b

Community Treasure Hunt

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

Start Hunting!