Example usage for org.opencv.core Mat setTo

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

Introduction

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

Prototype

public Mat setTo(Mat value, Mat mask) 

Source Link

Usage

From source file:qupath.opencv.processing.OpenCVTools.java

License:Open Source License

public static void watershedDistanceTransformSplit(Mat matBinary, int maxFilterRadius) {
    Mat matWatershedSeedsBinary;

    // Create a background mask
    Mat matBackground = new Mat();
    Core.compare(matBinary, new Scalar(255), matBackground, Core.CMP_NE);

    // Separate by shape using the watershed transform
    Mat matDistanceTransform = new Mat();
    Imgproc.distanceTransform(matBinary, matDistanceTransform, Imgproc.CV_DIST_L2,
            Imgproc.CV_DIST_MASK_PRECISE);
    // Find local maxima
    matWatershedSeedsBinary = new Mat();
    Imgproc.dilate(matDistanceTransform, matWatershedSeedsBinary,
            OpenCVTools.getCircularStructuringElement(maxFilterRadius));
    Core.compare(matDistanceTransform, matWatershedSeedsBinary, matWatershedSeedsBinary, Core.CMP_EQ);
    matWatershedSeedsBinary.setTo(new Scalar(0), matBackground);
    // Dilate slightly to merge nearby maxima
    Imgproc.dilate(matWatershedSeedsBinary, matWatershedSeedsBinary,
            OpenCVTools.getCircularStructuringElement(2));

    // Create labels for watershed
    Mat matLabels = new Mat(matDistanceTransform.size(), CvType.CV_32F, new Scalar(0));
    labelImage(matWatershedSeedsBinary, matLabels, Imgproc.RETR_CCOMP);

    // Remove everything outside the thresholded region
    matLabels.setTo(new Scalar(0), matBackground);

    // Do watershed
    // 8-connectivity is essential for the watershed lines to be preserved - otherwise OpenCV's findContours could not be used
    ProcessingCV.doWatershed(matDistanceTransform, matLabels, 0.1, true);

    // Update the binary image to remove the watershed lines
    Core.multiply(matBinary, matLabels, matBinary, 1, matBinary.type());
}

From source file:simeav.Utils.java

public static Mat borrarMascara(Mat imagenOriginal, Mat mascara) {
    Mat imGrises = new Mat();
    Imgproc.cvtColor(imagenOriginal, imGrises, Imgproc.COLOR_BGR2GRAY);
    Imgproc.threshold(imGrises, imGrises, 200, 250, Imgproc.THRESH_BINARY_INV);
    return imGrises.setTo(new Scalar(0, 0, 0), mascara);
}