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. Bilinear Transformation of Bitmap in QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

Bilinear Transformation of Bitmap in QGraphicsScene

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 9.9k 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.
  • M Offline
    M Offline
    moellney
    wrote on last edited by
    #1

    Dear Forum

    I'm looking for a way to transform / deform an image bi-linearly.

    I would like to give the coordinates of corners of an image in a QGraphicsScene and let the image be deformed to fill the new trapezoidal area.

    A good idea what effect I'm looking for is in the image:
    "Mesh Transformation":http://www.psastras.com/images/screenshots/mesh1_b.png

    I found quadToQuad to let me generate a QTransform, but applying this to an QGraphicsPixmapItem actually deforms the image perspectively:
    If you use a chess board pattern as image, you will see, that the length of the black/white pattern is not equal along the edge from the 'front' corner to the 'back' corner.

    If an image is deformed bi-linearly (like the typical approach with textures and texture coordinates in OpenGL) then the pattern of the chess-board would be equal lengthed along the edges of the deformed image.

    Is there a way to have bi-linear deformation / texture filling for an QGraphicsScene item?

    Thank you,
    Michael

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jbarron
      wrote on last edited by
      #2

      There is nothing in Qt to give you this effect out of the box (without using OpenGL directly). You will have to convert the pixmap to a QImage and apply your bi-linear transform directly to the bits.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        metRo_
        wrote on last edited by
        #3

        I think that OpenCV can do it, can't you use Qt with OpenCV?!

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xsacha
          wrote on last edited by
          #4

          I'm sure you can, it'd be cleaner to use Qt though.
          I wish there was a set of tools for this sort of thing, possibly with QtOpenCL as optional backend.

          • Sacha
          1 Reply Last reply
          0
          • I Offline
            I Offline
            infoctopus
            wrote on last edited by
            #5

            No problem to use OpenCV together with Qt.
            moellney, BTW, you may also would want to have a look at IPP (intel performance primitives)

            Qt rulez

            1 Reply Last reply
            0
            • M Offline
              M Offline
              moellney
              wrote on last edited by
              #6

              [quote author="metRo_" date="1291422906"]I think that OpenCV can do it, can't you use Qt with OpenCV?![/quote]

              I used OpenCV (in another project) along Qt, it works nicely.

              But I could not find any method to help me on bilinear deformation. All I could find is perspective de-/transformations.

              Can you give me a hint which method to use?

              Thanks Michael

              1 Reply Last reply
              0
              • I Offline
                I Offline
                infoctopus
                wrote on last edited by
                #7

                moellny, please see http://opencv.willowgarage.com/documentation/cpp/geometric_image_transformations.html?highlight=bilinear

                For instance, cv::warpAffine can use any interpolation method. See cv::resize for a list of all interpolation methods available

                Qt rulez

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  moellney
                  wrote on last edited by
                  #8

                  [quote author="infoctopus" date="1291637819"]moellny, please see http://opencv.willowgarage.com/documentation/cpp/geometric_image_transformations.html?highlight=bilinear

                  For instance, cv::warpAffine can use any interpolation method. See cv::resize for a list of all interpolation methods available[/quote]

                  Thanks for you answer, but there are no methods in your links that lead to a bilinear deformation. There is only affine deformation or perspectivic deformation. Bilinear in both context refer to the color filtering methods used.

                  Do not mix up the bilinear color interpolation (bilinear filtering e.g. as in "Wikipedia Bilinear Filtering":http://en.wikipedia.org/wiki/Bilinear_filtering) used for color interpolation with the general concept of a "Bilinear Interpolation":http://en.wikipedia.org/wiki/Bilinear_interpolation where the function of the corners of the [0,1]x[0,1] grid may be polygon corners of a quad leading to a deformation of a rectange in 2-dimensional space.

                  The problem is filling this deformed rectange.
                  This deformation is not a generizable as affine deformation (supported by Qt) and is not (in general) the 2d projection of a rotated rectange (perspectivic transformation supported by qt via squareToQuad method).

                  Image a plane rectangular peace of rubber on the table in front of you, that you deform by moving one corner (still on the table). Now imagine an image on the rectangular plane. How does the image deform?

                  The filling of a biliner deformed rectange on the screen can be done with e.g. a nearest neighbour algorithm or with other color interpolations methods.... but this is a seperate topic:
                  In Qt you can set this with "Transformation mode":http://doc.troll.no/4.7/qt.html#TransformationMode-enum

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    infoctopus
                    wrote on last edited by
                    #9

                    Ok, I see. I'm starting to think that it's easier to implement an algorithm for this transformation from scratch. Also good anti-aliasing method will be of need.

                    Qt rulez

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      infoctopus
                      wrote on last edited by
                      #10

                      I know that Photoshop does the job perfectly. But maybe some of opensource graphic editors has this feature as well, so you could look at the implementation, e.g. gimp

                      Qt rulez

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        moellney
                        wrote on last edited by
                        #11

                        Finally found the method(s) I was looking for in Intels
                        "IPP WarpBilinear (etc.)":http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/ippxe/ipp_manual_win_mac/IPPI/ippi_ch12/functn_WarpBilinear.htm

                        But hey, this is US$399... well... including a compiler and other goodies...

                        OpenCV seems to lack this functionality.

                        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