Correcting Alignment of an image series
-
- Posts: 1
- Joined: 2016-08-11T10:00:33-07:00
- Authentication code: 1151
Correcting Alignment of an image series
Hi Guys,
I'm not sure how best to describe what i'm trying to do so please let me know if you need any clarifications.
Basically I have a set of 24 images that were taken of an object that was being rotated on a flat surface. The purpose is to create a smooth high quality short video of the object rotating. once I compile the images into a video, the object seems to bounce around on the screen. I believe this is because the object is not perfectly aligned to the center. All the images are just of that object and basically a white background that I can crop out. I'm trying to batch this process as there is a good number of objects that are already photographed that I'd like to run this on.
How can I process the image set so it can crop all the images while making sure that the object is centered perfectly in the center?
I'm using "Version: ImageMagick 7.0.2-7 Q16 x64 2016-08-06 " on a Win32(64) machine.
I've already attempted to use the -gravity center option with crop with no luck.
"convert img001.png -gravity Center -crop 3840x2160+0+0 result.png"
I appreciate any help on this.
Thanks
I'm not sure how best to describe what i'm trying to do so please let me know if you need any clarifications.
Basically I have a set of 24 images that were taken of an object that was being rotated on a flat surface. The purpose is to create a smooth high quality short video of the object rotating. once I compile the images into a video, the object seems to bounce around on the screen. I believe this is because the object is not perfectly aligned to the center. All the images are just of that object and basically a white background that I can crop out. I'm trying to batch this process as there is a good number of objects that are already photographed that I'd like to run this on.
How can I process the image set so it can crop all the images while making sure that the object is centered perfectly in the center?
I'm using "Version: ImageMagick 7.0.2-7 Q16 x64 2016-08-06 " on a Win32(64) machine.
I've already attempted to use the -gravity center option with crop with no luck.
"convert img001.png -gravity Center -crop 3840x2160+0+0 result.png"
I appreciate any help on this.
Thanks
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Correcting Alignment of an image series
Try adding +repage after -crop 3840x2160+0+0
Does that help? If not, then it would help us understand the issue, if you could post a few of the images. You can upload to some place such as dropbox.com and put the URLs here.
Code: Select all
convert img001.png -gravity Center -crop 3840x2160+0+0 +repage result.png
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Correcting Alignment of an image series
If the camera was hand-held, you first need to align the images, perhaps using some immobile background feature. My pages have a number of methods for this.somew3irdo wrote:Basically I have a set of 24 images that were taken of an object that was being rotated on a flat surface.
If the camera was on a tripod, then I don't understand the problem.
snibgo's IM pages: im.snibgo.com
Re: Correcting Alignment of an image series
I believe the problem is, imagine watching a record spin on a turntable, from the side, except the cheap record has it's hole off-centre so it wavers to the side as you watch it spin. One way to fix that is a type of crop that can search the left/right edges for "non-white" and crop at that point. If the object is rotationally symmetrical, that would centre it.
You could also attempt calculate it's off-centredness and do a gradual left/right shift to compensate. That could be done easily in Avisynth, not imagemagick.
Finally, you could attempt to do a kind of image alignment with hugin.
You could also attempt calculate it's off-centredness and do a gradual left/right shift to compensate. That could be done easily in Avisynth, not imagemagick.
Finally, you could attempt to do a kind of image alignment with hugin.
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Correcting Alignment of an image series
I use IM7 on Windows 10 64. I haven't tested the following suggestions, but the concepts should work with a little tweaking. So...jmac698 wrote:I believe the problem is, imagine watching a record spin on a turntable, from the side, except the cheap record has it's hole off-centre so it wavers to the side as you watch it spin. One way to fix that is a type of crop that can search the left/right edges for "non-white" and crop at that point. If the object is rotationally symmetrical, that would centre it.
If the backgrounds are all some particular color, give or take a few percent, you could use "-trim" to clear that color right up to the relevant part of the images, then re-center them on a new background. That might look something like this...
Code: Select all
magick *.jpg ^
-set option:originalsize "%[w]x%[h]" ^
-fuzz 5% ^
-trim ^
+repage ^
-background white ^
-gravity center ^
-extent "%[originalsize]" ^
result_%03d.jpg
That can be done without much difficulty in IM7, too, if the movement is steady and in a consistent direction across the series of images. One approach would look something like this...You could also attempt calculate it's off-centredness and do a gradual left/right shift to compensate. That could be done easily in Avisynth, not imagemagick.
Code: Select all
magick *.jpg -distort affine "0,0 %[fx:t*(80/(n-1))],0" result_%03d.jpg
You can slide them to the left by making that FX expression a negative number. You can also combine that movement with a shift up or down by adding a similar FX expression as the vertical coordinate in the second coordinate pair. Something like this would shift the images 80 pixels to the right and 30 pixels up across the series of images...
Code: Select all
... "%[fx:t*(80/(n-1))],-%[fx:t*(30/(n-1))]" ...
In a BAT file those single percent signs "%" will all need to be doubles "%%".
Re: Correcting Alignment of an image series
I went to your page at http://im.snibgo.com/ . Thanks for all of the time you've put into that!snibgo wrote:If the camera was hand-held, you first need to align the images, perhaps using some immobile background feature. My pages have a number of methods for this.somew3irdo wrote:Basically I have a set of 24 images that were taken of an object that was being rotated on a flat surface.
If the camera was on a tripod, then I don't understand the problem.
I have the same issue - two images of the exact same scene but one is shifted. I would like to have both images centered the same. Which of the methods on your page would accomplish this?
Thanks!
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Correcting Alignment of an image series
It depends on what you mean by "shifted".bspencer wrote:...two images of the exact same scene but one is shifted.
Perhaps they are two crops from the same original image, so the shifting is a simple translation with no scaling or rotation. Is so, then just pick an area on one image and search for that in the other. See my "Searching an image" page. The area you pick should have some detail; if you pick plain blue sky, this will randomly match some other area of plain blue sky.
If the shifting is more complex, then so is the solution, and many of my pages give methods.
I've recently developed a new method that starts by finding rotation, and then translation, and then scale. (Not yet published.)
snibgo's IM pages: im.snibgo.com
Re: Correcting Alignment of an image series
For example, if you had two images of a person sitting on a beach. In one image the person is facing to the left and the other to the right. However, the photos were taken with a hand-held device and, in turn, the person is slightly shifted to the right in one image. The goal is for the person to be in the same, centered position in each photo.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Correcting Alignment of an image series
You can upload images to somewhere like dropbox.com and paste URLs here.
Perhaps you want the faces to be aligned, so the problem is to find the centre of the face in each photo, and simple subtraction then gives you the translation.
That requires that we detect the positions of the face. Sadly, I don't have a method for detecting faces (but I'd like one). This isn't an easy problem. For some images, we may be able to identify what isn't a face, eg because it is sky, bench or grass.
Perhaps you want the faces to be aligned, so the problem is to find the centre of the face in each photo, and simple subtraction then gives you the translation.
That requires that we detect the positions of the face. Sadly, I don't have a method for detecting faces (but I'd like one). This isn't an easy problem. For some images, we may be able to identify what isn't a face, eg because it is sky, bench or grass.
snibgo's IM pages: im.snibgo.com
Re: Correcting Alignment of an image series
I appreciate your help. I'm going to do some digging around in GIMP and see if I can figure something out. Thanks again!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Correcting Alignment of an image series
You can pick control points in both images. The use +distort perspective to warp one to match the other.
Am I correct that you want the chairs and body aligned, so that when you alternate images, you see the head moving back and forth.
If that is the case, then pick control points on the chair and/or body and do the perspective transformation. See
http://www.imagemagick.org/Usage/distor ... rol_points
http://www.imagemagick.org/Usage/distor ... t_viewport
http://www.imagemagick.org/Usage/distorts/#perspective
http://www.imagemagick.org/Usage/distorts/#box3d
If you post a pair of images, we can probably help more after we see what the issue is.
Am I correct that you want the chairs and body aligned, so that when you alternate images, you see the head moving back and forth.
If that is the case, then pick control points on the chair and/or body and do the perspective transformation. See
http://www.imagemagick.org/Usage/distor ... rol_points
http://www.imagemagick.org/Usage/distor ... t_viewport
http://www.imagemagick.org/Usage/distorts/#perspective
http://www.imagemagick.org/Usage/distorts/#box3d
If you post a pair of images, we can probably help more after we see what the issue is.
Re: Correcting Alignment of an image series
Funny you should ask. I just posted an image to Facebook a few minutes ago and was amused by the face recognition that it did:snibgo wrote: Sadly, I don't have a method for detecting faces (but I'd like one).
https://www.facebook.com/photo.php?fbid ... 8133015969 (note, facebook didn't supply the names, I did that, but facebook located them on the photo for me).