{"action":"opened","issue":{"url":"https://api.github.com/repos/Itseez/opencv/issues/4230","labels_url":"https://api.github.com/repos/Itseez/opencv/issues/4230/labels{/name}","comments_url":"https://api.github.com/repos/Itseez/opencv/issues/4230/comments","events_url":"https://api.github.com/repos/Itseez/opencv/issues/4230/events","html_url":"https://github.com/Itseez/opencv/issues/4230","id":96790235,"number":4230,"title":"improvement in  image registration using ECC algorithm.","user":{"login":"epitalon","id":3924697,"avatar_url":"https://avatars.githubusercontent.com/u/3924697?v=3","gravatar_id":"","url":"https://api.github.com/users/epitalon","html_url":"https://github.com/epitalon","followers_url":"https://api.github.com/users/epitalon/followers","following_url":"https://api.github.com/users/epitalon/following{/other_user}","gists_url":"https://api.github.com/users/epitalon/gists{/gist_id}","starred_url":"https://api.github.com/users/epitalon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/epitalon/subscriptions","organizations_url":"https://api.github.com/users/epitalon/orgs","repos_url":"https://api.github.com/users/epitalon/repos","events_url":"https://api.github.com/users/epitalon/events{/privacy}","received_events_url":"https://api.github.com/users/epitalon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-23T11:18:02Z","updated_at":"2015-07-23T11:18:02Z","closed_at":null,"body":"My purpose is to compare two successive images in time of a growing set of bacteria colonies\r\nFor that purpose, I tested OpenCV image registration using ECC algorithm.\r\nI suggest one improvement, already discussed with the original author of this module: Georgios Evangelidis.\r\n\r\nsource code is in opencv/modules/video/src/ecc.cpp\r\n\r\nI used an euclidean transformation (motionType == MOTION_EUCLIDEAN)\r\nWhen updating the warping matrix in the function \"update_warping_matrix_ECC()\", source code below computes angle new_theta from arc cosinus of mapPtr[0] (which is the cosinus of previous angle theta)\r\n    if (motionType == MOTION_EUCLIDEAN) {\r\n        double new_theta = updatePtr[0];\r\n        if (mapPtr[3]>0)\r\n            new_theta += acos(mapPtr[0]);\r\n\r\n        if (mapPtr[3]<0)\r\n            new_theta -= acos(mapPtr[0]);\r\n\r\nIt is better to compute it from sinus : since angle theta is small, its cosinus is close to 1 and departure from 1 is small of an order of theta squared.\r\nTherefore, cosinus value has some rounding error.\r\nComputing acos(cosinus) causes some rounding error on new_theta. \r\n\r\nI suggest the following code:\r\n    if (motionType == MOTION_EUCLIDEAN) {\r\n        double new_theta = updatePtr[0];\r\n        new_theta += asin(mapPtr[3]);\r\n\r\nwhich is also simpler;\r\nNotice that mapPtr[3] is the sinus of previous angle theta.\r\nI tested this change on my application. The accuracy in overlapping images is much better.\r\n\r\nActually, in my project, I used the orginal source code of Georgios Evangelidis, available at http://xanthippi.ceid.upatras.gr/people/evangelidis/ecc/ and liked it with OpenCV 2.0. But source code in OpenCV 3.0 has not evolved much. so that I am pretty sure about the code change that I suggest above.\r\n\r\nGood luck.\r\nepitalon@orange.fr"}}