GNOME Bugzilla – Bug 336183
use Otsu's method of calculating optimal "threshold" value
Last modified: 2006-04-21 09:40:11 UTC
current the default value for the threshold tool in the "<Image>/Colors/Threshold..." dialog is set to 127 this patch sets it to a better value, according to an algorithm called "Otsu's method". the code is an adaptation from the implementation from GNU Ocrad
Created attachment 62116 [details] [review] thresholding using Otsu's method
Using that method automatically would imply a certain use case for thresholding. To be consistent with other color correction tools (none of them starts with some precalculated param), I suggest putting that functionality behind an "Auto" button.
Also, if "Otsu" is some standard way of doing this, the function should probably have a comment with a link to the original paper or whatever reference. And the patch needs to follow the coding style.
Adding an "Auto" button to the Threshold tool seems like the right thing to do here. Would probably also need a PDB function so that it is accessible from scripts and plug-ins.
Lode, will you improve your patch so that we can accept it for inclusion in the GIMP source tree?
Created attachment 62714 [details] [review] cleanup + PDB registration improve conformance to coding style added registration in pdb renamed function to "histogram_get_threshold" instead of "histogram_get_otsu_threshold"
Thanks for the new patch, however I guess you mis-diffed somehow... Look at the attached patch, it's probably not exactly what you wanted to upload :-)
Created attachment 62721 [details] [review] re-diffed removed cruft from diffing Makefiles
That looks somewhat better but it cannot be applied as is. You must not change the existing PDB functions because that would break scripts and plug-ins. I suggest that we first get this feature into the core, then think about exposing it to the PDB later. Please remove that part of the patch. The Threshold tool should get an "Auto" button as sugggested in comment #2. There are also still some coding style issues.
As a first step, I have committed the patch with some minor cleanups and without the changes to the PDB: 2006-04-21 Sven Neumann <sven@gimp.org> Applied a slightly modified version of a patch from Lode Leroy (bug #336183): * app/base/gimphistogram.[ch]: added new function gimp_histogram_get_threshold() that returns an optimal binarization threshold. * app/tools/gimpthresholdtool.c: use the new function to initialize the Threshold tool. This is IMO a reasonable state that we could ship with. But adding an Auto button and a way to access the new functionality from the PDB would still be nice to have. For now, closing this report as FIXED.