Essentials of Mechatronics  ISBN: 0-471-72341-X- ©John Billingsley 2006 - published John Wiley & Sons, Inc

12/3/2.htm  Binary image smoothing

A roughly diamond-shaped patch is set up.
It really is rough, since the edges have been 'chewed' by random numbers.
Some cells contain the value 0, which we will display as black,
while others contain 1 and are displayed in red.

The routine 'smooth' simply adds up the red pixels in a 3 x 3 box
and sets the center corresponding pixel to 'red' if the total is greater than 4,
to black otherwise.

This routine is applied pixel-by-pixel over the whole image and then the second array is displayed.

Look at the listing.  You can click the button to run the program.

Try making a few edits to gain familiarity.

Run smoothbin.bas or smoothbin.htm