private static final LookupTableJAI createContrastLUT(float K,
                                                          int numBands) {
        byte[] contrastTable = new byte[256];

        double p = 0.43F;

        // Generate the LUT to be applied to the color band(s).
        for(int i = 0; i < 256; i++) {
            float j = (float)(i - 127.5F)/255.0F;
            float f = 0.0F;
            if(j < 0.0F) {
                f = (float)(-p*Math.pow(-j/p, K));
            } else if(j > 0.0F) {
                f = (float)(p*Math.pow(j/p, K));
            }
            int val = (int)(f*255.0F + 127.5F);
            if(val < 0) {
                contrastTable[i] = 0;
            } else if(val > 255) {
                contrastTable[i] = (byte)255;
            } else {
                contrastTable[i] = (byte)(val & 0x000000ff);
            }
        }

        // Allocate LUT memory.
        byte[][] data = new byte[numBands][];

        // Set all LUT color bands to the same previously calculated table.
        // If alpha is present, set the LUT for it to a ramp.
        if(numBands % 2 == 1) { // no alpha channel present
            for(int i = 0; i < numBands; i++) {
                data[i] = contrastTable;
            }
        } else { // alpha channel present
            for(int i = 0; i < numBands - 1; i++) {
                data[i] = contrastTable;
            }
            data[numBands-1] = new byte[256];
            byte[] b = data[numBands-1];
            for(int i = 0; i < 256; i++) {
                b[i] = (byte)i;
            }
        }

        return new LookupTableJAI(data);
    }