use of org.bytedeco.opencv.opencv_core.Scalar in project qupath by qupath.
the class OpenCVTools method fillSmallHoles.
/**
* Fill holes in a binary image (1-channel, 8-bit unsigned) with an area <= maxArea.
*
* @param matBinary
* @param maxArea
*/
public static void fillSmallHoles(Mat matBinary, double maxArea) {
Mat matHoles = new Mat();
invertBinary(matBinary, matHoles);
MatVector contours = new MatVector();
Mat hierarchy = new Mat();
opencv_imgproc.findContours(matHoles, contours, hierarchy, opencv_imgproc.RETR_CCOMP, opencv_imgproc.CHAIN_APPROX_SIMPLE);
Scalar color = Scalar.WHITE;
int ind = 0;
Point offset = new Point(0, 0);
Indexer indexerHierarchy = hierarchy.createIndexer();
for (int c = 0; c < contours.size(); c++) {
Mat contour = contours.get(c);
// TODO: Check hierarchy indexing after switch to JavaCPP!!
if (indexerHierarchy.getDouble(0, ind, 3) >= 0 || opencv_imgproc.contourArea(contour) > maxArea) {
ind++;
continue;
}
opencv_imgproc.drawContours(matBinary, contours, c, color, -1, opencv_imgproc.LINE_8, null, Integer.MAX_VALUE, offset);
ind++;
}
}
Aggregations