Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Remove small objects from binary image without erode.

1,236 views
Skip to first unread message

Ironic Prata

unread,
Dec 15, 2009, 7:17:03 PM12/15/09
to

Is there a function that removes objects binary image based only on their pixel area?

I want to maintain lines, so erode or close is out of the question. Planning on using region props and check each area region, but that seems slow and inefficient...

Tks

Ironic Prata

unread,
Dec 15, 2009, 7:22:36 PM12/15/09
to

Ironic Prata

unread,
Dec 15, 2009, 7:26:04 PM12/15/09
to

ImageAnalyst

unread,
Dec 15, 2009, 8:35:59 PM12/15/09
to
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
You can use bwareaopen(). Despite the name it doesn't use a
morphological opening, but rather uses the regionprops method, that
you want to avoid. I don't know of any faster methods. Why do you
say it's slow? It doesn't seem slow when I use it - just takes a
fraction of a second. How large are your images, how many blobs are
in them, and how long is it taking on your computer? Maybe you can
get a faster computer.

Ironic Prata

unread,
Dec 15, 2009, 9:28:03 PM12/15/09
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <99896c54-e824-4fc6...@x20g2000vbn.googlegroups.com>...

the problem is that this is to be used in a loop, so i want efficiency.

but at least that function will clear up the code. tks

ImageAnalyst

unread,
Dec 15, 2009, 9:54:06 PM12/15/09
to
On Dec 15, 9:28 pm, "Ironic Prata" <lixodoiro...@hotmail.com> wrote:
> the problem is that this is to be used in a loop, so i want efficiency.
> but at least that function will clear up the code. tks
-------------------------------------------------------------------------------------------------
You're implying that the bwareaopen function is inefficient. What's
the basis for saying that? Do you have a more efficient method? Why
is this method too slow for you? Again, what kind of speed do you
require and what kind of speed are you getting?

Anh son

unread,
Dec 16, 2009, 10:12:07 AM12/16/09
to
"Ironic Prata" <lixodo...@hotmail.com> wrote in message <hg99es$1ou$1...@fred.mathworks.com>...

>
> Is there a function that removes objects binary image based only on their pixel area?
>
> I want to maintain lines, so erode or close is out of the question. Planning on using region props and check each area region, but that seems slow and inefficient...
>
> Tks

Is that what u need?

help bwareaopen
BWAREAOPEN Morphologically open binary image (remove small objects).

Hope that it helps.
Son

kinor

unread,
Dec 16, 2009, 12:41:03 PM12/16/09
to
"Ironic Prata" <lixodo...@hotmail.com> wrote in message <hg99es$1ou$1...@fred.mathworks.com>...
>
> Is there a function that removes objects binary image based only on their pixel area?
>
> I want to maintain lines, so erode or close is out of the question. Planning on using region props and check each area region, but that seems slow and inefficient...
>
> Tks

Hi,

help bwmorph
the option 'clean' is interesting if you want to remove single dots

if you want to remove larger i.e. 2 pixels and smaller objects you could convolute with a box mask i.e. ones(3) and delete everything below 2 in the result.

hth
kinor

Novae

unread,
Dec 18, 2009, 11:54:04 AM12/18/09
to
Hi

Other possibility, aside the suggestion made by ImageAnalyst, is to use a small median filter. You can "efficiently" apply it multiple times in a loop.

Igor

"Ironic Prata" <lixodo...@hotmail.com> wrote in message <hg98tv$2m$1...@fred.mathworks.com>...

Matthew Whitaker

unread,
Dec 21, 2009, 10:46:04 AM12/21/09
to
"Ironic Prata" <lixodo...@hotmail.com> wrote in message <hg998c$jbe$1...@fred.mathworks.com>...

>
> Is there a function that removes objects binary image based only on their pixel area?
>
> I want to maintain lines, so erode or close is out of the question. Planning on using region props and check each area region, but that seems slow and inefficient...
>
> Tks


In the image processing toolbox there is a use function called bwareaopen to do exactly this.

Hope this helps
Matt W

Simone

unread,
Apr 13, 2010, 10:00:26 AM4/13/10
to
"Ironic Prata" <lixodo...@hotmail.com> wrote in message <hg98tv$2m$1...@fred.mathworks.com>...

>
> Is there a function that removes objects binary image based only on their pixel area?
>
> I want to maintain lines, so erode or close is out of the question. Planning on using region props and check each area region, but that seems slow and inefficient...
>
> Tks

Like this:

stats = regionprops(binary, 'Area', 'PixelIdxList');
cleaned = binary;
for region = 1 : length(stats)
if stats(region).Area < MIN_AREA
cleaned(stats(region).PixelIdxList) = 0;
end
end

I can guarantee this is REALLY fast! ;)

saurabh pandey

unread,
Jul 10, 2010, 12:53:02 PM7/10/10
to
"kinor " <kinor.remov...@gmx.de> wrote in message <hgb63f$20c$1...@fred.mathworks.com>...

HOW CAN WE DO THIS?

us

unread,
Jul 10, 2010, 2:48:05 PM7/10/10
to
"saurabh pandey" <sathiya...@yahoo.co.in> wrote in message <i1a8he$jsu$1...@fred.mathworks.com>...

a hint:
- use REGIONPROPS to identify your small objects...
- then, remove them...

us

Image Analyst

unread,
Jul 10, 2010, 6:02:05 PM7/10/10
to
"Anh son" <paso...@yahoo.de> wrote in message <hgatc7$rh8$1...@fred.mathworks.com>...

> Is that what u need?
> help bwareaopen
> BWAREAOPEN Morphologically open binary image (remove small objects).
> Hope that it helps.
> Son
-------------------------------------------------------------------
I know that's what it's documentation says, but that's not the way it does it. If you look at the code for bwareaopen, it essentially labels the objects and calculates the number of pixels in each object, then it removes objects with less than the prescribed number of objects. It does not do it by doing a morphological opening (which would not retain the exact shapes of the original blobs), nor does it do it by a morphological erosion followed by a morphological reconstruction (which would retain shapes). This latter way is one way to do it so I guess that the labeling way must be faster most of the time. Maybe it used to be done via morphological opening but they changed when they realized that way would change the shape of the retained blobs, hence the "open" in the name. I'm not sure why they didn't correct the documentation to reflect the actual way it appears to be done. The
way bwareaopen actually works is essentially like what us said - it labels, regionprops, and then filters based on size (you can use ismember() for this). In fact if you're going to eventually label and call regionprops, you woudn't want to call bwareopen, because then you'd be doing the labeling twice.

Raka kundu

unread,
May 22, 2012, 5:22:06 AM5/22/12
to
"Anh son" wrote in message <hgatc7$rh8$1...@fred.mathworks.com>...
Yes the function bwareaopen is working well for removing small objects from binary image. But, I am in need of the algorithm of bwareaopen.

Raka
mail id: kundu...@gmail.com
0 new messages