Skip to main content
10000+ Posts
Implementing image thresholding (Otsu's method) with PythonCaller

Hello!  I'm trying to implement Otsu's method of image thresholding on an incoming raster, using the PythonCaller transformer.  I  have the following code block in the PythonCaller parameters, although my Python isn't great, so there may well be issues with it:import fmeimport fmeobjectsimport numpy as npclass OtsuThreshold(object):    def __init__(self):        pass    def input(self, feature):        #implement Otsu thresholding in native Python with numpy        #get the image from the feature        image = feature.getAttribute('image')        #compute the histogram of the image, then find the peak of the histogram         hist = np.histogram(image, bins=256, range=(0, 256))                maxVal = np.max(hist[0])        maxLoc = np.argmax(hist[0])        #perform Otsu thresholding        T = maxLoc        thresh = np.where(image > T, 255, 0)

Badge Winners

Show all badges

Community Stats

32,343
Posts
122,979
Replies
40,417
Members