bwareaopen not removing noise as expected

Hi,
I have been using bwareaopen to remove noise from a binary image without having any problem. But after i changed my thresholding function, the noise reduction stopped working as expected.
The code that worked:
gray = rgb2gray(my_image);
bw = imbinarize(gray);
bw = bwareaopen(bw,100);
The code that did not work:
ballImg = my_image(:,:,1)/2 + my_image(:,:,2)/2 - my_image(:,:,3)/2;
greenThreshold = ballImg < 80;
ball=zeros(size(ballImg));
ball(greenThreshold)=1;
bw = bwareaopen(ball,100);
Original image:
After modified code (that did not work):
Can anybody see the problem here?
Thanks in advance!

댓글 수: 1

I found the solution myself: the image needs to be reversed for bwareaopen to work properly :)
Fix:
ball=ones(size(ballImg));
ball(greenThreshold)=0;
bw = bwareaopen(ball,100);

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

답변 (1개)

Fanos Christodoulou
Fanos Christodoulou 2021년 4월 1일

0 개 추천

Just a comment on the above that could benefit others having a similar problem. My understanding is that the function bwareaopen deletes the white areas smaller than P pixels.
In your example above you need to reverse the black and white pixels first using the function imcomplement and then apply bwareaopen.
Best,
Fanos

제품

릴리스

R2017b

질문:

2018년 10월 4일

답변:

2021년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by