Is there any GIMP API which allows getting max and min values of drawable ?

Hi,

I am writing a python-fu script for GIMP Ver. 2.10.x

I would like to get the maximum and minimum values ​​of drawable, but I can’t find any GIMP API to get them.

I found gimp_drawable_histogram API that allows me to get the mean, median, standard deviation, etc., but not the max and min values.

Does anyone know an API that can get max and min values?

From my collection:

def minmax(image,drawable):
	lo=0
	hi=255
	while hi - lo > 1:
            test=(lo+hi)/2
            _, _, _, pixels, count, _ = pdb.gimp_histogram(drawable,HISTOGRAM_VALUE, 0,test)
            if pixels != count:
                lo=test
            else:
                hi=test
        maxvalue=hi-1
        lo=0
        hi=255
        while hi - lo > 1:
            test=(lo+hi)/2
            _, _, _, pixels, count, _ = pdb.gimp_histogram(drawable,HISTOGRAM_VALUE, test,255)
            if pixels != count:
                hi=test
            else:
                lo=test
        minvalue=lo+1
        gimp.message('Min: %d, max: %d' % (minvalue,maxvalue)) 

Basically you do a dichotomic search, which isn’t as bad as it looks.

In practice this takes in account stray pixels, so I wouldn’t use that to do further processing, I would search for some value with 2% of greater/lower values or similar.

Thank you very much for your helpful advice.
Your code is working fine!