Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Fill the Black Holes in Binary Images

Subject: Fill the Black Holes in Binary Images

From: Nehal

Date: 4 Oct, 2010 04:17:04

Message: 1 of 9

I have 2 images:
image 01: http://img522.imageshack.us/img522/2738/s10001069.jpg
image 02: http://img838.imageshack.us/img838/7077/s10003002.jpg

image 01 has a big black hole because I have taken the image in this way. But image 02 has a smaller hole (on the palm of the hand) which was not suppose to be here. Now I want to close the hole with some closing operations (for example morphological operation). I used "BW2 = IMFILL(bwImageArray,'holes')" function on both the images in general. But it closes the big hole in image 01 too. Which I do not want.

I think I need to define the area of the black region to be closed/filled that only the smaller black regions will be filled, not the larger regions.
Or with some other methods.

Can anyone help..?

Subject: Fill the Black Holes in Binary Images

From: Avi

Date: 4 Oct, 2010 08:07:06

Message: 2 of 9

"Nehal " <arnab620@yahoo.com> wrote in message <i8bkg0$l8t$1@fred.mathworks.com>...
> I have 2 images:
> image 01: http://img522.imageshack.us/img522/2738/s10001069.jpg
> image 02: http://img838.imageshack.us/img838/7077/s10003002.jpg
>
> image 01 has a big black hole because I have taken the image in this way. But image 02 has a smaller hole (on the palm of the hand) which was not suppose to be here. Now I want to close the hole with some closing operations (for example morphological operation). I used "BW2 = IMFILL(bwImageArray,'holes')" function on both the images in general. But it closes the big hole in image 01 too. Which I do not want.
>
> I think I need to define the area of the black region to be closed/filled that only the smaller black regions will be filled, not the larger regions.
> Or with some other methods.
>
> Can anyone help..?

try use regionprops and identify holes the find the cordinate of pixels of holes and by criterion of area or radius fill the the pixels by ste imh(i,j)=1 in the find of result from regionprops

Subject: Fill the Black Holes in Binary Images

From: Nehal

Date: 4 Oct, 2010 16:05:22

Message: 3 of 9

"Avi " <michaels@dsit.co.il> wrote in message <i8c1va$n9t$1@fred.mathworks.com>...
> "Nehal " <arnab620@yahoo.com> wrote in message <i8bkg0$l8t$1@fred.mathworks.com>...
> > I have 2 images:
> > image 01: http://img522.imageshack.us/img522/2738/s10001069.jpg
> > image 02: http://img838.imageshack.us/img838/7077/s10003002.jpg
> >
> > image 01 has a big black hole because I have taken the image in this way. But image 02 has a smaller hole (on the palm of the hand) which was not suppose to be here. Now I want to close the hole with some closing operations (for example morphological operation). I used "BW2 = IMFILL(bwImageArray,'holes')" function on both the images in general. But it closes the big hole in image 01 too. Which I do not want.
> >
> > I think I need to define the area of the black region to be closed/filled that only the smaller black regions will be filled, not the larger regions.
> > Or with some other methods.
> >
> > Can anyone help..?
>

could you plz explain it.. actually I am not that expert..
> try use regionprops and identify holes the find the cordinate of pixels of holes and by criterion of area or radius fill the the pixels by ste imh(i,j)=1 in the find of result from regionprops

Subject: Fill the Black Holes in Binary Images

From: Sean

Date: 4 Oct, 2010 16:17:05

Message: 4 of 9

"Nehal " <arnab620@yahoo.com> wrote in message <i8bkg0$l8t$1@fred.mathworks.com>...
> I have 2 images:
> image 01: http://img522.imageshack.us/img522/2738/s10001069.jpg
> image 02: http://img838.imageshack.us/img838/7077/s10003002.jpg
>
> image 01 has a big black hole because I have taken the image in this way. But image 02 has a smaller hole (on the palm of the hand) which was not suppose to be here. Now I want to close the hole with some closing operations (for example morphological operation). I used "BW2 = IMFILL(bwImageArray,'holes')" function on both the images in general. But it closes the big hole in image 01 too. Which I do not want.
>
> I think I need to define the area of the black region to be closed/filled that only the smaller black regions will be filled, not the larger regions.
> Or with some other methods.
>
> Can anyone help..?


Iinv = ~I; %Invert your binary image
Iinv = bwareaopen(Iinv,your_min_hole_size); %Get rid of small areas (below your size criterion)
I = ~Inv; %Invert back

Subject: Fill the Black Holes in Binary Images

From: Nehal

Date: 4 Oct, 2010 16:20:31

Message: 5 of 9

"Avi " <michaels@dsit.co.il> wrote in message <i8c1va$n9t$1@fred.mathworks.com>...
> "Nehal " <arnab620@yahoo.com> wrote in message <i8bkg0$l8t$1@fred.mathworks.com>...
> > I have 2 images:
> > image 01: http://img522.imageshack.us/img522/2738/s10001069.jpg
> > image 02: http://img838.imageshack.us/img838/7077/s10003002.jpg
> >
> > image 01 has a big black hole because I have taken the image in this way. But image 02 has a smaller hole (on the palm of the hand) which was not suppose to be here. Now I want to close the hole with some closing operations (for example morphological operation). I used "BW2 = IMFILL(bwImageArray,'holes')" function on both the images in general. But it closes the big hole in image 01 too. Which I do not want.
> >
> > I think I need to define the area of the black region to be closed/filled that only the smaller black regions will be filled, not the larger regions.
> > Or with some other methods.
> >
> > Can anyone help..?
>
> try use regionprops and identify holes the find the cordinate of pixels of holes and by criterion of area or radius fill the the pixels by ste imh(i,j)=1 in the find of result from regionprops

could you plz explain it.. actually I am not that expert..

Subject: Fill the Black Holes in Binary Images

From: Sean

Date: 4 Oct, 2010 16:24:05

Message: 6 of 9


> Iinv = ~I; %Invert your binary image
> Iinv = bwareaopen(Iinv,your_min_hole_size); %Get rid of small areas (below your size criterion)
> I = ~Inv; %Invert back

And of course you could one-line that:
I = ~bwareaopen(~I,your_min_hole_size);

Subject: Fill the Black Holes in Binary Images

From: Nehal

Date: 5 Oct, 2010 05:14:05

Message: 7 of 9

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i8cv35$fk5$1@fred.mathworks.com>...
>
> > Iinv = ~I; %Invert your binary image
> > Iinv = bwareaopen(Iinv,your_min_hole_size); %Get rid of small areas (below your size criterion)
> > I = ~Inv; %Invert back
>
> And of course you could one-line that:
> I = ~bwareaopen(~I,your_min_hole_size);

could you plz tell me how to define "your_min_hole_size" .. ?

Subject: Fill the Black Holes in Binary Images

From: Rolf

Date: 5 Oct, 2010 07:51:11

Message: 8 of 9

"Nehal " <arnab620@yahoo.com> wrote in message <i8ec6t$89q$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i8cv35$fk5$1@fred.mathworks.com>...
> >
> > > Iinv = ~I; %Invert your binary image
> > > Iinv = bwareaopen(Iinv,your_min_hole_size); %Get rid of small areas (below your size criterion)
> > > I = ~Inv; %Invert back
> >
> > And of course you could one-line that:
> > I = ~bwareaopen(~I,your_min_hole_size);
>
> could you plz tell me how to define "your_min_hole_size" .. ?

Just determine that for yourself, which holes are intentional and which are not?
Or maybe better, read the help on bwareaopen.
Gives a perfect example for you.

Subject: Fill the Black Holes in Binary Images

From: Nehal

Date: 21 Oct, 2010 16:02:04

Message: 9 of 9

"Rolf " <r.vermeer@student.utwente.nl> wrote in message <i8eldf$r3g$1@fred.mathworks.com>...
> "Nehal " <arnab620@yahoo.com> wrote in message <i8ec6t$89q$1@fred.mathworks.com>...
> > "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i8cv35$fk5$1@fred.mathworks.com>...
> > >
> > > > Iinv = ~I; %Invert your binary image
> > > > Iinv = bwareaopen(Iinv,your_min_hole_size); %Get rid of small areas (below your size criterion)
> > > > I = ~Inv; %Invert back
> > >
> > > And of course you could one-line that:
> > > I = ~bwareaopen(~I,your_min_hole_size);
> >
> > could you plz tell me how to define "your_min_hole_size" .. ?
>
> Just determine that for yourself, which holes are intentional and which are not?
> Or maybe better, read the help on bwareaopen.
> Gives a perfect example for you.

thank you very much.. it worked... :)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us