Bilinear Distortion - Different Variants?

Use this forum for comments, suggestions or problems related to the online ImageMagick Studio web interface @ https://imagemagick.org/MagickStudio.
Post Reply
wortell

Bilinear Distortion - Different Variants?

Post by wortell »

I see that the perspective distortion keeps things rather linear - as best it can...
the bilinear creates a sense of "convergence" curves which ** ALWAYS ** start "inward" as they approach their final points.

Is there any way to create the exact OPPOSITE curves for a bilinear distortion?


topic #2 - related.

also, is there a way to do something like a *warp* of an object (like pulling on a particular point of the image and stretching it as in photoshop)?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Bilinear Distortion - Different Variants?

Post by anthony »

In actual fact, forward bilinear is the exact opposite. The current bilinear is currently implemented as a reverse mapping as I have not been able to get back to implementing a proper forward mapped version. I am just getting back to finishing off perspective 'infinity handling' for time improvements, as well as properly resize filter control, within the distortion function.

Fred Wienhaus has been implementing some 'proof of concept' DIY scripted forms of forward mapped (inverse mathematical function) Bilinear Distortion. You can see the script and results in is "3Drotate" script
http://www.fmwconcepts.com/imagemagick/3Drotate/
this script only just predates the implementation of the -distort fintion
and will do perspective, reversed biliner and forward bilinear. However it will not to image tiling or handle the correct pixel merging needed for viewing distant horizons.

Note I do plan on implementing a more generalized polynomial mapping function in which the current reversed bilinear would be classed as a 1.5 degree (between 1 degree and a full 2 degree polynomial), though of course you will need more control points for mapping higher ordered polynomials. However only the simpler reversed forms will be possible using that technique.

Things are happening... slowly but surely. lack of Core programmers is the main problem.

Localized Warp distortions...

the above mathematic functions of course only do global distortions. moving a single control point will effect the whole image.

For more localized warps there are two main methods...
  • One is a sequence of circular regional warps.... That is given a point, and a radius of influence scale (implode), rotate (swirl), or translate the point locally.
  • The other is grid or mesh warping, where the source image has a rectangular grid, or a triangular mesh of points overlay, and the destination is a distorted form of the same grid/mesh.
This last type of distortion is what is used in movies, though the low level distort is generated from a sequence of two (or more) images where the same mesh is used and a parameter is used to not only define where the generated image is to fall between these two images (both in amount of distortion, and in color influence from each source).

This is often regarded as true 'morphing' and is currently only openly available in the X morph package. This is one of the goals I am working toward in IM, but will probably require a higher level script to achieve, once 'mesh distortions' have been implemented, to do the 'core' work.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Bilinear Distortion - Different Variants?

Post by anthony »

The original reversed mapped (or directly using the bilinear polynomial to map destination coordinates to source) is now known as -distort BilinearReverse

As of the next release of IM v6.5.7-0 the forward mapping (reversed form of the equations) has been implemented as BilinearForward. Their was a degenative case that was preventing its correct working that has now been resolved.

BilinearForward maps orthogonal rectangles to any quadrilateral, preserving the straight edges.

BilinearReverse (the original) maps any quadrilateral to an orthogonal rectangle while preserving
the straightness of the edges.

What I now need is a way to combine the two to make a any quadrilateral to any quadrilateral, after which rectangular grid warping will be a possibility.

Of course I should also be able to re-classify a grid into a series of triangles, and use simpler affine warps as an alternative method of generating a grid distortion.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bilinear Distortion - Different Variants?

Post by fmw42 »

to make outward bowing or inward bowing effects, see -distort barrel
http://www.imagemagick.org/Usage/distorts/#barrel

Note that

1) bilinearReverse does not in general preserve straight lines

2) bilinearForward preserves straight lines parallel to the original coordinate axes, but not diagonals or other angles

3) perspective preserves all straight lines
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Bilinear Distortion - Different Variants?

Post by anthony »

fmw42 wrote:Note that
  1. bilinearReverse does not in general preserve straight lines
  2. bilinearForward preserves straight lines parallel to the original coordinate axes, but not diagonals or other angles
  3. perspective preserves all straight lines
ONLY "perspective" four point distortion preserves ALL straight lines. It does this by scaling the image so one side looks further way!

BilinearForward preserves the original orthogonal (horizontal and vertical) lines in the original image.

BilinearReverse does the opposite. It preserves straight lines that will become orthogonal in the destination image. If the quadrilateral in the source becomes an orthogonal rectangle in the destination, then the sides of that quadrilateral will remain straight.

I hope to implement a Bilinear distort for any quadrilateral to any quadrilateral which preserves the straight sides of the quadrilateral.

In all bilinear distortions all other lines (other than those defined above) are NOT expected to remain straight, and in fact usually become a parabolic curve of some kind.

See example in Bilinear Distortions, now in IM Usage Examples
http://www.imagemagick.org/Usage/distorts/#bilinear

What bilinear does do is ensure that the scales or distances along any individual line (even though they may become curved) remain the same.

That is if the sides of a quadrilateral remains straight (by using the right bilinear distortion, or combination of) bilinear will also ensure that the distance, scaling, or spacings along that line also remain the same.

This is why it is used for 'grid distortions' because then the sides of the individual quadrilaterals will still line up. And gird distortions in turn allows for user defined image 'morphing'.

Of course affine (triangle) distortions also have the same property, and a grid could be decomposed into triangular mesh. However I have not found any practical way of inputting triangular meshes into the IM distort operator.

ASIDE: -morph operator is not really a morph but a color dissolve from one image to another.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply