CarVac / librtprocess

A project to make RawTherapee's processing algorithms more readily available.
Other
51 stars 23 forks source link

how to use the demosaic algorithms in the library? #49

Open JVision opened 4 years ago

JVision commented 4 years ago

Hi CarVac,

I was trying to write a small test program to see how this raw processor works. However, after fumbling around for a few hours, I could not get the correct result. I must have done something wrong somewhere. Is there any guidance in this usage except the readme?

Here's what I did: step 1: filling the cfa pattern array: ` unsigned cfa[2][2];

if (bayer_pattern == RGGB) { cfa[0][0] = 0, cfa[0][1] = 1, cfa[1][0] = 1, cfa[1][1] = 2; }else if (bayer_pattern == BGGR){ cfa[0][0] = 2, cfa[0][1] = 1, cfa[1][0] = 1, cfa[1][1] = 0; }else if (bayer_pattern == GRBG) { cfa[0][0] = 1, cfa[0][1] = 0, cfa[1][0] = 2, cfa[1][1] = 1; };`

step 2: filling raw data ` int pixelsize = width height; / AmAZeMEmE wants an image as floating points and 2d array as well / const float restrict imagefloat2d = (const float )malloc(height sizeof(float )); float red1d = (float )malloc(pixelsize sizeof(float)); float restrict red2d = (float )malloc(height sizeof(float )); float green1d = (float )malloc(pixelsize sizeof(float)); float restrict green2d = (float )malloc(height sizeof(float )); float blue1d = (float )malloc(pixelsize sizeof(float)); float restrict blue2d = (float )malloc(height sizeof(float ));

/* AmAZe also wants to return floats, so heres memeory 4 it */
#ifdef _OPENMP
    #pragma omp parallel for
#endif
for (int y = 0; y < height; ++y) { 
    imagefloat2d[y] = (const float *)(src + (y*width)); 
    red2d[y] = (float *)(red1d + (y*width));
    green2d[y] = (float *)(green1d + (y*width));
    blue2d[y] = (float *)(blue1d + (y*width));
};
/* to do:
    use multithreading to solve 
*/
{
    /* run the Amaze */
    amaze_demosaic(width, height, 0, 0, width, height, imagefloat2d, red2d, green2d, blue2d, cfa, callback, 1.0, 0, 1.0f, 1.0f);
    //rcd_demosaic(width, height,imagefloat2d, red2d, green2d, blue2d, cfa, callback);

};
/* Giv back as RGB, not separate channels */
for (int i = 0; i < pixelsize; i++)
{
    int j = i * 3;
    dst[j]      = clip<uint32_t, T>((uint32_t)red1d[i]);
    dst[j + 1]  = clip<uint32_t, T>((uint32_t)green1d[i]);
    dst[j + 2]  = clip<uint32_t, T>((uint32_t)blue1d[i]);
}

`

Or even better, if there any document somewhere?

Regards JVision Capture

heckflosse commented 4 years ago

@JVision To me it looks like some negative values are converted to unsigned int before clipping them to 0. Clip the negatives to zero before converting to unsigned int should work.

JVision commented 4 years ago

Thanks. After checking that. the result is back to normal. Impressive results. Now, noticed that there are some black dots look quite unusual. is that normal? How to improve it? would like to exact the best quality from the raw data.

image

heckflosse commented 4 years ago

@JVision Usually white balancing before demosaic gives best results. Can you provide the raw file or check the output of RawTherapee?

JVision commented 4 years ago

Sure. here's the raw file. Thank you @heckflosse . LRM_20190907_150805.zip

heckflosse commented 4 years ago

@JVision Here's a screenshot of RawTherapee output using neutral profile (Amaze demosaic, no sharpening) image

And with default profile (raw ca correction, amaze demosaic, capture sharpening and auto-matched tone curve) image

JVision commented 4 years ago

Still see random black dots in the leaves. does not look natural. Any idea to improve? Thanks. image