List of usage examples for org.opencv.core Core multiply
public static void multiply(Mat src1, Scalar src2, Mat dst, double scale, int dtype)
From source file:qupath.opencv.processing.OpenCVTools.java
License:Open Source License
public static void watershedDistanceTransformSplit(Mat matBinary, int maxFilterRadius) { Mat matWatershedSeedsBinary;// w ww . j a va 2s. 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
/** * Apply a watershed transform to refine a binary image, guided either by a distance transform or a supplied intensity image. * // w w w .j ava 2s. 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()); }