Image Filter art --- (Nostalgla Filter) old photo Filter,
Nostalgla Filter (Nostalgla Filter) The Nostalgla Filter is used to simulate a retro and outdated photo style, so as to display old photos in new photos. At present, there are many algorithms. This article introduces a new algorithm that is more realistic and more efficient: 1. Old photos generally have yellow paper features, we construct A dark-yellow floor layer A: RGB (200,120, 10); 2. The old photo also has crack characteristics. Of course, not all old photos do. Here we add crack features, the image is more vivid, so we can use PS to construct a crack template B, as shown in:3. Perform grayscale processing on the original photo C to obtain the grayscale image D. here we can use the simplest grayscale formula: Gray = (R + G + B)/3; 4, perform the soft-light operation on D and A. See Figure E. The soft-light algorithm is as follows: int ModeSmoothLight (int basePixel, int mixPixel) {int res = 0; res = mixPixel> 128? (Int) (float) basePixel + (float) mixPixel-255.0f) * (Math. sqrt (float) basePixel/255.0f) * 255.0f-(float) basePixel)/255.0f): (int) (float) basePixel + (float) mixPixel + (float) mixPixel-255.0f) * (float) basePixel-(float) basePixel * (float) basePixel/255.0f)/255.0f); return Math. min (255, Math. max (0, res);} 5. Perform a soft operation on E and B to get the final F. The above is the implementation of the algorithm of the old photo filter, and the algorithm is relatively simple, but the results are quite good! The core code is as follows: private Bitmap NostalglaFilterProcess (Bitmap src, Bitmap mask) {Bitmap dst = new Bitmap (src); int w = dst. width; int h = dst. height; BitmapData maskData = mask. lockBits (new Rectangle (0, 0, w, h), ImageLockMode. readWrite, PixelFormat. format32bppArgb); BitmapData srcData = dst. lockBits (new Rectangle (0, 0, w, h), ImageLockMode. readWrite, PixelFormat. format32bppArgb); byte * p = (byte *) srcData. scan0; byte * pMask = (byte *) maskData. scan0; int offset = srcData. stride-w * 4; int B = 10, g = 130, r = 200, gray = 0; for (int j = 0; j Source image Old Photo Filter Finally put a complete C # program DEMO: http://www.zealpixel.com/thread-69-1-1.html |
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.