Filmgrainer is an image processing algorithm that adds noise to an image resembling photographic film grain. It's implemented in Python and runs as a command line utility on Linux platforms, installable with pip.
Check out the github project which includes installation instructions and other examples than shown here.
Adding a bit of film grain can be used for artistic effect and to mask imperfections. Images taken by smartphones sometimes have an overprocessed, plastic look with unaturally smooth surfaces. Adding film grain can make such images look more interesting.
Another use case is to process deep learning AI generated images, eg. by Stable Diffusion, to make them look more like real photographs.
This picture was taken by a smartphone as light starts to dim in the evening. It has a processed, plasticy look:
Processed with filmgrainer it gets a totally different character and looks like a photograph from another age:
filmgrainer --type 3 --gray --power 1,0.2,0.1
Harsh black and white photographic grain suits the character of this picture:
filmgrainer --type 3 --gray --gamma 1.1 --power 0.8,0.1,0.2
This strangely orange sky looks great with a bit of dias like film grain:
filmgrainer --type 1 --sat 0.5 --power 0.8,0.1,0.3
Mountains and sky
This picture got better by blending in more grain in the shadows and raising the gamma slightly. The result looks like in a pleasent negative film photograph:
filmgrainer --type 1 --sat 0.8 --gamma 1.1 --power 0.8,0.2,0.5
The algorithm works by generating a grain base image and blending it with the image. The grain base is made with gaussian random value pixels rescaled to achieve a certain grain size. The rescaling also makes the random pixels fuse together slightly, making them look more like actual grain. A configurable level of color noise can be added to the grain base.
The blending of the grain and the image can be adjusted in intensity for highlights and shadows. Statistical analysis of real photographs was done and used for developing the blending profile.
This is the output of
filmgrainer -h version v1.0.2:
Usage: filmgrainer [OPTION] [OPTION] ... INPUTFILE Options: -------- --gamma <gamma> Gamma compensate input, default: 1.0 --gray Grayscale mode --type <type> Grain type: 1: fine, 2: fine simple, 3: coarse, 4: coarser --sat <saturation> Grain color saturation, 0.0 to 1.0 --power <overall>,<highlights>,<shadows> Grain power: overall, highlights, shadows --scale <ratio> Scaling, default 1.0. This will scale the image before applying grain and scale back to original size afterwards for an increase in grain size. --sharpen <passes> Sharpen output, passes, default: 0 --seed <number> Seed for grain random generator -o <output-filename> Set output filename -h Show this help --version Show version
I hope you enjoyed this content!
Comments powered by Talkyard