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.4k 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.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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

      beeckscheB 1 Reply Last reply
      2
      • SGaistS SGaist

        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.

        beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on 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
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 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
          • beeckscheB Offline
            beeckscheB Offline
            beecksche
            wrote on 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

            • Login

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