NYCJUG/2010-03-09/DeSpeckleImage
Skip Cave describes an algorithm to "de-speckle" an image.
from Skip Cave <skip@caveconsulting.com> date Mon, Feb 15, 2010 at 10:03 AM
In the mid 70's I wrote an APL function to threshold and de-speckle grayscale images from a handheld video camera, which was used to read the price tags on store merchandise (OCR Wand). The algorithm was eventually coded in assembly, and implemented in the commercial product. This was before barcodes became common.
The thresholding algorithm looked at the surrounding cells of each pixel (usually a 3x3 , 5x5, or 7x7 square depending on the character and line resolution), and did several steps.
1) It turned the pixel black if the pixel was significantly darker than the average of all the local pixels (part of a character)
2) It turned the pixel white if the pixel was significantly lighter than the average of all the local pixels (not part of a character)
3) It turned the pixel white if there were few surrounding dark pixels (fly speck)
I found that looking at local averages for pixel decisions worked better than thresholding by looking at the overall average of the whole image, since gradual shading across the image could throw off the thresholding process. I don't have the APL code anymore (it was developed on a IBM Selectric typewriter with an acoustic coupler). However the J version of Conway's Game of Life uses a very similar scheme, looking at the cells surrounding a specific cell, to make a decision on that cell's state.
Cliff Reiter has his Life code at: http://ww2.lafayette.edu/~reiterc/j/vector/vlife2.html
Skip Cave