[Interest] Understanding QImage::transformed()
jhihn at gmx.com
Mon Dec 17 20:34:02 CET 2018
> Sent: Monday, December 17, 2018 at 1:19 PM
> From: "Samuel Rødal" <srodal at gmail.com>
> To: "Jason H" <jhihn at gmx.com>
> Cc: interest at lists.qt-project.org
> Subject: Re: [Interest] Understanding QImage::transformed()
> Btw, I think instead of using QImage::transformed() here which is a
> bit wasteful as it generates a bigger image containing the entirety of
> the source image mapped into the new coordinate system, it's simpler
> and better to just use QPainter directly, and set the painter
> transform to the result from quadToQuad(). That way you don't even
> need to use trueMatrix(). I've shown both approaches in the attached
> example, along with some code that maps the source points correctly
> into the mapped images.
Indeed, your example works!
A few things though:
It seems (to me) trueMatrix() is not really well named. I think this is the part that is confusing to me. It depends on what "true" is. To me, ground truth is the linear algebra operation which should be done by using the quadToQuad transform. trueMatrix() in Qt is really the adjusted matrix used for containing all the image points. Maybe QImage::transformed() should take a parameter for whether or not the resulting image should be pixel-all-encompassing or as-specified? I think this is very confusing.
Indeed the QPainter approach is superior:
1) It is much faster: QImage::transformed() is 55 msec, QPainter is 25 msec. Over several runs, QPainter was always at least 2x as fast.
2) I can completely follow your QPainter and point mapping code it matches my idea of what should be happening.
Many, many thanks!
More information about the Interest