I am translating a go program that uses leptonica library to a python script that uses openCV, and I cant find a way to translate the following:
img = pixReduceRankBinary2(img, 2, NULL);
img = pixReduceRankBinary2(img, 2, NULL);
img = pixCloseBrick(NULL, img, 2, 3);
is there an implementation of those functions in openCV?
Here is one way to do that using Python/OpenCV/Skimage. Simply read the image and ensure it is binary. The use Skimage downscale_local_mean to downsample by 2 using 2x2 neighborhoods producing a factor of two smaller image whose values are the means of the 2x2 neighborhoods. Then threshold again in 25% increments to correspond to leptonica counts for their pixReduceRankBinary2 function.
Input (rice grains):
Result for count=2: