Gregjksmith / Single-Image-Example-Based-Super-Resolution

Single image example-based super resolution. Improves the spatial and temporal resolution of an image using a direct mapping of LR HR patch pairs. C++, openCV.
MIT License
33 stars 8 forks source link

Paper #1

Open kealennieh opened 6 years ago

kealennieh commented 6 years ago

Hi, dear Author,

Thanks for your work. With adequent APIs and explanations, yours codes are so great! Here, I have a tiny question. Which paper can I find this algorithm? "Single image example-based Super-resolution using direct mapping of self-examples"? To be frank, I cannot find this paper. Thanks in advance!

Besh wishes, Kealen

Gregjksmith commented 6 years ago

Kealen, thanks, I'm glad you liked it.

The paper used was "Single-image super-resolution via linear mapping of interpolated self-examples", and I extended it to use rational wavelets. Citations are now in the source in readme.

Greg.

kealennieh commented 6 years ago

Dear Greg,

Thanks for your reply. About the code, I've found a tiny question that the first super-resolve algorithm cannot function well in Debug, thought it can work fine in Release. I've tried it in both VS2012 and VS2015. And they show the same result. I don't get it. Thanks in advance.

Best wishes, Kealen

Gregjksmith commented 6 years ago

Kealen,

I don't get it either, it's a problem with openCV. Some functions in openCV will not work if you're in debug. I usually just copy over the release configs to my custom configs. If you ever figure out why it does that, I would like to know.

Greg.

kealennieh commented 6 years ago

Dear Greg,

Thanks for your information. And the problem has been found. Actually, it's a problem with your OPM procedure on dictionary creation.

    ....
    /*iterate through each overlapping patch*/
    int patchIndex = 0;
#pragma omp parallel for
    for (int i = 0; i < ny - patchSize; i++)
    {
        for (int j = 0; j < nx - patchSize; j++)
        {
            int pixelIndex = 0;
            for (int x = 0; x < patchSize; x++)
            {
                for (int y = 0; y < patchSize; y++)
                {
                    int sampleX = (x + i);
                    int sampleY = (y + j);
                    float sampleLow = (float)imageFiltered.at<float>(sampleX, sampleY);
                    float sampleHigh = (float)inputImage.at<float>(sampleX, sampleY);

                    /*append to dictionaries*/
                    dLow->at<float>(patchIndex, pixelIndex) = sampleLow;
                    dHigh->at<float>(patchIndex, pixelIndex) = sampleHigh;
                    pixelIndex++;
                }
            }
            patchIndex++;
        }
    }
    ...

You can delete #pragma omp parallel for , and it will work out in Debug. In order to use OMP, I made some modifications. And here's my suggestion as follows.

    ...
    ///*iterate through each overlapping patch*/
    // int patchIndex = 0;
    int row = ny-pathSize;
    int col = nx-patchSize;
#pragma omp parallel for
    for (int i = 0; i < row*col; i++)
    {
        int r = i/col;
        int c = i%col;
        int patchIndex = i;

        int pixelIndex = 0;
        for (int x = 0; x < patchSize; x++)
        {
            for (int y = 0; y < patchSize; y++)
            {
                int sampleX = (x + r);
                int sampleY = (y + c);
                float sampleLow = (float)imageFiltered.at<float>(sampleX, sampleY);
                float sampleHigh = (float)inputImage.at<float>(sampleX, sampleY);

                /*append to dictionaries*/
                dLow->at<float>(patchIndex, pixelIndex) = sampleLow;
                dHigh->at<float>(patchIndex, pixelIndex) = sampleHigh;
                pixelIndex++;
            }
        }   
    }
   ...

Yours, Kealen

Gregjksmith commented 6 years ago

ok, thanks for looking into it. I'll commit a fix sometime soon.