Hi ,
I have a reference image and another one is which ill be clicking from a webcamera. Hence I need to check for image alignment/image registration of the new image with the reference one in case any camera angle got changed accidently. Is there any way of doing it in image magick where I can give both the reference and the new image as an input and get the new image aligned with the reference one. I am using the latest version of imagemagick.
Automatic Image Alignment/Registration
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Automatic Image Alignment/Registration
You can pick control points on each image and then warp one image to align with the other. Several methods are possible. A simple affine warp, a perspective warp or a polynomial warp. See -distort at http://www.imagemagick.org/Usage/distorts/.
If the two images are just offset relative to each other and no rotation or scaling differences, then you can use compare with -subimage-search to find the best match location of the smaller one relative to the larger one. See compare at http://www.imagemagick.org/script/compare.php and
http://www.imagemagick.org/Usage/compare/
Perhaps you can provide and example pair of images. You can upload to some free hosting service such as dropbox.com (public folder) and put links here. We can better advise if we can see what you are trying to do.
In the future, please provide your version of IM and platform, if you already have Imagemagick. Often there are syntax differences between Unix and Windows versions, plus more features for newer versions of IM.
If the two images are just offset relative to each other and no rotation or scaling differences, then you can use compare with -subimage-search to find the best match location of the smaller one relative to the larger one. See compare at http://www.imagemagick.org/script/compare.php and
http://www.imagemagick.org/Usage/compare/
Perhaps you can provide and example pair of images. You can upload to some free hosting service such as dropbox.com (public folder) and put links here. We can better advise if we can see what you are trying to do.
In the future, please provide your version of IM and platform, if you already have Imagemagick. Often there are syntax differences between Unix and Windows versions, plus more features for newer versions of IM.
Re: Automatic Image Alignment/Registration
Thanks for the answer. I assume by picking control points on the 2 images you mean we need to know the image coordinates on both images that are similar and then we can apply the image magick command using those control points as an input for rotating or scaling?
Currently on windows using image magick version 6.8.9-Q16
Currently on windows using image magick version 6.8.9-Q16
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Automatic Image Alignment/Registration
Upload a couple of sample images. It's easier to show than explain.
For control points, the basic idea is to crop a small area from one image and do a subimage search for the crop within the other image.
For control points, the basic idea is to crop a small area from one image and do a subimage search for the crop within the other image.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Automatic Image Alignment/Registration
You can pick control points manually or the way user snibgo suggested (provided there is no rotation or scaling between the two images, if there is then you might be able to convert each image to log-polar form and do the subimage matching in that domain). Since you are on Windows, I will let snibgo follow up on your request and examples, since he is a Windows user and I am on a Mac/Unix.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Automatic Image Alignment/Registration
My "to do" list includes a page or two on this topic.
Panotools can automatically and quickly find control points that correspond, and transform one image so it matches another. Panotools is designed for building panoramas, but is also useful for related activities.
IM contains the low-level tools to do the jobs, but scripts have to be built (which I have done, and will publish). These:
1. Select points in image A. So far I just select an array of points, eg in a 6x4 pattern. But I intend to incorporate feature-detection from my "Details, details" page.
2. Crop areas from image A at these points. Discard crops where there is no detail.
3. Locate each crop in image B. This is typically a 2- or 3-phase search, using reduced image sizes, for high speed.
4. Compare the transformations at each point-pair. Discard outliers (assumed false-positive matches).
5. Select a distortion method that will transform image B to image A (or vice versa).
6. Do the transform.
7. Optionally, create marked-up copies of the images, showing what it has done.
I currently use this for stabilising hand-held video. It works well. It needs expanding to permit manual editing of control points for special effects.
Panotools can automatically and quickly find control points that correspond, and transform one image so it matches another. Panotools is designed for building panoramas, but is also useful for related activities.
IM contains the low-level tools to do the jobs, but scripts have to be built (which I have done, and will publish). These:
1. Select points in image A. So far I just select an array of points, eg in a 6x4 pattern. But I intend to incorporate feature-detection from my "Details, details" page.
2. Crop areas from image A at these points. Discard crops where there is no detail.
3. Locate each crop in image B. This is typically a 2- or 3-phase search, using reduced image sizes, for high speed.
4. Compare the transformations at each point-pair. Discard outliers (assumed false-positive matches).
5. Select a distortion method that will transform image B to image A (or vice versa).
6. Do the transform.
7. Optionally, create marked-up copies of the images, showing what it has done.
I currently use this for stabilising hand-held video. It works well. It needs expanding to permit manual editing of control points for special effects.
snibgo's IM pages: im.snibgo.com