Example usage for org.opencv.core Mat mul

List of usage examples for org.opencv.core Mat mul

Introduction

In this page you can find the example usage for org.opencv.core Mat mul.

Prototype

public Mat mul(Mat m) 

Source Link

Usage

From source file:cx.uni.jk.mms.iaip.tools.SimpleBrushTool.java

License:Open Source License

/**
 * @param brush/*from w ww .  ja  v a 2 s.c  o m*/
 * @param inverseEffect
 * @param workMat
 */
private void applyToWorkMat(BrushModel brush, boolean inverseEffect, Mat workMat) {
    switch (brush.getMode()) {
    case SET: {
        if (!inverseEffect) {
            /** set */
            Core.add(workMat.mul(brush.getOneMinusAlphaMat()), brush.getMultipliedMat(), workMat);
        } else {
            /** clear */
            Core.multiply(workMat, brush.getOneMinusAlphaMat(), workMat);
        }
    }
        break;
    case ADD: {
        if (!inverseEffect) {
            /** add */
            Core.add(workMat, brush.getMultipliedMat(), workMat);
        } else {
            /** subtract */
            Core.subtract(workMat, brush.getMultipliedMat(), workMat);
        }
    }
        break;
    case MULTIPLY: {
        if (!inverseEffect) {
            /** multiply */
            Core.add(workMat.mul(brush.getOneMinusAlphaMat()), workMat.mul(brush.getMultipliedMat(), 0.01d),
                    workMat);
        } else {
            /** multiply by 1/alpha. trick: divide twice ;) */
            Core.divide(1.0d, workMat, workMat);
            Core.add(workMat.mul(brush.getOneMinusAlphaMat()), workMat.mul(brush.getMultipliedMat(), 0.01d),
                    workMat);
            Core.divide(1.0d, workMat, workMat);
        }
    }
        break;
    default:
        /** do nothing */
    }
}

From source file:info.jmfavreau.bifrostcore.imageprocessing.ImageToColor.java

License:Open Source License

private Mat extract_main_region(Mat img, Mat roi) {
    Mat hist = new Mat();
    int h_bins = 30;
    int s_bins = 32;
    MatOfInt mHistSize = new MatOfInt(h_bins, s_bins);

    MatOfFloat mRanges = new MatOfFloat(0, 179, 0, 255);
    MatOfInt mChannels = new MatOfInt(0, 1);

    Imgproc.calcHist(Arrays.asList(img), mChannels, roi, hist, mHistSize, mRanges, false);

    Core.normalize(hist, hist, 0, 255, Core.NORM_MINMAX, -1, new Mat());

    Mat backproj = new Mat();
    Imgproc.calcBackProject(Arrays.asList(img), mChannels, hist, backproj, mRanges, 1);

    Log.w("bifrostcore",
            "Number of pixels in the biggest region: " + String.valueOf(Core.countNonZero(backproj)));
    return backproj.mul(roi);
}

From source file:org.openpnp.vision.FluentCv.java

License:Open Source License

public static double calculatePsnr(Mat I1, Mat I2) {
    Mat s1 = new Mat();
    Core.absdiff(I1, I2, s1); // |I1 - I2|
    s1.convertTo(s1, CvType.CV_32F); // cannot make a square on 8 bits
    s1 = s1.mul(s1); // |I1 - I2|^2

    Scalar s = Core.sumElems(s1); // sum elements per channel

    double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels

    if (sse <= 1e-10) // for small values return zero
        return 0;
    else {//from  w  w  w.  j a v a  2s . com
        double mse = sse / (double) (I1.channels() * I1.total());
        double psnr = 10.0 * Math.log10((255 * 255) / mse);
        return psnr;
    }
}