Example usage for org.opencv.core Mat submat

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

Introduction

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

Prototype

public Mat submat(int rowStart, int rowEnd, int colStart, int colEnd) 

Source Link

Usage

From source file:uk.ac.horizon.artcodes.process.TileThresholder.java

License:Open Source License

@Override
public void process(ImageBuffers buffers) {
    Mat image = buffers.getImageInGrey();
    Imgproc.GaussianBlur(image, image, new Size(5, 5), 0);

    if (display == Display.greyscale) {
        Imgproc.cvtColor(image, buffers.getOverlay(false), Imgproc.COLOR_GRAY2BGRA);
    }//from  ww  w .  j a va2  s .co m

    if (!buffers.hasDetected()) {
        tiles = (tiles % 9) + 1;
    }
    final int tileHeight = (int) image.size().height / tiles;
    final int tileWidth = (int) image.size().width / tiles;

    // Split image into tiles and apply process on each image tile separately.
    for (int tileRow = 0; tileRow < tiles; tileRow++) {
        final int startRow = tileRow * tileHeight;
        int endRow;
        if (tileRow < tiles - 1) {
            endRow = (tileRow + 1) * tileHeight;
        } else {
            endRow = (int) image.size().height;
        }

        for (int tileCol = 0; tileCol < tiles; tileCol++) {
            final int startCol = tileCol * tileWidth;
            int endCol;
            if (tileCol < tiles - 1) {
                endCol = (tileCol + 1) * tileWidth;
            } else {
                endCol = (int) image.size().width;
            }

            final Mat tileMat = image.submat(startRow, endRow, startCol, endCol);
            Imgproc.threshold(tileMat, tileMat, 127, 255, Imgproc.THRESH_OTSU);
            tileMat.release();
        }
    }

    if (display == Display.threshold) {
        Imgproc.cvtColor(image, buffers.getOverlay(false), Imgproc.COLOR_GRAY2BGRA);
    }

    buffers.setImage(image);
}