How to detect small white pixels in an image and change their colour

조회 수: 5 (최근 30일)
Jalal Al-Lami
Jalal Al-Lami 2021년 1월 23일
편집: Image Analyst 2021년 1월 23일
I have a tif image with lots of small white pixels dispersed throughout on a dark bluish background. How can I use Matlab to detect those small white pixels and change them into the same blue shade as my image background? Please note that my image contains other colours that I want to keep unchanged. I just need to get rid of the white pixels and merge them with my bluish background. Thanks!

답변 (2개)

Walter Roberson
Walter Roberson 2021년 1월 23일
Are there other white pixels that need to be retained? If there are, can they be distinguished by size? Or is it necessary to look at surrounding color as well to determine whether to get rid of any particular small white pixel?
  댓글 수: 2
Jalal Al-Lami
Jalal Al-Lami 2021년 1월 23일
Yes, there are other large white pixels that I want to retain. It is easy to differentiate between the large and small pixels by size because the size difference is quite big. I just need to get rid of the small white ones by merging them with the bluish background colour that I have. Thanks.
Walter Roberson
Walter Roberson 2021년 1월 23일
Threshold on all three RGB channels being sufficiently large, in order to get true for white and false for non-white. bwareafilt() to get regions below a particular size. What remains will be a binary map of locations that need to be filled in with the background color.
It is usually a nuisance to fill a 3D array based upon a 2D mask, so often the easiest is
R = YourImage(:,:,1);
R(mask) = background_pixel_red_component; %eg 0
G = YourImage(:,:,2);
G(mask) = background_pixel_green_component; %eg 0
B = YourImage(:,:,3);
B(mask) = background_pixel_blue_component; %eg 32
NewImage = cat(3, R, G, B);

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2021년 1월 23일
편집: Image Analyst 2021년 1월 23일
You can use regionfill(), or you can treat them as salt and pepper noise and use my attached demo which uses a modified median filter. Attach your image if you need more help.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by