Example usage for org.opencv.core Core compare

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

Introduction

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

Prototype

public static void compare(Mat src1, Scalar src2, Mat dst, int cmpop) 

Source Link

Usage

From source file:org.pattern.utils.MatUtils.java

/**
 * Compares if two image matrices contains similar data.
 * //from   www.ja  v  a2s.  co  m
 * @param mat1
 * @param mat2
 * @return 
 */
public static boolean similar(Mat mat1, Mat mat2) {

    if (mat1.cols() != mat2.cols() || mat1.rows() != mat2.rows()) {
        return false;
    }

    Mat mat = new Mat();
    Core.compare(mat1, mat2, mat, Core.CMP_EQ);
    return Core.countNonZero(mat) != 0;
}

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

License:Open Source License

public static void watershedDistanceTransformSplit(Mat matBinary, int maxFilterRadius) {
    Mat matWatershedSeedsBinary;/* w w  w  .  ja  va 2  s.com*/

    // 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:qupath.opencv.processing.OpenCVTools.java

License:Open Source License

public static void invertBinary(Mat matBinary, Mat matDest) {
    Core.compare(matBinary, new Scalar(0), matDest, Core.CMP_EQ);
}

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

License:Open Source License

/**
 * Apply a watershed transform to refine a binary image, guided either by a distance transform or a supplied intensity image.
 * /*from w  w  w  .j ava 2  s .  c  o m*/
 * @param matBinary - thresholded, 8-bit unsigned integer binary image
 * @param matIntensities - optional intensity image for applying watershed transform; if not set, distance transform of binary will be used
 * @param threshold
 */
public static void watershedIntensitySplit(Mat matBinary, Mat matWatershedIntensities, double threshold,
        int maximaRadius) {

    // Separate by intensity using the watershed transform
    // Find local maxima
    Mat matTemp = new Mat();

    Mat strel = getCircularStructuringElement(maximaRadius);
    Imgproc.dilate(matWatershedIntensities, matTemp, strel);
    Core.compare(matWatershedIntensities, matTemp, matTemp, Core.CMP_EQ);
    Imgproc.dilate(matTemp, matTemp, getCircularStructuringElement(2));
    Mat matWatershedSeedsBinary = matTemp;

    // Remove everything outside the thresholded region
    Core.min(matWatershedSeedsBinary, matBinary, matWatershedSeedsBinary);

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

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

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