Commit 0461de7a authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Add a new tool for global thresholding.

	* src/binarization/Makefile.am: Add a new target.

	* src/binarization/global_threshold.cc: New.
parent ad194b5f
2011-10-14 Guillaume Lazzara <z@lrde.epita.fr>
Add a new tool for global thresholding.
* src/binarization/Makefile.am: Add a new target.
* src/binarization/global_threshold.cc: New.
2011-10-14 Guillaume Lazzara <z@lrde.epita.fr>
* tests/binarization/global_threshold.cc: Fix test.
......
......@@ -41,6 +41,7 @@ ppm_sauvola_ms_split_SOURCES = ppm_sauvola_ms_split.cc
if HAVE_MAGICKXX
noinst_PROGRAMS += \
global_threshold \
sauvola_debug \
sauvola_ms_debug
......@@ -52,6 +53,12 @@ if HAVE_MAGICKXX
sauvola_ms_split
global_threshold_SOURCES = global_threshold.cc
global_threshold_CPPFLAGS = $(AM_CPPFLAGS) \
$(MAGICKXX_CPPFLAGS)
global_threshold_LDFLAGS = $(AM_LDFLAGS) \
$(MAGICKXX_LDFLAGS)
otsu_SOURCES = otsu.cc
otsu_CPPFLAGS = $(AM_CPPFLAGS) \
......
// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#include <mln/core/image/image2d.hh>
#include <mln/value/int_u8.hh>
#include <mln/io/magick/load.hh>
#include <mln/io/pbm/save.hh>
#include <mln/data/transform.hh>
#include <mln/fun/v2v/rgb_to_luma.hh>
#include <scribo/binarization/global_threshold.hh>
#include <scribo/debug/option_parser.hh>
#include <scribo/debug/logger.hh>
static const scribo::debug::arg_data arg_desc[] =
{
{ "input.*", "An image." },
{ "threshold_value", "Global threshold to apply." },
{ "output.pbm", "A binary image." },
{0, 0}
};
// --enable/disable-<name>
static const scribo::debug::toggle_data toggle_desc[] =
{
// name, description, default value
{0, 0, false}
};
// --<name> <args>
static const scribo::debug::opt_data opt_desc[] =
{
// name, description, arguments, check args function, number of args, default arg
{ "debug-prefix", "Enable debug image outputs. Prefix image name with that "
"given prefix.", "<prefix>", 0, 1, 0 },
{ "verbose", "Enable verbose mode", 0, 0, 0, 0 },
{0, 0, 0, 0, 0, 0}
};
int main(int argc, char *argv[])
{
using namespace mln;
scribo::debug::option_parser options(arg_desc, toggle_desc, opt_desc);
if (!options.parse(argc, argv))
return 1;
// Enable debug output.
if (options.is_set("debug-prefix"))
{
scribo::debug::logger().set_filename_prefix(options.opt_value("debug-prefix").c_str());
scribo::debug::logger().set_level(scribo::debug::All);
}
Magick::InitializeMagick(*argv);
trace::entering("main");
bool verbose = options.is_set("verbose");
unsigned threshold = atoi(options.arg("threshold_value"));
if (verbose)
std::cout << "Using threshold=" << threshold << std::endl;
image2d<value::rgb8> input;
io::magick::load(input, options.arg("input.*"));
// Convert to Gray level image.
image2d<value::int_u8>
input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>());
image2d<bool> out = scribo::binarization::global_threshold(input_1_gl, threshold);
io::pbm::save(out, options.arg("output.pbm"));
trace::exiting("main");
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment