Ask Your Question

Revision history [back]

I developed a function that retrieves a measure of brightness in an image, using the RGB color channels to get a measure of image luminance (which I got here )

void _getBrightness(const Mat& frame, double& brightness)
    {
        Mat temp, color[3], lum;
        temp = frame;

        split(temp, color);

        color[0] = color[0] * 0.299;
        color[1] = color[1] * 0.587;
        color[2] = color[2] * 0.114;


        lum = color[0] + color [1] + color[2];

        Scalar summ = sum(lum);


        brightness = summ[0]/((2^8-1)*frame.rows * frame.cols) * 2; //-- percentage conversion factor

The last operation is a conversion factor to percentage. (2^8-1) means the Mat is 8-bit, if your working with 32 bit the conversion factor has to be ((2^32-1)*frame.rows * frame.cols) * 2

I developed a function that retrieves a measure of brightness in an image, using the RGB color channels to get a measure of image luminance (which I got here )

 void _getBrightness(const Mat& frame, double& brightness)
     {
         Mat temp, color[3], lum;
         temp = frame;

         split(temp, color);

         color[0] = color[0] * 0.299;
         color[1] = color[1] * 0.587;
         color[2] = color[2] * 0.114;


         lum = color[0] + color [1] + color[2];

         Scalar summ = sum(lum);


         brightness = summ[0]/((2^8-1)*frame.rows * frame.cols) * 2; //-- percentage conversion factor
         }

The last operation is a conversion factor to percentage. (2^8-1) means the Mat is 8-bit, if your working with 32 bit the conversion factor has to be ((2^32-1)*frame.rows * frame.cols) * 2

I developed a function that retrieves a measure of brightness in an image, using the RGB color channels to get a measure of image luminance (which I got here )

    void _getBrightness(const Mat& frame, double& brightness)
        {
            Mat temp, color[3], lum;
            temp = frame;

            split(temp, color);

            color[0] = color[0] * 0.299;
            color[1] = color[1] * 0.587;
            color[2] = color[2] * 0.114;


            lum = color[0] + color [1] + color[2];

            Scalar summ = sum(lum);


            brightness = summ[0]/((2^8-1)*frame.rows summ[0]/((pow(2,8)-1)*frame.rows * frame.cols) * 2; //-- percentage conversion factor
         }

The last operation is a conversion factor to percentage. (2^8-1) means the Mat is 8-bit, if your working with 32 bit the conversion factor has to be ((2^32-1)*frame.rows * frame.cols) * 2

I developed a function that retrieves a measure of brightness in an image, using the RGB color channels to get a measure of image luminance (which I got here )

    void _getBrightness(const Mat& frame, double& brightness)
        {
            Mat temp, color[3], lum;
            temp = frame;

            split(temp, color);

            color[0] = color[0] * 0.299;
            color[1] = color[1] * 0.587;
            color[2] = color[2] * 0.114;


            lum = color[0] + color [1] + color[2];

            Scalar summ = sum(lum);


            brightness = summ[0]/((pow(2,8)-1)*frame.rows * frame.cols) * 2; //-- percentage conversion factor
         }

The last operation is a conversion factor to percentage. (2^8-1) pow(2,8) means the Mat is 8-bit, if your working with 32 bit the conversion factor has to be ((2^32-1)*frame.rows ((pow(2,32)-1)*frame.rows * frame.cols) * 2