Giter Site home page Giter Site logo

image-align's Introduction

About this library

Image Align is a C++ library providing variants of the classic image alignment algorithm by Lucas-Kanade.

Image Align under Euclidean Motion

The project emerged while working on AAM, an active appearance models library. Fitting active appearance models is similar to the classic image alignment problem:

The goal of image alignment is to find the locally 'best' transform between a template image and a target image by minimizing an energy function measuring the fitness of the alignment. -- Ian Matthews

Algorithms and Features

All image alignment algorithms implemented in this library are based on the original formulation of Lucas-Kanade:

  • Forward additive algorithm
  • Forward compositional algorithm
  • Inverse compositional algorithm

For convergence and runtime reasons all algorithms support multi-level hierarchical matching.

The alignment algorithms are independent of the chosen warp function. Currently the library provides the following warp modes:

  • 2D Translational Warp
  • 2D Euclidean Warp
  • 2D Similarity Warp
  • 2D Affine Warp

User defined warp functions can be easily added.

Usage

Image Align is quite simple to use. Start by including the necessary headers

#include <imagealign/imagealign.h>

Next, declare the type / precision of warp, and the alignment variant you wish to use

namespace ia = imagealign;

// Use a double precision warp describing a similarity motion
// (rotation, translation and uniform scale).
typedef ia::WarpSimilarityD WarpType;

// Use Inverse Compositional algorithm for image alignment.
typedef ia::AlignInverseCompositional<WarpType> AlignType;

Given a template image and a target image you can now perform alignment

cv::Mat tpl;    // The template image
cv::Mat target; // The target image

namespace ia = imagealign;

// Instance necessary objects
WarpType w;
AlignType a;

// Prepare for alignment using 3 levels of hierarchy
a.prepare(tpl, target, w, 3);

// Perform iterative alignment over all levels in hierarchy.
a.align(w, 30, 0.003);

When alignment has finished, w will hold the warp that best aligns the template image with the target image.

Please note, Lucas-Kanade methods are locally operating methods that require a good guess of true warp parameters to converge. To provide a guess, simple adjust the parameters of w using methods such as w.setParameters() and similar before calling a.align().

Image Align comes with a couple of examples that illustrate further usage. you can find these in the examples directory. Additionally these unit tests might provide in-depth information.

Building from source

Image Alignment requires the following pre-requisites

  • CMake - for generating cross platform build files
  • OpenCV 2.x / 3.x - for image processing related functions

To build from source

  1. Point CMake to the cloned git repository
  2. Click CMake Configure
  3. Point OpenCV_DIR to the directory containing the file OpenCVConfig.cmake
  4. Activate / Deactivate IMAGEALIGN_USE_OPENMP
  5. Click CMake Generate

Although Image Alignment should build across multiple platforms and architectures, tests are carried out on these systems

  • Windows 8/10 MSVC10 / MSVC12 x64
  • OS X 10.10 XCode 7.x x64

If the build should fail for a specific platform, don't hesitate to create an issue.

References

  1. Lucas, Bruce D., and Takeo Kanade. "An iterative image registration technique with an application to stereo vision." IJCAI. Vol. 81. 1981.
  2. Baker, Simon, and Iain Matthews. "Equivalence and efficiency of image alignment algorithms." Computer Vision and Pattern Recognition, 2001. CVPR 2001. Proceedings of the 2001 IEEE Computer Society Conference on. Vol. 1. IEEE, 2001.
  3. Baker, Simon, and Iain Matthews. Lucas-Kanade 20 years on: A unifying framework: Part 1. Technical Report CMU-RI-TR-02-16, Carnegie Mellon University Robotics Institute, 2002.
  4. Baker, Simon, and Iain Matthews. Lucas-Kanade 20 years on: A unifying framework: Part 2. Technical Report CMU-RI-TR-03-01, Carnegie Mellon University Robotics Institute, 2003.
  5. Baker, Simon, et al. "Lucas-Kanade 20 years on: A unifying framework: Part 3." The Robotics Institute, Carnegie Mellon University (2003).

License

This file is part of Image Alignment.

Copyright Christoph Heindl 2015

Image Alignment is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Image Alignment is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Image Alignment.  If not, see <http://www.gnu.org/licenses/>.

image-align's People

Contributors

cheind avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

image-align's Issues

How to align this two image

I have dig your project some times. I can use your code by Cmake method and no building method both. But it give a bad result for me. Maybe this is a disturb issues but I hope to get you help still if you are available. And it very very similar your this project

If I have a such empty paper, then I write some text on it,then I deform it in Photoshop. So I get such result. Now hope this result image align that empty paper. I mean this is my expected. Actually I can do it almost by other language. I just not very familiar the OpenCV. This is my try by Mathematica

Before Align

After Align

But I have to implement it by c++ and OpenCV now. Could you give me a hand?

Build Error By CMake

I have a problem when I build this project using cmake. It shows that I need to have a OpenCVConfig.cmake file to point. But where is the suitable OpenCVConfig.cmake file? Could anyone help me? thanks!

How to use affine warp?

Hello,

Thank you for making your implementation available. The code is very well-written!

In the Readme it is stated that the library supports 2D Affine Warp. Could you please provide a usage example for that? It seems that this warp cannot be used in the same way as the other ones.

Thank you very much in advance for your response!

Best regards.

Compilation error please help me

error: call of overloaded ‘goodFeaturesToTrack(cv::Mat&, std::vector<cv::Point >&, const int&, double, int, cv::Mat, int, int, double)’ is ambiguous_
205 | cv::goodFeaturesToTrack(gray, points[1], MAX_FEATURES, 0.01, 10, cv::Mat(), 3, 0, 0.04);
| ^
In file included from /data/notebook/ZZR/lib/opencv/include/opencv2/imgproc/imgproc.hpp:48,
from /data/notebook/ZZR/code/image-align/inc/imagealign/image_pyramid.h:29,
from /data/notebook/ZZR/code/image-align/inc/imagealign/align_base.h:25,
from /data/notebook/ZZR/code/image-align/inc/imagealign/forward_additive.h:23,
from /data/notebook/ZZR/code/image-align/inc/imagealign/imagealign.h:24,
from /data/notebook/ZZR/code/image-align/examples/optical_flow.cpp:20:
/data/notebook/ZZR/lib/opencv/include/opencv2/imgproc.hpp:1959:19: note: candidate: ‘void cv::goodFeaturesToTrack(cv::InputArray, cv::OutputArray, int, double, double, cv::InputArray, int, bool, double)’
1959 | CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
| ^~~~~~~~~~~~~~~~~~~
/data/notebook/ZZR/lib/opencv/include/opencv2/imgproc.hpp:1964:19: note: candidate: ‘void cv::goodFeaturesToTrack(cv::InputArray, cv::OutputArray, int, double, double, cv::InputArray, int, int, bool, double)’
1964 | CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
| ^~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/example_optflow.dir/build.make:76: CMakeFiles/example_optflow.dir/examples/optical_flow.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:141: CMakeFiles/example_optflow.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

build fails on ubuntu 16.04

Thank you for the library, it looks fine.

Build with gcc fails on Ubuntu 16.04. Namely, this is the error:

/home/alexander/soft/image-align/image-align/tests/algorithms.cpp:217:12: error: specialization of ‘template<int W, class Scalar> struct imagealign::WarpTraits’ in different namespace [-fpermissive]
struct ia::WarpTraits<WARP_TRANSLATION_DYAMIC, Scalar> : ia::WarpTraitsForRunTimeKnownParameterCount<WARP_TRANSLATION_DYAMIC, Scalar> {};
^
In file included from /home/alexander/soft/image-align/image-align/inc/imagealign/align_base.h:23:0,
from /home/alexander/soft/image-align/image-align/inc/imagealign/forward_additive.h:23,
from /home/alexander/soft/image-align/image-align/tests/algorithms.cpp:22:
/home/alexander/soft/image-align/image-align/inc/imagealign/warp.h:74:12: error: from definition of ‘template<int W, class Scalar> struct imagealign::WarpTraits’ [-fpermissive]
struct WarpTraits {
^
/home/alexander/soft/image-align/image-align/tests/algorithms.cpp:220:11: error: specialization of ‘template<int WarpMode, class Scalar> class imagealign::Warp’ in different namespace [-fpermissive]
class ia::Warp<WARP_TRANSLATION_DYAMIC, Scalar> {
^
In file included from /home/alexander/soft/image-align/image-align/inc/imagealign/align_base.h:23:0,
from /home/alexander/soft/image-align/image-align/inc/imagealign/forward_additive.h:23,
from /home/alexander/soft/image-align/image-align/tests/algorithms.cpp:22:
/home/alexander/soft/image-align/image-align/inc/imagealign/warp.h:232:11: error: from definition of ‘template<int WarpMode, class Scalar> class imagealign::Warp’ [-fpermissive]
class Warp {
^
CMakeFiles/tests.dir/build.make:110: recipe for target 'CMakeFiles/tests.dir/tests/algorithms.cpp.o' failed
make[2]: *** [CMakeFiles/tests.dir/tests/algorithms.cpp.o] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/tests.dir/all' failed
make[1]: *** [CMakeFiles/tests.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Inclusion of the lines 214-357 of algorithms.cpp into namespace imagealign solves the issue.

Documents/L-K/image-align/tests/catch.hpp:875:17: error: ‘nullptr_t’ in namespace ‘std’ does not name a type

hello,my environment is:
(1)ubuntu 16.04
(2)gcc 5.4
(3)opencv3.4
when i input the command "make",the output is as follows:
In file included from /home/moonx/Documents/L-K/image-align/tests/warp.cpp:21:0: /home/moonx/Documents/L-K/image-align/tests/catch.hpp:875:17: error: ‘nullptr_t’ in namespace ‘std’ does not name a type inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; } ^ /home/moonx/Documents/L-K/image-align/tests/catch.hpp:996:58: error: ‘template<Catch::Internal::Operator Op, class T> bool Catch::Internal::compare’ conflicts with a previous declaration template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) { ^ /home/moonx/Documents/L-K/image-align/tests/catch.hpp:990:44: note: previous declaration ‘namespace Catch::Internal { }::compare’ template<Operator Op, typename T> bool compare( T* lhs, int rhs ) { ^ /home/moonx/Documents/L-K/image-align/tests/catch.hpp:996:53: error: ‘nullptr_t’ is not a member of ‘std’ template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) { ^ /home/moonx/Documents/L-K/image-align/tests/catch.hpp:996:70: error: expected primary-expression before ‘*’ token template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) { ^ /home/moonx/Documents/L-K/image-align/tests/catch.hpp:996:72: error: ‘rhs’ was not declared in this scope template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) { ^ /home/moonx/Documents/L-K/image-align/tests/catch.hpp:996:76: error: expression list treated as compound expression in initializer [-fpermissive] template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) { ^ /home/moonx/Documents/L-K/image-align/tests/catch.hpp:996:78: error: expected ‘;’ before ‘{’ token template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) { ^ /home/moonx/Documents/L-K/image-align/tests/catch.hpp:999:66: error: ‘std::nullptr_t’ has not been declared template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) { ^ /home/moonx/Documents/L-K/image-align/tests/catch.hpp:999:44: error: redefinition of ‘template<Catch::Internal::Operator Op, class T> bool Catch::Internal::compare(T*, int)’ template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) { ^ /home/moonx/Documents/L-K/image-align/tests/catch.hpp:990:44: note: ‘template<Catch::Internal::Operator Op, class T> bool Catch::Internal::compare(T*, int)’ previously declared here template<Operator Op, typename T> bool compare( T* lhs, int rhs ) { ^ In file included from /home/moonx/Documents/L-K/image-align/tests/warp.cpp:21:0: /home/moonx/Documents/L-K/image-align/tests/catch.hpp:1099:38: error: ‘std::__cxx11::string Catch::toString’ redeclared as different kind of symbol std::string toString( std::nullptr_t ); ^ /home/moonx/Documents/L-K/image-align/tests/catch.hpp:1096:13: note: previous declaration ‘std::__cxx11::string Catch::toString(unsigned char)’ std::string toString( unsigned char value ); ^ /home/moonx/Documents/L-K/image-align/tests/catch.hpp:1099:23: error: ‘nullptr_t’ is not a member of ‘std’ std::string toString( std::nullptr_t ); ^ In file included from /home/moonx/Documents/L-K/image-align/tests/warp.cpp:21:0: /home/moonx/Documents/L-K/image-align/tests/catch.hpp:7351:38: error: ‘std::__cxx11::string Catch::toString’ redeclared as different kind of symbol std::string toString( std::nullptr_t ) { ^ In file included from /home/moonx/Documents/L-K/image-align/tests/warp.cpp:21:0: /home/moonx/Documents/L-K/image-align/tests/catch.hpp:1222:13: note: previous declaration ‘template<class T, class Allocator> std::__cxx11::string Catch::toString(const std::vector<_Tp, _Alloc>&)’ std::string toString( std::vector<T,Allocator> const& v ) { ^ In file included from /home/moonx/Documents/L-K/image-align/tests/warp.cpp:21:0: /home/moonx/Documents/L-K/image-align/tests/catch.hpp:7351:23: error: ‘nullptr_t’ is not a member of ‘std’ std::string toString( std::nullptr_t ) { ^ CMakeFiles/tests.dir/build.make:62: recipe for target 'CMakeFiles/tests.dir/tests/warp.cpp.o' failed make[2]: *** [CMakeFiles/tests.dir/tests/warp.cpp.o] Error 1 CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/tests.dir/all' failed make[1]: *** [CMakeFiles/tests.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2
can you give me a hand about this problem?thank you very much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.