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. Merge Two Images

Merge Two Images

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 3.0k Views
  • 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.
  • B Offline
    B Offline
    beecksche
    wrote on 29 Jun 2019, 06:09 last edited by beecksche
    #1

    Hi,
    my code generate two quadaratic grayscale images. The background is white. In the first image an object is in the center, in the second picture the object is shifted horizontally, as you can see in the figures below.

    First Image Second Image
    1_1561787748362_i2.jpg 0_1561787748361_i1.jpg

    I want to merge these images, so that the second image lies over the first. But with the result that you still see the object from the first image as shown below.

    Merged Image:

    2_1561787748362_i3.jpg

    Unfortunately, I'm not able to generate the merged image. So I have to merge the two images.

    I tried the following:

    QImage image1; // converted from the grayscale image to ARGB32 format
    QImage image2; // converted from the grayscale image to ARGB32 format
    
    QPainter painter(&image1);
    painter.setCompositionMode(); // I tried a few modes but without expected result
    painter.drawImage(image1.rect(), image2);
    

    Any advice?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 29 Jun 2019, 06:44 last edited by
      #2

      Hi,

      Since you are generating these image, can you generate a translucent background rather than a white one ? That would simplify things to merge the two images.

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

      B 1 Reply Last reply 29 Jun 2019, 06:56
      2
      • S SGaist
        29 Jun 2019, 06:44

        Hi,

        Since you are generating these image, can you generate a translucent background rather than a white one ? That would simplify things to merge the two images.

        B Offline
        B Offline
        beecksche
        wrote on 29 Jun 2019, 06:56 last edited by beecksche
        #3

        @SGaist said in Merge Two Images:

        Since you are generating these image, can you generate a translucent background rather than a white one ?

        By now: no!

        The images are generated with a convolution of a target image and a impulse response function (point spread function, psf). Which is the multiplication of the frequencies in the frequency domain of the two images. To calculate the frequency domain with a FFT the target and the psf are both grayscale (PGM) images.

        Maybe there is a way to calcuate the FFT of an image with a transparent background, I don't know.

        1 Reply Last reply
        0
        • C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 29 Jun 2019, 07:14 last edited by
          #4

          Then maybe replace white with the alpha channel - e.g. with QImage::createMaskFromColor()

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          3
          • B Offline
            B Offline
            beecksche
            wrote on 30 Jun 2019, 08:55 last edited by beecksche
            #5

            Thanks for the help.

            I solved my problem by converting the gray levels into alpha values.

            double opacity = 0.5;
            int alpha = opacity * (255 - grayValue(x, y));
            
            QImage converted;
            converted.setPixelColor(x, y, QColor(0, 0, 0, alpha)
            

            So the whiter the pixel the lower the alpha value. With this converted image I'm able to draw it over the other with

            QPainter painter(&image1);
            painter.drawImage(image1.rect(), converted);
            
            1 Reply Last reply
            2

            5/5

            30 Jun 2019, 08:55

            • Login

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