HTML5 Canvas image contrast

前端 未结 7 1360
情书的邮戳
情书的邮戳 2020-12-13 04:51

I\'ve been writing an image processing program which applies effects through HTML5 canvas pixel processing. I\'ve achieved Thresholding, Vintaging, and ColorGradient pixel m

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 05:23

    After trying the answer by Schahriar SaffarShargh, it wasn't behaving like contrast should behave. I finally came across this algorithm, and it works like a charm!

    For additional information about the algorithm, read this article and it's comments section.

    function contrastImage(imageData, contrast) {
    
        var data = imageData.data;
        var factor = (259 * (contrast + 255)) / (255 * (259 - contrast));
    
        for(var i=0;i

    Usage:

    var newImageData = contrastImage(imageData, 30);
    

    Hopefully this will be a time-saver for someone. Cheers!

提交回复
热议问题