Ask Your Question

Pou Belle's profile - activity

2019-04-15 04:44:34 -0600 marked best answer Focus stacking with C++ are not the same as in Java

Firstly, sorry for my english, it's not my mother tongue I have to implement a system of focus stacking in a software, I found an algorithm on Github in Java and I transcribed it in C ++ but the result is not as good. I use OpenCV Thank you in advance

PS : if you have a better algorithm in C ++, I do not refuse ^^

C++ result : https://image.noelshack.com/fichiers/... Java result : https://image.noelshack.com/fichiers/...

Java code : https://github.com/LucasLelaidier/Foc...

My code :

FocusStacking::FocusStacking(vector<Mat> img) : m_img(img)
{

}

Mat FocusStacking::laplacien(Mat image)
{
    int kernel_size = 5;
    int blur_size = 5;

    Mat gray;
    cvtColor(image, gray, COLOR_BGR2GRAY);

    Mat gauss;
    Size size(blur_size, blur_size);
    GaussianBlur(gray, gauss, size, 0);

    Mat laplace;
    Laplacian(gauss, laplace, CV_64F, kernel_size, 1, 0);

    Mat absolute;
    convertScaleAbs(laplace, absolute);

    return absolute;
}

Mat FocusStacking::work()
{
    vector<Mat> laps;
    for (unsigned i = 0 ; i < m_img.size() ; i++)
    {
        laps.push_back(laplacien(m_img[i]));
    }
    Mat stack = Mat(laps[0].size(), m_img[0].type(), double(0));

    int index;
    int indexValue;
    for(int y = 0 ; y < laps[0].cols ; y++)
    {
        for(int x = 0 ; x < laps[0].rows ; x++)
        {
            index = -1;
            indexValue = -1;
            for(unsigned int i = 0 ; i < laps.size(); i++)
            {
                if(indexValue < 0 || laps[i].at<Vec3b>(x,y)[0] > indexValue)
                {
                    indexValue = laps[i].at<Vec3b>(x,y)[0];
                    index = static_cast<int>(i);
                }
            }
            stack.at<Vec3b>(x,y) = m_img[static_cast<unsigned>(index)].at<Vec3b>(x,y);
        }
    }
    return stack;
}
2019-04-15 04:44:10 -0600 received badge  Self-Learner
2019-04-14 08:07:33 -0600 received badge  Student (source)
2019-04-14 08:00:07 -0600 answered a question Focus stacking with C++ are not the same as in Java

Thanks you berak, It was necessary to change Vec3b into uchar in one place

2019-04-12 08:28:26 -0600 commented question Focus stacking with C++ are not the same as in Java

"please be more explicit" You can see an example of the result using Java and C++ in the post (both links to the images

2019-04-12 08:25:34 -0600 commented question Focus stacking with C++ are not the same as in Java

"please be more explicit" You can see an example of the result using Java and C++ in the post (both links to the images

2019-04-12 08:25:24 -0600 commented question Focus stacking with C++ are not the same as in Java

"please be more explicit" You can see an example of the result using Java and C++ in the post (both links to the images

2019-04-12 08:25:10 -0600 commented question Focus stacking with C++ are not the same as in Java

please be more explicit You can see an example of the result using Java and C++ in the post (both links to the images)

2019-04-12 08:25:01 -0600 commented question Focus stacking with C++ are not the same as in Java

please be more explicit You can see an example of the result using Java and C++ in the post (both links to the images)

2019-04-12 08:24:44 -0600 commented question Focus stacking with C++ are not the same as in Java

please be more explicit You can see an example of the result using Java and C++ in the post (both links to the images)

2019-04-12 08:24:35 -0600 commented question Focus stacking with C++ are not the same as in Java

please be more explicit You can see an example of the result using Java and C++ in the post (both links to the images)

2019-04-12 01:32:01 -0600 asked a question Focus stacking with C++ are not the same as in Java

Focus stacking with C++ are not the same as in Java Firstly, sorry for my english, it's not my mother tongue I have to i