Hello,
I have a set of aerial images which I am trying to clip by their overlapping areas, for use in a more involved program I am writing in Python with PIL. Does ImageMagick have an easy method for extracting the overlapping area from a pair of images? I know this may be difficult since the images will have perspective differences, but should still be possible.
I need to call this tool through Python as an external sub process, as it will be part of a batch processing script. Any ideas/advice would be great! Thanks so much in advance.
Clip Aerial Image Pair by Overlapping Area
-
- Posts: 4
- Joined: 2014-05-20T13:16:38-07:00
- Authentication code: 6789
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Clip Aerial Image Pair by Overlapping Area
IM doesn't have an simple method for this. You need a script. If you can post up some images (eg put them somewhere like dropbox.com and paste URLs here) we can give more specific advice.
Some tools like Hugin are designed for more-or-less this purpose; it finds all you need to know to create panoramas.
IM has lower-level tools, that you can use to find the alignment of images. See similar threads in this forum eg viewtopic.php?f=1&t=25543
Some tools like Hugin are designed for more-or-less this purpose; it finds all you need to know to create panoramas.
IM has lower-level tools, that you can use to find the alignment of images. See similar threads in this forum eg viewtopic.php?f=1&t=25543
snibgo's IM pages: im.snibgo.com
-
- Posts: 4
- Joined: 2014-05-20T13:16:38-07:00
- Authentication code: 6789
Re: Clip Aerial Image Pair by Overlapping Area
Thanks for your response. I think including a couple images to show what I mean is a good idea. Take a look at the two images below:
https://drive.google.com/file/d/0B3VgXc ... sp=sharing
https://drive.google.com/file/d/0B3VgXc ... sp=sharing
There is a region between those images that physically overlaps. This is what I want to clip out of both images, the "common area". I can easily do this manually, but the script I am working on will need to do this for many images at a time.
https://drive.google.com/file/d/0B3VgXc ... sp=sharing
https://drive.google.com/file/d/0B3VgXc ... sp=sharing
There is a region between those images that physically overlaps. This is what I want to clip out of both images, the "common area". I can easily do this manually, but the script I am working on will need to do this for many images at a time.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Clip Aerial Image Pair by Overlapping Area
I would tackle this in the seven steps I outlined in viewtopic.php?f=1&t=25539
For steps 1-3, feature matching between the images, you might want to match features at ground level, rather than the tops of buildings. If you only want to find the overlap, this won't matter.
A simple affine transformation could align the images, if you want that. You feed "-distort affine" with three or more coordinates from each image. This gives you 6 parameters, from which you can calculate the exact overlap.
I've put some of the building blocks for this on my IM pages.
For steps 1-3, feature matching between the images, you might want to match features at ground level, rather than the tops of buildings. If you only want to find the overlap, this won't matter.
A simple affine transformation could align the images, if you want that. You feed "-distort affine" with three or more coordinates from each image. This gives you 6 parameters, from which you can calculate the exact overlap.
I've put some of the building blocks for this on my IM pages.
snibgo's IM pages: im.snibgo.com
-
- Posts: 4
- Joined: 2014-05-20T13:16:38-07:00
- Authentication code: 6789
Re: Clip Aerial Image Pair by Overlapping Area
Thanks again. Is this a process that can be automated and looped through a set of images, or do points need to manually be selected per image? As you said, it would be best to line up points on the ground, but it wouldn't be worth having to manually select points every time. Would this be able to be wrapped up into one command with several different arguments?
I'm new with IM so I'm just now learning the tools and arguments!
I'm new with IM so I'm just now learning the tools and arguments!
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Clip Aerial Image Pair by Overlapping Area
It could be automated. For example, it could find 24 points in one image and search for those in the second. Perhaps it finds 18. It might accept all of them, or it might do some statistics to eliminate outliers. Then it would feed the coords to "-distort affine".
snibgo's IM pages: im.snibgo.com
-
- Posts: 4
- Joined: 2014-05-20T13:16:38-07:00
- Authentication code: 6789
Re: Clip Aerial Image Pair by Overlapping Area
Thanks for the advice! I'll give it a shot and see what happens.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Clip Aerial Image Pair by Overlapping Area
How's it going? By my calculation, to match img_Left, img_Right needs to be shifted right by 502 pixels and up by 23 pixels. I found this by creating a simple script that calls various other scripts. See my page "Simple alignment".
snibgo's IM pages: im.snibgo.com