Skip to content

Commit e29ec40

Browse files
committed
No-argument thresold() using Otsu's method
This should provide sensible behavior in circumstances where manually choosing a threshold is undesirable.
1 parent 157888a commit e29ec40

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎src/gab/opencv/OpenCV.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,17 @@ public void threshold(int threshold){
844844
Imgproc.threshold(getCurrentMat(), getCurrentMat(), threshold, 255, Imgproc.THRESH_BINARY);
845845
}
846846

847+
/**
848+
* Apply a global threshold to the image. The threshold is determined by Otsu's method, which
849+
* attempts to divide the image at a threshold which minimizes the variance of pixels in the black
850+
* and white regions.
851+
*
852+
* See: https://en.wikipedia.org/wiki/Otsu's_method
853+
*/
854+
public void threshold() {
855+
Imgproc.threshold(getCurrentMat(), getCurrentMat(), 0, 255, Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU);
856+
}
857+
847858
/**
848859
* Apply an adaptive threshold to an image. Produces a binary image
849860
* with white pixels where the original image was above the threshold

0 commit comments

Comments
 (0)