Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Converting QImage data from RGB to luminance
Qt 6.11 is out! See what's new in the release blog

Converting QImage data from RGB to luminance

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 5.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    astodolski
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        astodolski
        wrote on last edited by
        #3

        [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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            astodolski
            wrote on last edited by
            #5

            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);
                    }
                }
            

            }
            @

            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Thanks for sharing !

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved