After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 336183 - use Otsu's method of calculating optimal "threshold" value
use Otsu's method of calculating optimal "threshold" value
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Tools
unspecified
Other All
: Normal enhancement
: Future
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2006-03-27 13:15 UTC by Lode Leroy
Modified: 2006-04-21 09:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
thresholding using Otsu's method (4.17 KB, patch)
2006-03-27 13:16 UTC, Lode Leroy
needs-work Details | Review
cleanup + PDB registration (154.09 KB, patch)
2006-04-04 07:45 UTC, Lode Leroy
none Details | Review
re-diffed (5.75 KB, patch)
2006-04-04 09:48 UTC, Lode Leroy
committed Details | Review

Description Lode Leroy 2006-03-27 13:15:09 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
Comment 1 Lode Leroy 2006-03-27 13:16:04 UTC
Created attachment 62116 [details] [review]
thresholding using Otsu's method
Comment 2 Michael Natterer 2006-03-27 13:27:21 UTC
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.
Comment 3 Michael Natterer 2006-03-27 13:28:46 UTC
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.
Comment 4 Sven Neumann 2006-03-28 15:35:57 UTC
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.
Comment 5 Sven Neumann 2006-04-03 13:07:02 UTC
Lode, will you improve your patch so that we can accept it for inclusion in the GIMP source tree?
Comment 6 Lode Leroy 2006-04-04 07:45:26 UTC
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"
Comment 7 Michael Natterer 2006-04-04 09:30:23 UTC
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 :-)
Comment 8 Lode Leroy 2006-04-04 09:48:59 UTC
Created attachment 62721 [details] [review]
re-diffed 

removed cruft from diffing Makefiles
Comment 9 Sven Neumann 2006-04-06 15:11:35 UTC
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.
Comment 10 Sven Neumann 2006-04-21 09:40:11 UTC
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.