Sorry that this got somewhat lengthy, but I would like to ensure that you know what exactly I'm after:
At the moment I am optimising my VisualBasic Script (VBS) presented at http://www.imagemagick.org/Usage/windows/#vb_text. Basically, this script maps one image onto another by a perspective transformation. Usually, the first image is a perpectively distorted photograph and the second one is a plan drawing or a perspectively correct image (i.e. a plane parallel photograph). The perspectively distorted photograph is then mapped onto this plan drawing by means of (at least) 4 match points and thereby rectified. (I will work on a better example for the web site later on.)
When working with this script, the two images often have different sizes, but I would like the rectified version of the first one to exactly match the dimensions of the second one, such that I can place the first over the second and the four match points do exactly match (as can be seen in the example given at the above link).
I am using the "-distort perspective" operation (and not its + version) in order to avoid problems arising from horizons appearing the source picture.
When the size of the two pictures are different, there are three possible scenarios:
1) Source is larger in both dimensions => Apply perspective transformation an then crop.
2) Source is smaller in both dimensions => Extend the source picture to the dimensions of the target picture, then apply perspective transformation.
3) One dimension of the source is smaller, the other is larger than that of the target picture => Extend the smaller dimension to that of the target picture, apply perspective transformation, then crop the other dimension to the extent of the target picture.
These operations can of course be performed by the script in an If-then-else construction. (Although this is complicated by VBS lacking a MAX function and implicit if (IIF) structures.)
But could you think of an Convert statement performing such adjustments in one step?
Adjusting the size of an image based on a second image
- whugemann
- Posts: 289
- Joined: 2011-03-28T07:11:31-07:00
- Authentication code: 8675308
- Location: Münster, Germany 52°N,7.6°E
Adjusting the size of an image based on a second image
Wolfgang Hugemann
-
- Posts: 88
- Joined: 2010-06-29T14:36:09-07:00
- Authentication code: 8675308
Re: Adjusting the size of an image based on a second image
I did have something similar to this problem
but I have solved by calling "convert.exe"
several times getting the values (size) as output , putting them in a variable
and then "feeding" convert.exe a second time with the those values.
Made something like a batch script.
But a problem arouse : the DOS batch variables do not allow non-integer values
So I had to turn to sometihng else ...
I suppose that in VBs you can do the same ...
but I have solved by calling "convert.exe"
several times getting the values (size) as output , putting them in a variable
and then "feeding" convert.exe a second time with the those values.
Made something like a batch script.
But a problem arouse : the DOS batch variables do not allow non-integer values
So I had to turn to sometihng else ...
I suppose that in VBs you can do the same ...
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Adjusting the size of an image based on a second image
The simplest is probably to simple do you perspective transformation (generally with virtual pixels set to transparent) then read in the second image, swap the order and then 'flatten' them (to preserve virtual offsets from a +distort)
When composing, the final image size (and other meta-data) all comes from the first image, that is why swapping the images is important.
The alternative is to manually set a 'viewport' for the distort, which will enlarge (pad) or crop (cut) the output image to fit the interger bounds given.
http://www.imagemagick.org/Usage/distor ... t_viewport
When composing, the final image size (and other meta-data) all comes from the first image, that is why swapping the images is important.
The alternative is to manually set a 'viewport' for the distort, which will enlarge (pad) or crop (cut) the output image to fit the interger bounds given.
http://www.imagemagick.org/Usage/distor ... t_viewport
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Adjusting the size of an image based on a second image
Can that be changed or something?markmarques wrote:But a problem arouse : the DOS batch variables do not allow non-integer values
- whugemann
- Posts: 289
- Joined: 2011-03-28T07:11:31-07:00
- Authentication code: 8675308
- Location: Münster, Germany 52°N,7.6°E
Re: Adjusting the size of an image based on a second image
DOS environment variables just store strings, which IM's fx operator may interpretate as real values, see http://www.imagemagick.org/Usage/windows/#calculations. You are right in so far that the DOS SET command can only do integer arithmetics.davdigsb wrote:Can that be changed or something?markmarques wrote:But a problem arouse : the DOS batch variables do not allow non-integer values
Wolfgang Hugemann
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Adjusting the size of an image based on a second image
The same is also true of BASH shell arithmetic, which is why 'bc' or 'convert' itself is sometimes used as a floating point calculator.whugemann wrote:DOS environment variables just store strings, which IM's fx operator may interpretate as real values, see http://www.imagemagick.org/Usage/windows/#calculations. You are right in so far that the DOS SET command can only do integer arithmetics.
Examples are in
http://www.imagemagick.org/Usage/transform/#fx_escapes
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/