Question

I have a few Color lookup tables that looks like this. Is there a guide that i can use to program an image filter using color lookup table in Nokia Imaging SDK. I am switching to Nokia Imaging SDK because i have been told that it is more optimized and accurate.

currently the code looks like this.

public WriteableBitmap Process()
    {
        int width = inputimage.PixelWidth;
        int height = inputimage.PixelHeight;

        int[] pixelArray = this.inputimage.Pixels;

        for (int i = 0; i < width; i++)
        {           

            for (int j = 0; j < height; j++)
            {
                // Extract color components
                var c = inputimage.GetPixel(i,j);
                var b = c.B;
                var g = c.G;
                var r = c.R;
                var a = c.A;

                int blockBlue = b / 4;
                int blockGreen = g / 4;
                int blockRed = r / 4;

                int right = blockBlue % 8;
                int down = blockBlue / 8;

                int px = right * 64 + blockRed;
                int py = down * 64 + blockGreen;


                Color clr = LookUpTable.GetPixel(px, py);

                // Set result color
                inputimage.SetPixel(i, j, clr);                    
            }
        }

        return wBmp;
    }
Was it helpful?

Solution

The CustomFilterBase or CustomEffectBase base classes will let you translate this loop almost directly.

I'm not sure if you'll get any better performance or accuracy for this RGB LUT alone, as it is already pretty simple. The main things I see are the GetPixel/SetPixel which you really should change to direct array accesses instead. Also avoid the Color class. Ideally read and write 32 bit uint values, mask and shift out the parts.

The second improvement would be if you can constrain the function stored in the LUT.

If it can be expressed as individual red, green and blue LUTs, you can use the CurvesFilter class in the Imaging SDK. Even without the SDK this will speed things up as those tables can live closer to the CPU in the L1 or L2 cache.

Edit: The final version of Nokia Imaging SDK 1.2 (soon to be released) has some precision improvements that may be relevant as well, btw.

Edit 2: You should be able to access Pixels with something like the following. (Haven't tested the casts fully. C# is picky about signed-ness.)

// in for loop..

var uintColor = (uint)wb.Pixels[i];
var a = (byte)((uintColor >> 24) & 255);
var r = (byte)((uintColor >> 16) & 255);
var g = (byte)((uintColor >> 8) & 255);
var b = (byte)((uintColor) & 255);

// ..do something..

wb.Pixels[i] = (int)(b | (g << 8) | (r << 16) | (a << 24));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top