MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayTo resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Asked by Nitin on 16 Jun 2013

Hello, I am performing a transformation for video stabilization on frames at 0.125 of the original size. I would now like to infer the geometric transform back onto the original image.

for i = 1: 10

% Estimate transform from frame A to frame B, and fit as an s-R-t H = cvexEstStabilizationTform(imgA_small,imgB_small); HsRt = cvexTformToSRT(H); Hcumulative = HsRt * Hcumulative;

imgB_small_transform = imwarp(imgB_small,affine2d(Hcumulative),'OutputView',imref2d(size(imgB_small)));

% img_B_original_size = ??

end

Any ideas how to acheive this please? Many thanks,

Answer by Alex Taylor on 17 Jun 2013

Edited by Alex Taylor on 17 Jun 2013

Accepted answer

You have an estimate for rotation, scale, and translation. Ideally, the rotation and scale estimates that you obtain at lower scale are invariant to the fact that you have pre-scaled your images (this won't be strictly true in reality because you will lose information in downsampling that your features may be sensitive to). If your registration estimate indicates a scale difference of 1.2 and a rotation of 10 degrees, this is independent of whether you have pre-scaled your images as long as both images are at the same scale.

The translation component of your SRT transformation is relative to your downsampled images. You can see this immediately if you think about it: a translation in pixels of (-2,5) in your downsampled images is not the same amount of translation (in physical units) as (-2,5) pixels at full scale.

To solve your problem, you will need to re-scale your translation estimate in HsRt(3,1:2) by a factor of 8x to account for your initial pre-scaling.

Answer by Matt J on 16 Jun 2013

Edited by Matt J on 16 Jun 2013

There are dozens of image registration files on the File Exchange

http://www.mathworks.com/matlabcentral/fileexchange/index?utf8=%E2%9C%93&term=image+registration

I don't know if all of them require the images to be at the same resolution, but you can always imsize() the high-resolution image down to the same resolution as the low-resolution image, if needed. It couldn't matter that much for the low parameter affine registration that you're trying to do.

Show 12 older comments

Alex Taylor on 18 Jun 2013

When I answered yesterday, I didn't notice Matt J's comments, which are spot on. Ashvin, try simply upscaling just the translation parameters in Hcummulative. That should work.

Alternatively, you will need to describe what exactly is still not working. Try looking at your images. Does it look like the scale/rotation are correct? Does it look like translation is correct?

Try providing visualizations that would help people to understand the nature of misalignment you are seeing. For example:

help imshowpair

You should also try using the transformPointsForward/transformPointsInverse methods of the affine2d class to see if points map the way that you expect them to between your target and reference images. This is what I do when I'm stuck on a geometric transformation problem. It is often more helpful to think about point mapping than to look at the resampled images grids when you are trying to figure out what is going on.

Matt J on 18 Jun 2013

**When I answered yesterday, I didn't notice Matt J's comments, which are spot on. Ashvin, try simply upscaling just the translation parameters in Hcummulative. That should work.**

Earlier in this string of comments, Ashvin showed the following code. It should have had the effect of scaling the translation parameters, but apparently that didn't help. So, I am puzzled...

Hdown = [ 256/2048 0 0; 0 256/2048 0; 0 0 1];

Hup = [ 2048/256 0 0; 0 2048/256 0; 0 0 1];

Hcumulative = Hup * HsRt * Hcumulative * Hdown;

## 0 Comments