Converting QImage data from RGB to luminance



  • Are there methods to convert RGB data (that which is passed to QImage constructor) to that of luminance (YUV) values?


  • Lifetime Qt Champion

    Hi,

    AFAIK, QImage doesn't work in the YUV colorspace, however you could use a library like e.g. OpenCV for that



  • [quote author="SGaist" date="1414483275"]Hi,

    AFAIK, QImage doesn't work in the YUV colorspace, however you could use a library like e.g. OpenCV for that[/quote]

    I could have used libVLC too. I posted here becuase I wanted to keep it within Qt only.

    Thanks anyway. I thought it might have been possible.

    However, perhaps taking the rgb data thats passed to QImage can be converted to luminance beforehand. Hopefully someone's done that already


  • Lifetime Qt Champion

    If it's just a question of color space conversion you should be able to do it yourself pixel by pixel.



  • This is where I've gone with this:

    @
    void Worker::run()
    {
    QImage image;
    marker markerFound;

    const double rY = 0.299, gY = 0.587, bY = 0.114;
    
    ProcessFrames();
    
    if (bitCount == 32)
        image = QImage(imageAverage, imageWidth, imageHeight, QImage::Format_RGB32);
    
    else
        image = QImage(imageAverage, imageWidth, imageHeight, QImage::Format_RGB888);
    
        QVector<marker>MarkerMap(0);
    
        for (int y = 0; y < imageHeight; ++y)
        {
            for (int x = 0; x < imageWidth; ++x)
            {
                int Sum = 0;
                int Y = 0;
    
                Y = (int)(imageAverage[(y * imageStride) + byteCount * x + 0] & 0xff) * rY +
                    (int)(imageAverage[(y * imageStride) + byteCount * x + 1] & 0xff) * gY +
                    (int)(imageAverage[(y * imageStride) + byteCount * x + 2] & 0xff) * bY;
    
    
                for (int c = 0; c < 3; ++c) //c = color i.e. RGB so 3 colors.
                    Sum += imageAverage[(y * imageStride) + byteCount * x + c]; //We have a 3 color pixel value for testing.
    
                if (Sum <= thresholdValue)  // Map it or go check the next.
                    continue;
    
                markerFound.x = x;          // Mapping it.
                markerFound.y = y;
                markerFound.intensity = Y;
    
                MarkerMap.append(markerFound);
            }
        }
    

    }
    @


  • Lifetime Qt Champion

    Thanks for sharing !


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.