Example usage for org.opencv.core Core LUT

List of usage examples for org.opencv.core Core LUT

Introduction

In this page you can find the example usage for org.opencv.core Core LUT.

Prototype

public static void LUT(Mat src, Mat lut, Mat dst) 

Source Link

Usage

From source file:imageprocess.HistogramProcessor.java

public static Mat applyLookUp(Mat image, Mat lookup) {
    // Set output image (always 1-channel)
    Mat result = new Mat(image.rows(), image.cols(), CV_8U);

    //        for (int i = 0; i < image.cols(); i++) {
    //            for (int j = 0; j < image.rows(); j++) {
    //                double[] data = image.get(j, i);
    //                double newIntensity = lookup.get((int)data[0], 0)[0];
    //                result.put(j, i, newIntensity);
    //            }
    //        }/*w  w w  .java 2 s . com*/
    Core.LUT(image, lookup, result);
    return result;
}

From source file:uk.ac.horizon.artcodes.process.HlsEditImageProcessor.java

License:Open Source License

@Override
public void process(ImageBuffers buffers) {
    if (this.hueShift != 0 || this.lightnessAddition != 0 || this.saturationAddition != 0) {
        // Convert to HLS:
        Mat threeChannelBuffer = buffers.getImageInBgr();
        Imgproc.cvtColor(threeChannelBuffer, threeChannelBuffer, Imgproc.COLOR_BGR2HLS);

        // Apply look-up-table:
        Core.LUT(threeChannelBuffer, lut, threeChannelBuffer);

        // Convert back to BGR:
        Imgproc.cvtColor(threeChannelBuffer, threeChannelBuffer, Imgproc.COLOR_HLS2BGR);
        buffers.setImage(threeChannelBuffer);
    }//from   w w w. j  a  v a 2  s.  c  o  m
}

From source file:uk.ac.horizon.artcodes.process.WhiteBalanceImageProcessor.java

License:Open Source License

@Override
public void process(ImageBuffers buffers) {
    Mat image = buffers.getImageInBgr();
    if (this.histograms == null) {
        this.setup();
    }/*  w  ww.  j  av a  2s  .c  o  m*/
    List<Mat> listOfMat = new ArrayList<>();
    listOfMat.add(image);

    // create a histogram for each channel:
    // (oddly it seems ~10x faster to do 3 channels separately rather than all 3 in one calcHist call)
    for (int channel = 0; channel < image.channels(); ++channel) {
        Imgproc.calcHist(listOfMat, channels[channel], emptyMatMask, histograms[channel], size, range);
    }

    float[] a = new float[image.channels()];
    float[] b = new float[image.channels()];

    final int desiredHistogramBufferSize = histograms[0].rows() * histograms[0].cols()
            * histograms[0].channels();
    float[] pixelHistogramBuffer = new float[desiredHistogramBufferSize];

    // get the values to remap the histograms:
    for (int channel = 0; channel < image.channels(); ++channel) {
        histograms[channel].get(0, 0, pixelHistogramBuffer);
        getHistogramRemap(pixelHistogramBuffer, desiredHistogramBufferSize, image.total(), a, channel, b,
                channel);
    }

    // Use a Look Up Table to re-map values
    // (it's a lot faster to workout and save what the 256 possible values transform into
    // than to do the math image.cols*rows times)

    if (lut == null) {
        lut = new Mat(1, 256, CvType.CV_8UC3);
    }
    final int lutSize = lut.cols() * lut.rows() * lut.channels();
    int lutIndex = -1;
    if (lutBufferArray == null || lutBufferArray.length != lutSize) {
        lutBufferArray = new byte[lutSize];
    }
    for (int i = 0; i < 256; ++i) {
        for (int channel = 0; channel < image.channels(); ++channel) {
            lutBufferArray[++lutIndex] = (byte) Math.min(Math.max(a[channel] * ((i) - b[channel]), 0), 255);
        }
    }
    lut.put(0, 0, lutBufferArray);
    Core.LUT(image, lut, image);
    buffers.setImage(image);
}