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 dots in a black and white image

Subject: Fill dots in a black and white image

From: Aron Sceidt

Date: 3 Mar, 2011 15:34:05

Message: 1 of 3

Hi,

Is there an easy and fast way to fill missing pixels in an image. I'm not referring to the filling of holes.. Simply connecting pixels where there's only one connection (pixel) missing. For example imagine I have:

0 0 1 1 0 0
0 1 1 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0

should become:

0 0 1 1 0 0
0 1 1 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0

Basically I will use regionprops after to identify it as one island instead of two. I know I could use a 3 x 3 mask and "OR" with the image values to create a new image, however I'm not sure how to do that on matlab, and I'm not even sure if thats the cleanest way to do it... Any guide/help would be appreciated.

Thanks

Subject: Fill dots in a black and white image

From: ImageAnalyst

Date: 3 Mar, 2011 16:15:35

Message: 2 of 3

You could use imclose() however that also tends to smooth boundaries.
If you wanted to just fill in the center pixel of certain specific
patterns, like
1 0 0
0 0 0
0 0 1

1 0 0
0 0 0
0 1 0

1 0 0
0 0 1
0 0 0

and so on, then I think you'd have to check each of those cases with
imfilter. Just call imfilter once for whichever patterns you want to
change.
-ImageAnalyst

Subject: Fill dots in a black and white image

From: ImageAnalyst

Date: 3 Mar, 2011 16:18:25

Message: 3 of 3

Just to add...you could use bwmorph() with the 'bridge' option but it
also does a little smoothing/filling and won't be as accurate as if
you manage each and every pattern yourself with imfilter. However,
maybe what bridge does will be good enough for you and it will be
faster than calling imfilter a dozen or so times.

Tags for this Thread

No tags are associated with 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