Add otsu threshold to leptonica

This commit is contained in:
James R. Barlow 2016-03-12 00:09:20 -08:00
parent 12868b461a
commit 94a3e447cc
2 changed files with 29 additions and 0 deletions

View File

@ -195,6 +195,25 @@ class Pix:
else:
return (None, None)
def otsu_adaptive_threshold(
self, tile_size=(300, 300), kernel_size=(4, 4), scorefract=0.1):
with LeptonicaErrorTrap():
sx, sy = tile_size
smoothx, smoothy = kernel_size
p_cpix = ffi.new('PIX **')
result = lept.pixOtsuAdaptiveThreshold(
self.cpix,
sx, sy,
smoothx, smoothy,
scorefract,
ffi.NULL,
p_cpix)
if result == 0:
return Pix(p_cpix[0])
else:
return None
@staticmethod
@lru_cache(maxsize=1)
def make_pixel_sum_tab8():

View File

@ -62,6 +62,16 @@ l_int32 * makePixelSumTab8 ( void );
PIX * pixDeserializeFromMemory ( const l_uint32 *data, size_t nbytes );
l_int32 pixSerializeToMemory ( PIX *pixs, l_uint32 **pdata, size_t *pnbytes );
l_int32
pixOtsuAdaptiveThreshold(PIX *pixs,
l_int32 sx,
l_int32 sy,
l_int32 smoothx,
l_int32 smoothy,
l_float32 scorefract,
PIX **ppixth,
PIX **ppixd);
void lept_free(void *ptr);
""")