How to remove small black dots in pictures (without using the method below how many pixels to remove)

12 views (last 30 days)
I have an image as shown above.Due to the dirt on the CMOS, there are many small black spots in the picture.
How can I remove them without using the method of removing less than how many pixels ? I'm worried about removing small bubbles in the images.
  4 Comments

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 12 Apr 2022
The standard way to do this is to make a mask of the bad spots and then use a modified median filter. Here are the steps
  1. Take the lens off and snap a photo. Make sure the image is not over exposed (look at the histogram).
  2. Segment (threshold) that photo to determine where the bad spots are. You get a binary mask image.
  3. Use a median filter on your image to be repaired with a window twice as big as your largest bad spot.
  4. Replace the bad spots in the mask with the median filtered image values:
  5. repaired = originalImage; % Initialize
  6. repaired(mask) = medianFilteredImage(mask);
You take the lens off so that you can be assured that the light on the sensor is uniform and has no structure in it. This will let you correct for defects or dust on the sensor. If you also need to correct for defects in the lens, then leave the lens on and take a picture of a uniform white background, like a sheet of white paper.
See attached examples where I do this for repairing salt and pepper noise.
  3 Comments
CW Hsu
CW Hsu on 24 Apr 2022
@Image Analyst I think your code and idea would be helpful for me . Thank you . But I'm a little confused about the section below :
Why not just use medianFliterImage instead of using a mask ? What's the difference ? How does 74 paragraph work ?
Image Analyst
Image Analyst on 24 Apr 2022
The median filter smooths out images, even where there is no extreme impulse noise. So a mask is used so that only the impulse noise is replaced and the pixels not in the mask and not identified as impulse noise are not changed. So the image remains the same with no blurring anywhere there is no noise. Only the noise is changed (repaired).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!