Adjusting the size of an image based on a second image
Posted: 2011-12-26T17:46:19-07:00
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?
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?