IMAGE Team - The Pantheon project

Tutorial: Removing Moiré Pattern From Scanned Photos



I. Objective

The objective is to reduce the moiré effect that appears in scans of photos. A moiré pattern is an interference pattern created by two grids with different frequency. This phenomenon occurs particularly when scanning photos from printed matter such as postcards, book illustrations, newspaper or magazine images. It produces a uniform periodic texture on the whole image. It is caused by the fact that a photo is printed as a series of dots at a certain frequency and the scanner captures the photo as a series of pixels at another sampling frequency. Sometimes there is a perfect matching between the image dots and the sampling dots, and sometimes there is a shift between the dots, and this happens at a regular frequency.

The goal is to detect the frequency peaks that correspond to the moiré pattern and remove them without modifying the significant information.

The initial image.The result image.

II. Method

A simple method to remove the moiré pattern is to use a Gaussian blur filter (operator pgaussianfiltering in Pandore).

The method described here is more sophisticated. It is based on the elimination of the most important peaks of frequency in the Fourier transform of the initial image. Because the moiré is quite strong in the images, it is characterized by important peaks in the frequency domain.

The method is composed of four steps:

  1. Transformation of the image into the Fourier frequency domain.
  2. Detection of the frequency peaks.
  3. Elimination of the frequency peaks.
  4. Inverse Fourier transformation to get back to the spatial domain.

Note that for color images, this plan should be applied band per band.

II.1 Fourier Transform

The transformation is straightforward. We are only interested by the modulus of the Fourier transform.

pany2pan input.png input.pan
psetcst 0 input.pan tmp1.pan
pfft input.pan tmp1.pan real.pan imag.pan

pfftshift real.pan imag.pan tmp2.pan tmp3.pan
pmodulus tmp2.pan tmp3.pan modulus.pan
logtransform 0 0 255 modulus.pan mod.pan
mod.pan: The Fourier transform modulus.

II.2 Detection of Frequency Peaks

The detection of the frequency peaks is done by a white top-hat followed by a binarization. Beforehand, a median smoothing removes two small isolated peaks.

The white top-hat corresponds to the difference between an image and its opening:

WTH(f) = f - δ(ε(f))

The threshold value of the binarization is determined as the gray level value that maximizes the total amount of information provided by the background and the foreground separately. The amount of information is measured by entropy.

pmedianfiltering 3 mod.pan mod.pan

perosion 1 8 mod.pan tmp4.pan
pdilatation 1 8 tmp4.pan tmp5.pan
pdif tmp5.pan mod.pan wth.pan

pentropybinarization wth.pan freq.pan
freq.pan: The detect peaks.

II.3 Removal of Frequency Peaks

Removing the peaks is done by masking the peaks detected in the Fourier transform image. Only the peaks located along the abscissa and ordinate axis are kept. For this, we create an artificial binary image with a white cross.

pshapedesign 1024 512 0 3 23 1024 horiz.pan
pshapedesign 1024 512 0 3 512 12 vertic.pan
por horiz.pan vertic.pan mask1.pan
pinverse mask1.pan mask1.pan

pmask freq.pan mask1.pan mask.pan
mask1.pan: The mask used to remove peaks.
mask.pan: The peaks to be removed.

II.4 Inverse Fourier Transform

Once the mask image is constructed, the real and imaginary parts of the Fourier image are masked. Finally, the inverse Fourier yields the result image in the spatial domain.

# Masking (inversion and shift)
pinverse tmp6.pan tmp6.pan
pfftshift tmp6.pan tmp6.pan tmp7.pan tmp8.pan
pmask real.pan tmp7.pan tmp9.pan
pmask imag.pan tmp8.pan tmp10.pan

# Inverse Fourier transform
pifft tmp9.pan tmp10.pan tmp11.pan tmp12.pan
plineartransform 0 0 255 tmp11.pan tmp13.pan
pim2uc tmp13.pan output.pan
ppan2png output.pan output.png
output.pan: The result.

The Complete Pandore Script (bash)

The Pantheon project
Image Team GREYC Laboratory
UMR CNRS 6072 - ENSICAEN - University of Caen, France
This page was last modified on 14 November 2013