Small objects not being removed using bwareaopen()

조회 수: 4 (최근 30일)
Rebecca Napolitano
Rebecca Napolitano 2018년 5월 2일
답변: Rebecca Napolitano 2018년 5월 2일
I am using the function:
bwareaopen(Image, minPixels)
on the following image:
It should remove all of the objects in my binary image which are less than a specified number of pixels (minPixels). However, it seems to be consistently missing some that are smaller than that range. The following figure shows the original image and the one after bwareaopen() is applied.
The issues are the same for minPixel < 100000. It turns the image completely black expectedly at higher orders of magnitude.
Below is the code I am using. Thanks for any help!
image = imread('Gaussian.jpg'); % load in your image
binaryImage = im2bw(image, 0.5); % converts image to binary file
BW2 = bwareaopen(binaryImage, 150); % removes objects comprised of < 150 pixels
imshowpair(binaryImage, BW2, 'montage') % display both images to see if spots are removed
(Documentation for bwareaopen can be found at: https://www.mathworks.com/help/images/ref/bwareaopen.html)

채택된 답변

Rebecca Napolitano
Rebecca Napolitano 2018년 5월 2일
I figured I would post the answer since I figured it out. If I add the line
binaryImage = imcomplement(binaryImage)
in it inverts what is black and white and that works for this. It apparently wanted to have the objects be white and not black (?) which is a bit confusing to me, but it works now.
Full code:
image = imread('Gaussian.jpg'); % load in your image
binaryImage = im2bw(image, 0.5); % converts image to binary file
binaryImage = imcomplement(binaryImage) % inverts black and white
BW2 = bwareaopen(binaryImage, 150); % removes objects comprised of < 150 pixels
imshowpair(binaryImage, BW2, 'montage') % display both images to see if spots are removed

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by