I have two images taken in quick succession.. however, they are off by a few pixels..
For some of the neat effects like animation, hdr, addition and subraction, I need to align the frame.. so, something like offset coordinates from one frame to the next.
So, I'm wondering how that would be done?
would you do a search pattern around a set of pixels looking for similarities?
Has anyone done anything like this in an automated format?
This is certainly one of those fuzzy logic type things where a person can 'eye' up the difference real quick, but much harder for a computer.
Aligning frames..
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Aligning frames..
If you crop one image at least a little and take into account how you cropped it, then compare can match the smaller image to where it best fits in the larger image.
see examples in other posts
viewtopic.php?f=1&t=14613&p=51076&hilit ... mse#p51076
viewtopic.php?f=1&t=14662&start=0&hilit ... mse#p51267
see examples in other posts
viewtopic.php?f=1&t=14613&p=51076&hilit ... mse#p51076
viewtopic.php?f=1&t=14662&start=0&hilit ... mse#p51267
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Aligning frames..
Note compare would only find the 'best aligned match' without any form of scaling or rotation.
Also as two images are large it would be VERY slow (tens of minutes to hours), as IM compare just tries comparing the image at ALL locations. A very slow iterative process.
For better speed up, cropping a couple of very small distinctive features from one photo and comparing those features to the other image, should let you fine their location in the other image very quickly. That may be a very useful script actually! With the location of two of thre such features the image alignment and, mild rotation modification should be able to be determined. The control points found can then be feed into 'distort affine' to re-align images. The more control points you can align the better the final alignment.
However there are also techniques for finding image alignment (affine alignment, or a position/scale/rotation determination) but no examples of doing this in IM at this time (technique may need a new 'distort' function).
Also as two images are large it would be VERY slow (tens of minutes to hours), as IM compare just tries comparing the image at ALL locations. A very slow iterative process.
For better speed up, cropping a couple of very small distinctive features from one photo and comparing those features to the other image, should let you fine their location in the other image very quickly. That may be a very useful script actually! With the location of two of thre such features the image alignment and, mild rotation modification should be able to be determined. The control points found can then be feed into 'distort affine' to re-align images. The more control points you can align the better the final alignment.
However there are also techniques for finding image alignment (affine alignment, or a position/scale/rotation determination) but no examples of doing this in IM at this time (technique may need a new 'distort' function).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Aligning frames..
Hmm. interesting. I like the sound of "finding the local maxima in hough space".. thought I have no idea what that actually means
.. so if you could find distinctive coordinates in both images, you might be able to find a best guess of the offsets.
Like, find the average center of the brightness in the image, and use that as a cheap way to fix a location.. then maybe look at different colors or something..
I don't know the easiest/fastest way to do that though.. or if it would actually work.
I'll check out the compare feature.. it does seem do the offset.. though annoying to have to do a crop first.
.. so if you could find distinctive coordinates in both images, you might be able to find a best guess of the offsets.
Like, find the average center of the brightness in the image, and use that as a cheap way to fix a location.. then maybe look at different colors or something..
I don't know the easiest/fastest way to do that though.. or if it would actually work.
I'll check out the compare feature.. it does seem do the offset.. though annoying to have to do a crop first.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Aligning frames..
For looking for matching points. cropping the area around a 'point of maximum change' and searching for that
would probably be the simplist technique for a one or two point image registration (good enough for rough affine
alignment).
The other technique involves transforming both images into a 'polar-log' distortion, then finding the best corresponding match.
This removes the effect of position, with the location giving you a rotation/scale match. You can then do the rotate/scale and do another image comparison match between the images to find there images x/y position. Note this is for affine alignment, not perspective alignment.
Wish I could find the URL to the paper that Fred Wienhaus gave me.
would probably be the simplist technique for a one or two point image registration (good enough for rough affine
alignment).
The other technique involves transforming both images into a 'polar-log' distortion, then finding the best corresponding match.
This removes the effect of position, with the location giving you a rotation/scale match. You can then do the rotate/scale and do another image comparison match between the images to find there images x/y position. Note this is for affine alignment, not perspective alignment.
Wish I could find the URL to the paper that Fred Wienhaus gave me.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Aligning frames..
http://www-cs.ccny.cuny.edu/~wolberg/pub/icip00.pdf
But I don't think he has rotation issues since these were quick succession frames. He just needs to find the x,y offset between the two images. The simplest method is just find some reasonably distinct subsection of one image and use compare to locate it in the other image. Then add back the crop offset. If there is any significant rotation then compare will not be of much use even if you try to find the offsets of numerous small areas.
But I don't think he has rotation issues since these were quick succession frames. He just needs to find the x,y offset between the two images. The simplest method is just find some reasonably distinct subsection of one image and use compare to locate it in the other image. Then add back the crop offset. If there is any significant rotation then compare will not be of much use even if you try to find the offsets of numerous small areas.
Last edited by fmw42 on 2009-11-23T20:10:37-07:00, edited 1 time in total.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Aligning frames..
Thanks Fred for the link again. I have no idea why it 'disappeared' on me. It is a good paper for
general sub-image searching without scale or rotation problems.
As I mentioned if the rotate is minor (likely) then looking for two well spaced sub-sections from only image in the other should get you the image offset and any minor rotation correction. I do mean minor as a large rotation will probably fail or incorrectly match the two 'sub-sections'.
The center of those sub-sections would make good control inputs to -distort affine to re-align the images.
source control point = section_crop_offset + size /2
destination control point = compare_offset +size/2
If you can give us small (resized) example image we demonstrate it for you with actual commands.
general sub-image searching without scale or rotation problems.
As I mentioned if the rotate is minor (likely) then looking for two well spaced sub-sections from only image in the other should get you the image offset and any minor rotation correction. I do mean minor as a large rotation will probably fail or incorrectly match the two 'sub-sections'.
The center of those sub-sections would make good control inputs to -distort affine to re-align the images.
source control point = section_crop_offset + size /2
destination control point = compare_offset +size/2
If you can give us small (resized) example image we demonstrate it for you with actual commands.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/