Example usage for org.opencv.core Core max

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

Introduction

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

Prototype

public static void max(Mat src1, Scalar src2, Mat dst) 

Source Link

Usage

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();//from w w w  .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  av  a2  s .  co  m
    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;
}