I have been writing code in the python-fu console of gimp and I wanted to find the minimum of an image histogram (the pixel intensity value with the least frequency).

There are two functions in the procedural database that deals with histograms - pdb.gimp_drawable_histogram() and pdb.python_fu_histogram_export(). The first function pdb.gimp_drawable_histogram() is not useful for me because it does not give me the histogram minimum. The second function pdb.python_fu_histogram_export() does exactly what I want, but it exports the result into a .csv file and prevents me from accessing the values within the console.

I can get around this by exporting the .csv function first, followed by importing the .csv file back into the console and accessing the values. But this seems like a rather ugly and inefficient way to do it.

Is there a way to access the histogram values without exporting it to a .csv and then back into the console?

1 Answer 1


You can use the gimp_drawable_histogram while iterating a window, for instance:

hist=[pdb.gimp_drawable_histogram(drawable,HISTOGRAM_VALUE,x/255.,(x+1)/255.) for x in range(255)]

On an 8Mpix image it takes a couple of seconds. If you don't need that much precision you can use wider windows to make it run faster.

PS: it turns out that the CSV export you mention, written in Python, does exactly that (so won't run any faster). You can find it in your Gimp installation, as lib/gimp/2.0/plug-ins/histogram-export/histogram-export.py, under /usr in a regular Linux install, or your Gimp install tree in Windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.