Opencv Image Registration - MapperGradEuclid

Viewed 265

I'm trying to find the translation & rotation of an image with the reference template image. The template image is one of the following pictures. Set of Different IMages

Since the resolution is quite small (320*240) we would like to solve the alignment problem with the image registration class of opencv (Image Registration). We don't want to use feature based alignment.

So far I did the following function to align the reference mImageTemplate image and the image to find the rotation and translations image - input:

cv::Mat pixelMapRegistration::align(cv::Mat input)
{
    cv::Mat transformed;
    cv::Ptr<cv::reg::Map> rot_shift_res;
    cv::reg::MapperGradEuclid rot_shift = cv::reg::MapperGradEuclid();
    rot_shift_res = rot_shift.calculate(mImageTemplate, input);
    cv::reg::Map* res = rot_shift_res.get();
    rot_shift_res->inverseWarp(input, transformed);
    return transformed;
}

Unfortunately it does not work so far. Does someone see the problem?

2 Answers

In your images, you have a static gradient background and a moving foreground. You need to get rid of the background detail as it will impact the MapperGrad. You could try taking an empty picture and use the absolute difference, or you could try doing a morphological TopHat or BackroundSegmentation to filter out the background. But I suspect you will need to start with cleaner images where the background has no detail. It would certainly be easiest.

If the movements are small, you use MapperGrad directly, but if the movements are big like in your image set, then you need to feed MapperGrad into a MapperPyramid.

I think the real answer is that you will want to use something like shape or template matching instead. Image Registration is not really meant to be a feature/pattern match tool as it considers the whole image. It's really for when you're trying to mitigate vibrations between captures without using fiducials, video stabilization, etc.

The solution was not only one, but several different aligning methods. Those image registration techniques only work if the target is already close to the template position. Therefore I was not using it anymore.

To achieve mentioned aligning problem the pipeline of several methods did the job :

  • PCA (basic shift and rotation)
  • ICP (Iterative Closest Point - for refinement)

or

  • Ellipse Fitting (basic shift and rotation)
  • ECC (cv::findTransformECC function - for refinement)

At the end you still face the problem that none of mentioned rough alignment methods are able to rotate the part properly if the part is rotated more than +/- 90° from the template. Therefore use the Enhanced Correlation Coefficient (ECC) to check if your alignment was successful, if not - rotate it around 180°.

Related