The amazing adventures of Doug Hughes

I received an email today from an Image Component user. This person works for a museum in New York and was working on a project apparently related to making archived digital pictures available online. Many of their pictures were scanned from printed materials and, unfortunately, had a very strong moir pattern. When the image was scaled down using the Image Component the pattern became very apparent.

For those of you that don’t know what a moir pattern is, it’s a funny, repeating pattern you get when you scan printed images. This comes from the fact that printed images are made up of tiny little dots, similar to pixels, but a different pattern.

When you scan these images, the translation from the offset dot pattern to a computer pixel system creates a very obvious pattern in the image. When you scale the image down this pattern usually becomes even more apparent.

For more information, visit this link: http://www.scantips.com/basics06.html .

Most scanners have a setting called “descreen” which applies an algorithm which removes this pattern when you’re doing the scan. This is the best time to fix these types of problems. Unfortunately, the images the museum was working with had no been descreened and the resulting scaled images were not pretty.

Here’s an example with the moir pattern. The image is obviously of very poor quality.

Moire Example

If you’re working in some software like Photoshop, there are techniques you can apply to reduce this effect. Generally, this is to have an image two to three times the size you need the image to be. You then apply a median filter of two or three pixels, scale the image to the target size, then apply an unsharp mask.

The Image Component isn’t exactly as powerful as photoshop. However, the purpose really is to average a set of 4 or 6 pixels so they are roughly the same color. Then, scale them down and their resampled pixels should end up the correct color. So, before rescaling the image I applied a 3-pixel blur. (The AIC has an annoying feature where blurred images get a black border around them. To prevent that I increased the image canvas size before burring then cropped it back out.) I then re-read the unaltered image and drew it back over the blurred version at 30% transparency. The purpose of this was to bring some sharpness back into the image.

Finally, I resized the image to the target size. This process did a pretty good job of lessening the moir effect. It’s not gone, but it’s a lot better than it was. Here’s the result with this technique applied:

Moire Thumbnail

The code I wrote is as follows. (You’ll need the Image Component to do this. Download it here .)

<cfset myImage=CreateObject("Component", "Image")/>
<cfset myImage.readImage(expandPath("moire.jpg"))/>

<!--- increase the size of the canvas by the number of pixels we're going to blur * 2 --->
<cfset myImage.setImageSize(myImage.getWidth() + 6, myImage.getHeight() + 6, "middleCenter")/>

<!--- blur the image --->
<cfset myImage.blur(2,2)/>

<!--- crop the image down to the old size --->
<cfset myImage.setImageSize(myImage.getWidth() - 6, myImage.getHeight() - 6, "middleCenter")/>

<!--- read the original image and write it overtop of the current image at 30% transparency --->
<cfset myImage.setTransparency(20)/>
<cfset myImage.drawImage(expandPath("moire.jpg"), 0, 0)/>

<!--- lastly, scale --->
<cfset myImage.scaleToFit(257)/>
<cfset myImage.writeImage(expandPath("thumbnail.jpg"), "jpg")/>

Cool, eh?

Comments on: "Lessen Moire Patterns in Scanned Images With the Alagad Image Component" (2)

  1. Ah… attack of the CFSETs! CFSCRIPT is your friend… get to know him. ๐Ÿ™‚

    Like

  2. Doug Hughes said:

    You like cfscript, I like cfset. ๐Ÿ™‚

    Like

Comments are closed.

Tag Cloud

%d bloggers like this: