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. Proper image rotation by 90 degrees
Forum Updated to NodeBB v4.3 + New Features

Proper image rotation by 90 degrees

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.6k 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.
  • D Offline
    D Offline
    david.luggen
    wrote on last edited by
    #1

    Hey there,

    I have huge images of sizes about 1GB. These I want to turn by 90 degrees. Is there a way to rotate them by 90 degrees without creating a temporary copy of the image which doubles the amount of data for a short time?

    I'm only aware of these two possibilities, first:
    @
    QMatrix rm;
    rm.rotate(90);
    newImage = oldImage.transformed(rm);
    @

    This copies the image and doubles the amount of data.

    The other way is to rotate the QPainter while he is drawing it, but this results in the fact, that the QPainter is going to rotate the image at every update which isn't that nice as well.

    Do you have any suggestions? Thx for any help.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      I don't think you can implement a matrix multiplication "in-place", i.e. without creating a temporary copy. That's because the same index of the input matrix will be read multiple times, so overwriting it will result in an invalid result.

      Just imagine you want to multiply matrix A by matrix B, resulting in matrix C. Multiplying the first row of matrix A with the first column of matrix B, will give you the value for index (0,0) of matrix C. Now, if you did overwrite the input matrix A at (0,0) at this point, because you don't want to store C separately, things go horribly wrong! Next you have to multiply the first row of A with the second column of B in order to get the value of C at position (0,1). But the first row of A has been modified already and thus you get a "wrong" result.

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • D Offline
        D Offline
        david.luggen
        wrote on last edited by
        #3

        Yes, that's the inconvenient truth. But there are still algorithms that make it possible. Your "in-place" was the word I was missing to find something like that:

        http://en.wikipedia.org/wiki/In-place_matrix_transposition

        It's like I first thought of it, you just copy one pixel from it's source to where it belongs, but deploy the overwritten pixel to a temporary variable. Then you replace that one and so on till the whole matrix is transformed.

        This can be accelerated by using multiple values at a time. There it is possible to find a trade between how many data I want to allocate for the transformation and the speed of the transformation.

        But this will take me quite some time to set up a proper algorithm, therefore I'm in the search of something like this already done in C++.

        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