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. how to display only red channel QImage using a QPixmap formed using RGB8 QImage?
Forum Updated to NodeBB v4.3 + New Features

how to display only red channel QImage using a QPixmap formed using RGB8 QImage?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 2.0k Views 2 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.
  • hardikgarg19H Offline
    hardikgarg19H Offline
    hardikgarg19
    wrote on last edited by
    #1

    Hello,
    I have RBG image frames coming form the camera. I have formed the RGB8 QImage and QPixmap from the QImage. I have to display only the Red channel image from this QPixmap. How can I do that?

    hardikgarg19H 1 Reply Last reply
    0
    • hardikgarg19H hardikgarg19

      Hello,
      I have RBG image frames coming form the camera. I have formed the RGB8 QImage and QPixmap from the QImage. I have to display only the Red channel image from this QPixmap. How can I do that?

      hardikgarg19H Offline
      hardikgarg19H Offline
      hardikgarg19
      wrote on last edited by
      #2

      @hardikgarg19 presently, I am doing it like below:

      for ( int row = 0; row <widthImg; ++row )
      {
      for ( int col = 0; col < heightImg; ++col )
      {
      QColor clrCurrent( imgEdge.pixel( row, col ) );
      //clrCurrent.setRed(255);
      clrCurrent.setBlue(0);
      clrCurrent.setGreen(0);
      imgEdge.setPixelColor(row,col,clrCurrent);
      }
      }
      Is there any other way to do it that saves some computation?

      1 Reply Last reply
      0
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        If RGB8 is indexed then you could modify the color map instead. Go and set all the G B values of colormap to 0. If its not indexed then doing each pixel is the best you can do I think.

        There might be a quicker way doing some kind of memory lookup and modifying 2 bytes our of every three. This would reduce function calls. However, you will need to determine how the memory is structured.

        C++ is a perfectly valid school of magic.

        hardikgarg19H 1 Reply Last reply
        0
        • fcarneyF fcarney

          If RGB8 is indexed then you could modify the color map instead. Go and set all the G B values of colormap to 0. If its not indexed then doing each pixel is the best you can do I think.

          There might be a quicker way doing some kind of memory lookup and modifying 2 bytes our of every three. This would reduce function calls. However, you will need to determine how the memory is structured.

          hardikgarg19H Offline
          hardikgarg19H Offline
          hardikgarg19
          wrote on last edited by
          #4

          @fcarney thank you for your reply. Can you please tell me how can I set the B and G to 0 for the color map without the for loop?

          1 Reply Last reply
          0
          • fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #5

            Is the image indexed? What is the format?

            C++ is a perfectly valid school of magic.

            hardikgarg19H 1 Reply Last reply
            0
            • fcarneyF fcarney

              Is the image indexed? What is the format?

              hardikgarg19H Offline
              hardikgarg19H Offline
              hardikgarg19
              wrote on last edited by
              #6

              @fcarney Please tell me what is "indexing" here?
              The format is RGB8 (QImage::Format_RGB888)

              1 Reply Last reply
              0
              • fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by
                #7

                It is not indexed:
                https://doc.qt.io/qt-5/qimage.html#Format-enum

                So you are stuck with looping through the data like you already figured out. The indexed format would have been: QImage::Format_Indexed8

                If you can get access to the memory itself (not sure how do to that) you could set the bytes in a loop that has less function calls. It would require pointer math.

                C++ is a perfectly valid school of magic.

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

                  Hi,

                  You can compose a new QImage using the QPainter::RasterOp_SourceAndNotDestination mode.

                  Create a fully red QImage of the same size of the frames you are getting, then compose it with your red frame and show the result. You should get what you want.

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

                  hardikgarg19H 1 Reply Last reply
                  1
                  • fcarneyF fcarney

                    It is not indexed:
                    https://doc.qt.io/qt-5/qimage.html#Format-enum

                    So you are stuck with looping through the data like you already figured out. The indexed format would have been: QImage::Format_Indexed8

                    If you can get access to the memory itself (not sure how do to that) you could set the bytes in a loop that has less function calls. It would require pointer math.

                    hardikgarg19H Offline
                    hardikgarg19H Offline
                    hardikgarg19
                    wrote on last edited by
                    #9

                    @fcarney pixel by pixel processing is bringing time lag in the video. So, I have included opecv library in the project and used the opencv function to extract the red channel.
                    Thank you

                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Hi,

                      You can compose a new QImage using the QPainter::RasterOp_SourceAndNotDestination mode.

                      Create a fully red QImage of the same size of the frames you are getting, then compose it with your red frame and show the result. You should get what you want.

                      hardikgarg19H Offline
                      hardikgarg19H Offline
                      hardikgarg19
                      wrote on last edited by
                      #10

                      @SGaist Hello,
                      Thank you for your reply. I will try this method.

                      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