opencv3.0 illuminationChange Issue and bug fix [closed]

asked 2014-08-22 23:30:53 -0600

vsooda gravatar image

updated 2014-08-23 00:14:21 -0600

Hi,

I have find a bug in illuminationChange sample. when I use the illuminationchange sample code to test the function.The result is wrong. image description

I have tried to fix the bug and it looked as if I were succeeding. The result is as follow: image description

The bug is in the file sources\modules\photo\src\seamless_cloning.hpp (line 549 and 553), in the functon Cloning::illum_change. The magnitude of the place outside of mask is [0, 0, 0] and if calucalate: pow(mag, -1 * beta, multy_temp); The value of multy_temp will be "-1.#IND".

what I have do is do filter the mag value as follow:

for (int i = 0; i < mag.cols; i++)
    {
        for (int j = 0; j < mag.rows; j++)
        {
            if (mag.at<cv::Vec3f>(j, i)[0] == 0)
                mag.at<cv::Vec3f>(j, i)[0] = 1e-8;

            if (mag.at<cv::Vec3f>(j, i)[1] == 0)
                mag.at<cv::Vec3f>(j, i)[1] = 1e-8;

            if (mag.at<cv::Vec3f>(j, i)[2] == 0)
                mag.at<cv::Vec3f>(j, i)[2] = 1e-8;
        }
    }

This is my solutionn. There must be some better methods to fix the bug.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-11-13 12:50:05.957070

Comments

1

could you add a link to the sample ? can't find it.

berak gravatar imageberak ( 2014-08-23 01:17:42 -0600 )edit

And provide a fix if you find one through this topic! Thanks in advance!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-23 04:31:57 -0600 )edit

@berak , There is bug in the api illuminationChange" not the sample. The api can find in http://docs.opencv.org/trunk/modules/photo/doc/cloning.html . The problem is in the Cloning::illum_change functions. https://github.com/Itseez/opencv/blob/master/modules/photo/src/seamless_cloning.hpp

vsooda gravatar imagevsooda ( 2014-08-23 08:41:09 -0600 )edit
1

@StevenPuttemans . Adding the code in my question after line 544 can fix the bug. https://github.com/Itseez/opencv/blob/master/modules/photo/src/seamless_cloning.hpp

vsooda gravatar imagevsooda ( 2014-08-23 08:44:51 -0600 )edit

@vsooda, i know, just wanted to play around with it ;)

you made it pretty obvious already. wherever mag is 0, pow(mag, -something) is INF. well understood.

berak gravatar imageberak ( 2014-08-23 09:30:27 -0600 )edit

@berak . Thank you. This is my first time to report bug. The test data are in this page https://github.com/Itseez/opencv_extra/tree/master/testdata/cv/cloning/Illumination_Change . You can simplely read the source image and mask, then call the api illuminationChange. And the show the result. You can also see the test code in https://github.com/Itseez/opencv/blob/master/modules/photo/test/test_cloning.cpp (TEST(Photo_SeamlessClone_illuminationChange, regression))

vsooda gravatar imagevsooda ( 2014-08-23 10:07:58 -0600 )edit

@vsooda, thanks a lot, i somehow missed that.

(and no fear, even if you're new to it, all of them quite good questions, imho, keep on with it ;)

berak gravatar imageberak ( 2014-08-23 10:17:53 -0600 )edit

@berak, thank you. I am using opencv for my researsh recently. If I find any other bug, I will report and fix it.

vsooda gravatar imagevsooda ( 2014-08-23 20:28:08 -0600 )edit