LUT Look Up Table

Discussions about image processing and document imaging.
Post Reply
fnaudeau
Posts: 14
Joined: Thu Dec 25, 2014 7:25 pm

LUT Look Up Table

Post by fnaudeau » Thu Aug 18, 2016 3:31 pm

Hello,

Is there a way to apply a LUT ( Look Up Table ) by passing Red, Green and Blue arrays ?
I didn't find a function to achieve that directly.

Many thanks.
Kind regards,
Frédéric

fnaudeau
Posts: 14
Joined: Thu Dec 25, 2014 7:25 pm

Re: LUT Look Up Table

Post by fnaudeau » Mon Jan 02, 2017 12:58 pm

Hello,

Here is my proposal solution to code a LUT function.
Tell me if you find an optimization on it:

Code: Select all

public void ApplyLut(int[] lookupTableRed, int[] lookupTableGreen, int[] lookupTableBlue)
{                        
    int imageWidth = _gdPictureImaging.GetWidth(_image);
    int imageHeight = _gdPictureImaging.GetHeight(_image);

    byte[] bytes = new byte[imageWidth * imageHeight * 4];
    _gdPictureImaging.GetPixelArrayByte(_image, ref bytes, 0, 0, imageWidth, imageHeight);
            
    for (int x = 0; x < imageWidth  - 1; x++) 
    {
        for (int y = 0; y < imageHeight - 1; y++)
        {
            int blueIndex  = y * 4 * imageWidth + x * 4;
            int greenIndex = blueIndex + 1;
            int redIndex   = blueIndex + 2;

            byte blueValue  = bytes[blueIndex];
            byte greenValue = bytes[greenIndex];
            byte redValue   = bytes[redIndex];

            bytes[blueIndex]  = (byte)lookupTableBlue[blueValue];
            bytes[greenIndex] = (byte)lookupTableGreen[greenValue];
            bytes[redIndex]   = (byte)lookupTableRed[redValue];
        }
    }

    _gdPictureImaging.SetPixelArrayByte(_image, bytes, 0, 0, imageWidth, imageHeight);
}

User avatar
Loïc
Site Admin
Posts: 5593
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: LUT Look Up Table

Post by Loïc » Tue Jan 03, 2017 6:47 pm

Hi,

You can increase speed by using parallelization: https://msdn.microsoft.com/en-us/librar ... .110).aspx

You can increase speed + memory usage using unsafe block, getting image back buffer and also using parallelization. (more tricky since you will have to handle the pixel format of the bitmap).

I forgot to tell you that your request is into our whist list. We should implement such feature this year.

Kind regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests