Example usage for org.opencv.core Core log

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

Introduction

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

Prototype

public static void log(Mat src, Mat dst) 

Source Link

Usage

From source file:cx.uni.jk.mms.iaip.filter.LogOfOnePlusAbs.java

License:Open Source License

@Override
public Mat convert(Mat mat) {

    /** make absolute values and log */
    Mat tempMat = mat.clone();//  ww w .ja v a  2 s.c om
    Core.absdiff(tempMat, new Scalar(0.0d), tempMat);
    Core.add(tempMat, new Scalar(1.0d), tempMat);
    Core.log(tempMat, tempMat);

    /** find contrast and brightness to fit into 8 bit */
    MinMaxLocResult mmlr = Core.minMaxLoc(tempMat);
    double min = Math.min(mmlr.minVal, 0);
    double max = mmlr.maxVal;
    double alpha = 256.0d / (max - min);
    double beta = -min * alpha;

    /** conversion to 8 bit Mat applying contrast alpha and brightness beta */
    Mat byteMat = new MatOfByte();
    tempMat.convertTo(byteMat, CvType.CV_8U, alpha, beta);

    return byteMat;
}

From source file:cx.uni.jk.mms.iaip.filter.LogRedBlue.java

License:Open Source License

@Override
public Mat convert(Mat mat) {

    MinMaxLocResult negativeMmlr, positiveMmlr;
    double min, max, alpha, beta;

    /** negative values to positive and log */
    Mat negativeMat = mat.clone();/*  w  ww  . j a  v  a 2 s . c  om*/
    Core.min(negativeMat, new Scalar(0.0d), negativeMat);
    Core.multiply(negativeMat, new Scalar(-1.0d), negativeMat);
    Core.add(negativeMat, new Scalar(1.0d), negativeMat);
    Core.log(negativeMat, negativeMat);

    /** positve values log */
    Mat positiveMat = mat.clone();
    Core.max(positiveMat, new Scalar(0.0d), positiveMat);
    Core.add(positiveMat, new Scalar(1.0d), positiveMat);
    Core.log(positiveMat, positiveMat);

    /** find common contrast and brightness to fit into 8 bit */
    negativeMmlr = Core.minMaxLoc(negativeMat);
    positiveMmlr = Core.minMaxLoc(positiveMat);
    min = 0;
    max = Math.max(negativeMmlr.maxVal, positiveMmlr.maxVal);
    alpha = 256.0d / (max - min);
    beta = -min * alpha;

    /** conversion of both matrices to 8 bit */
    negativeMat.convertTo(negativeMat, CvType.CV_8UC1, alpha, beta);
    positiveMat.convertTo(positiveMat, CvType.CV_8UC1, alpha, beta);

    /** combine both matrices into one 8 bit 3 channel rgb picture */
    Mat tempMat = new Mat(mat.rows(), mat.cols(), CvType.CV_8UC3);
    List<Mat> mixSrcMats = new ArrayList<>();
    mixSrcMats.add(negativeMat); // 1 channel: 0
    mixSrcMats.add(positiveMat); // 1 channel: 1
    List<Mat> mixDstMats = new ArrayList<>();
    mixDstMats.add(tempMat); // 3 channels: 0-2
    MatOfInt fromToMat = new MatOfInt(0, 0 /* neg->red */, -1, 1/*
                                                                * null->green
                                                                */, 1, 2 /*
                                                                          * pos-
                                                                          * >
                                                                          * blue
                                                                          */);
    Core.mixChannels(mixSrcMats, mixDstMats, fromToMat);

    return tempMat;
}

From source file:cx.uni.jk.mms.iaip.filter.LogYellowCyan.java

License:Open Source License

@Override
public Mat convert(Mat mat) {

    MinMaxLocResult negativeMmlr, positiveMmlr;
    double min, max, alpha, beta;

    /** negative values to positive and log */
    Mat negativeMat = mat.clone();/*from  w  w  w .  j  a v  a 2  s .  com*/
    Core.min(negativeMat, new Scalar(0.0d), negativeMat);
    Core.multiply(negativeMat, new Scalar(-1.0d), negativeMat);
    Core.add(negativeMat, new Scalar(1.0d), negativeMat);
    Core.log(negativeMat, negativeMat);

    /** positve values log */
    Mat positiveMat = mat.clone();
    Core.max(positiveMat, new Scalar(0.0d), positiveMat);
    Core.add(positiveMat, new Scalar(1.0d), positiveMat);
    Core.log(positiveMat, positiveMat);

    /** find common contrast and brightness to fit into 8 bit */
    negativeMmlr = Core.minMaxLoc(negativeMat);
    positiveMmlr = Core.minMaxLoc(positiveMat);
    min = 0;
    max = Math.max(negativeMmlr.maxVal, positiveMmlr.maxVal);
    alpha = 256.0d / (max - min);
    beta = -min * alpha;

    /** conversion of both matrices to 8 bit */
    negativeMat.convertTo(negativeMat, CvType.CV_8UC1, alpha, beta);
    positiveMat.convertTo(positiveMat, CvType.CV_8UC1, alpha, beta);

    /** create additional mat for saturated green */
    Mat brightMat = negativeMat.clone();
    Core.max(negativeMat, positiveMat, brightMat);
    // Core.absdiff(brightMat, new Scalar(255.0d), brightMat);
    // Core.multiply(brightMat, new Scalar(1.0d/3.0d), brightMat);

    /** combine all matrices into one 8 bit 3 channel rgb picture */
    Mat tempMat = new Mat(mat.rows(), mat.cols(), CvType.CV_8UC3);
    List<Mat> mixSrcMats = new ArrayList<>();
    mixSrcMats.add(negativeMat); // 1 channel: 0
    mixSrcMats.add(positiveMat); // 1 channel: 1
    mixSrcMats.add(brightMat); // 1 channel: 2
    List<Mat> mixDstMats = new ArrayList<>();
    mixDstMats.add(tempMat); // 3 channels: 0-2
    MatOfInt fromToMat = new MatOfInt(0, 0 /* neg->red */, 2, 1/*
                                                               * avg->green
                                                               */, 1, 2 /*
                                                                         * pos-
                                                                         * >
                                                                         * blue
                                                                         */);
    Core.mixChannels(mixSrcMats, mixDstMats, fromToMat);

    return tempMat;
}