HTML5 Canvas image contrast

前端 未结 7 1355
情书的邮戳
情书的邮戳 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:06

    You can take a look at the OpenCV docs to see how you could accomplish this: Brightness and contrast adjustments.

    Then there's the demo code:

     double alpha; // Simple contrast control: value [1.0-3.0]
     int beta;     // Simple brightness control: value [0-100]
    
     for( int y = 0; y < image.rows; y++ )
     { 
          for( int x = 0; x < image.cols; x++ )
          { 
              for( int c = 0; c < 3; c++ )
              {
                  new_image.at(y,x)[c] = saturate_cast( alpha*( image.at(y,x)[c] ) + beta );
              }
          }
     }
    

    which I imagine you are capable of translating to javascript.

提交回复
热议问题