The described method is used for generating a security document by applying a security pattern to an original image. The security pattern comprises a plurality of points, wherein each of said points represents a pattern value. Local averages are calculated from said pattern values for at least some areas of the security pattern. For at least some of the points of the security pattern the color of the corresponding point of the original image is replaced by a modified color. The modified color is a function of the local average, the original color and the corresponding pattern value. The method provides good security against counterfeit because it is difficult to implement using conventional image processing applications. For a suitable choice of the color transformation function, the resulting image can preserve the local color tones of the original image.