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. Superposition of two images
Forum Updated to NodeBB v4.3 + New Features

Superposition of two images

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.6k 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.
  • Z Offline
    Z Offline
    Zhitoune
    wrote on last edited by
    #1

    Dear all,

    I'm facing a problem in my soft, I'm superposing two image coming from a video stream :

                *leftImg = im.copy(0, 0, 512/2, 512);
                leftImg->setColorTable(redTable);
                *rightImg = im.copy( 256, 0, 512/2,  512);
                rightImg->setColorTable(greenTable);
                QPainter painter(dualViewImg);
                painter.drawImage(0, 0, *leftImg);
                painter.setCompositionMode(QPainter::CompositionMode_Overlay);
                painter.drawImage(0, 0, *rightImg);
                display->setPixmap(QPixmap::fromImage(dualViewImg->scaled(Xmaxi/2, Ymaxi)));
    

    The superposition is working, but I would like to assign a spécific color to each image in order to make the comparison of the images easie. to do that I assign a red or green colortable to each image :

    QVector<QRgb> redTable (256);
        QVector<QRgb> greenTable (256);
        for (int i = 0 ; i < 255; i++)
        {
            redTable[i] = qRgb(i, 0, 0);
            greenTable[i] = qRgb(0, i, 0);
        }
    

    but it's not working the resulting image is still gray. What did I miss?
    thanks in advance for your help.

    ValentinMicheletV 1 Reply Last reply
    0
    • Z Zhitoune

      Dear all,

      I'm facing a problem in my soft, I'm superposing two image coming from a video stream :

                  *leftImg = im.copy(0, 0, 512/2, 512);
                  leftImg->setColorTable(redTable);
                  *rightImg = im.copy( 256, 0, 512/2,  512);
                  rightImg->setColorTable(greenTable);
                  QPainter painter(dualViewImg);
                  painter.drawImage(0, 0, *leftImg);
                  painter.setCompositionMode(QPainter::CompositionMode_Overlay);
                  painter.drawImage(0, 0, *rightImg);
                  display->setPixmap(QPixmap::fromImage(dualViewImg->scaled(Xmaxi/2, Ymaxi)));
      

      The superposition is working, but I would like to assign a spécific color to each image in order to make the comparison of the images easie. to do that I assign a red or green colortable to each image :

      QVector<QRgb> redTable (256);
          QVector<QRgb> greenTable (256);
          for (int i = 0 ; i < 255; i++)
          {
              redTable[i] = qRgb(i, 0, 0);
              greenTable[i] = qRgb(0, i, 0);
          }
      

      but it's not working the resulting image is still gray. What did I miss?
      thanks in advance for your help.

      ValentinMicheletV Offline
      ValentinMicheletV Offline
      ValentinMichelet
      wrote on last edited by ValentinMichelet
      #2

      Hi,

      Not sure if it's important, but your for loop will assign 255 values instead of 256.

      QVector<QRgb> redTable (256);
      QVector<QRgb> greenTable (256);
      for (int i = 0 ; i < 256; i++)
      {
          redTable[i] = qRgb(i, 0, 0);
          greenTable[i] = qRgb(0, i, 0);
      }
      

      That being said, I don't really understand what you are trying to achieve here.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zhitoune
        wrote on last edited by
        #3

        Sorry I didnot explain very well my problem. But it can be summed up to :
        How do I transform a monochromatic QImage into a colored one?

        mrjjM 1 Reply Last reply
        0
        • Z Zhitoune

          Sorry I didnot explain very well my problem. But it can be summed up to :
          How do I transform a monochromatic QImage into a colored one?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Zhitoune said:

          setColorTable

          Are you sure it uses a color table?
          Before you do ->setColorTable, what does
          QImage::colorCount()
          return?
          For leftImg

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zhitoune
            wrote on last edited by
            #5

            It returns 0. I have check my images format is RGB16.
            there is always the options to rewritte a new image like this :

            for (int i = 0 ; i <resX ; i++)
            {
                 for (int j = 0 ; j <resY ; j++)
                 {
                     newQImage.setPixel(i, j, qRgb (leftImg.pixel(i, j).red(), 0, 0)
                 }
            }
            but I fear it to be too much time consuming..
                   
            
            
            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Well it seems not to use palette for that format.
              So only option is to rewrite pixels as far I can see.
              At least all samples do that.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                chaiFF
                wrote on last edited by chaiFF
                #7

                I know that this post is pretty old but I think I found what is wrong! setColorTable only works for monochrome and 8-bit formats!! So the picture has to be transformed first :) I personally used
                image->convertToFormat(QImage::Format_Indexed8,redTable) and It worked!!

                1 Reply Last reply
                1

                • Login

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