'Apply simplex noise to image with ffmpeg

Is there any way to apply simplex noise on image with ffmpeg?

Implementation in JavaScript

export function addGrain(out, image, slice, scale, intensity){
    let simplex = new SimplexNoise(new Alea());
    let od = out.data,
        id = image.data,
        w = image.width,
        h = image.height,
        ox = slice.x,
        oy = slice.y,
        d = Math.min(slice.width, slice.height);

    for(var y = 0; y < h; y++) {
        for(var x = 0; x < w; x++) {
            // reduce noise in shadows and highlights, 4 = no noise in pure black and white
            let i = (y*w+x)*4,
                l = (id[i]+id[i+1]+id[i+2])/768-0.5,
                rx = x + ox,
                ry = y + oy,
                noise = (simplex.noise2D(rx/d*scale, ry/d*scale) +
                         simplex.noise2D(rx/d*scale/2, ry/d*scale/2)*0.25 +
                         simplex.noise2D(rx/d*scale/4, ry/d*scale/4))*0.5;
            // reduce noise in shadows and highlights, 4 = no noise in pure black and white
            noise *= (1-l*l*2);
            noise *= intensity*255;
            od[i] = id[i]+noise; // R
            od[i+1] = id[i+1]+noise; // G
            od[i+2] = id[i+2]+noise; // B
        }
    }
}

I've idea to do it with generic equation on each pixel geq but i need to get simplex noise value that is calculated from pixel's X and Y

Resources



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source