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.
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:
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")/>