I have an image where in I need to remove the "white" artifacts that do not represent a detected curve. I want to preserve the white pixels which represent the curve but, remove pixel outliers which are far away from the curve. After removing the artifacts, I would like to fit a smooth curve to the points in the image.
This is my image:
The image is a 8-bit grayscale image image with only black and white points. The white pixels in the "curve" are the area of interest and most of them are only a single pixel thick. Some white pixels are connected to each other but, not all of them. Some white pixels are strewn across. I would like to remove these white pixels since they are not contributing to the overall shape because I want to fit a smooth curve to them.
So far, I have tried to do dilation
followed by erosion
, closing
and black hat
operations. None of them seem to give me the result that I expect.
I also tried to iterate through all points in the image, find the bright points, look in a 3x3 neighborhood around that pixel and set the value to 0
if it did not have more than two neighbors which are equal to itself.
What can I apply in order to achieve my desired result? Also, once I have my final "clean" output, how do I fit a smooth curve to the points in the image?