Page 1 of 1

When using affine, is there a way to not have it crop?

Posted: 2007-02-20T11:50:27-07:00
by rschmitty
I'm trying to use the transform matrix on an object that is placed on an image at a later step but have run into a problem

The cricle im transforming was just rotated 45 degrees and moved to a location on the larger image 'platter' the circle_transform.png object is now 198x198 (which isnt a problem) but it gets cropped.

Code: Select all

convert -affine 0.7071068286895752,0.7071068286895752,-0.7071068286895752,0.7071068286895752,556.75,53 -transform circle_160_120.png circle_transform.png
composite -compose atop -background none circle_transform.png -geometry +556.75+53 platter_730_486.jpg transformtest.jpg
Here's the output that was produced

Image

Here's the circle I'm transforming (ignore my horrible skills :P)

Image



Any ideas/suggestions appreciated!

TIA

Re: When using affine, is there a way to not have it crop?

Posted: 2007-02-21T11:45:36-07:00
by rschmitty
Digging deeper into this....

Not sure if this is by design and part of the step I'm missing? but when I change the code to have tx and ty both be 0 in the matrix

Code: Select all

convert -affine 0.7071068286895752,0.7071068286895752,-0.7071068286895752,0.7071068286895752,0,0 -transform circle_160_120.png circle_transform.png
the circle is no longer cropped, however the placement on the final image is offset by a large amount.


should I continue down this path to work out the math to correct the offset, or is there something in the initial affine that needs to be done to eliminate the cropping?

Re: When using affine, is there a way to not have it crop?

Posted: 2007-02-21T12:22:36-07:00
by magick
Grab the latest version of ImageMagick, 6.3.2-8. It has a patch for the affine transform which may solve your problem.

Re: When using affine, is there a way to not have it crop?

Posted: 2007-02-22T15:38:31-07:00
by rschmitty
Thank you that did the trick :) No longer cropping it off oddly!


Cheers! 8)

Re: When using affine, is there a way to not have it crop?

Posted: 2007-02-22T19:16:56-07:00
by anthony
State of Development

Note that -affine/-transform was only completely fixed (at a gross level) as of two weeks ago. There is stil some work needed to ensure it is also fixed at the pixel offset level (EG: make sure half pixel displacements work as you would expect).
See IM examples for more info and examples on using...
http://www.imagemagick.org/Usage/distorts/#affine

There has been a suggestion that we have a setting that controls affine (and in the future perspective) transforms as to what size the result should be.
That is, a choice of...
  • output fits transformed image (the current handling default)
    output as original image (as positioned)
    output as original image (no page offset)
    output original image (centered)
    given output size and offset (probably set with -size)
    given ouput size and transformed image centered (as per -rotate and -scale)
However while this could speed things up by reducing the number of pixels that needs to be calculated, especially in extreme cases (for example rotating a very very long by thin image), all of these can be simply generated via some post-processing (with some pre-processing for the extreme cases).

The important point is that ALL the builtin distortions do not lose information, either image data, or from position changes, while keeping the resulting image at a minimal size.

Do you, or anyone else have any comment on the above?

The next aspect is to somehow merge -affine/-transform with a new -perspective distrotion operator.

A perspective distortion could be specified as a matrix of 8 values, and/or displacement of a quadrangle or 2x4coords or 16 values). However we are in need of a simplified perspective matrix inverse function, simular to what we have for affine matrix. See Affine Internals...
http://www.imagemagick.org/Usage/distorts/#affine_diy

We may even add some other methods of specifying an affine transform :-)