Commit cd2d9355 authored by Edwin Carlinet's avatar Edwin Carlinet

Merge branch 'scribo-cli-negate-toggles-and-save-format' into 'master'

scribo-cli: negate toggles and save format

See merge request !5
parents 3bb2737c e547b432
...@@ -2,5 +2,5 @@ AC_DEFUN([adl_CHECK_PYTHON], ...@@ -2,5 +2,5 @@ AC_DEFUN([adl_CHECK_PYTHON],
[AM_PATH_PYTHON([2.0]) [AM_PATH_PYTHON([2.0])
AC_CACHE_CHECK([for $am_display_PYTHON includes directory], AC_CACHE_CHECK([for $am_display_PYTHON includes directory],
[adl_cv_python_inc], [adl_cv_python_inc],
[adl_cv_python_inc=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_inc()" 2>/dev/null`]) [adl_cv_python_inc=`$PYTHON -c "from distutils import sysconfig; import sys; sys.stdout.write(sysconfig.get_python_inc())" 2>/dev/null`])
AC_SUBST([PYTHONINC], [$adl_cv_python_inc])]) AC_SUBST([PYTHONINC], [$adl_cv_python_inc])])
...@@ -26,10 +26,11 @@ ...@@ -26,10 +26,11 @@
#include <mln/core/image/image2d.hh> #include <mln/core/image/image2d.hh>
#include <mln/value/int_u8.hh> #include <mln/value/int_u8.hh>
#include <mln/io/magick/load.hh> #include <mln/io/magick/all.hh>
#include <mln/io/pbm/save.hh>
#include <mln/data/transform.hh> #include <mln/data/transform.hh>
#include <mln/fun/v2v/rgb_to_luma.hh> #include <mln/fun/v2v/rgb_to_luma.hh>
#include <mln/arith/revert.hh>
#include <mln/logical/not.hh>
#include <scribo/binarization/global_threshold.hh> #include <scribo/binarization/global_threshold.hh>
#include <scribo/debug/option_parser.hh> #include <scribo/debug/option_parser.hh>
...@@ -39,7 +40,7 @@ static const scribo::debug::arg_data arg_desc[] = ...@@ -39,7 +40,7 @@ static const scribo::debug::arg_data arg_desc[] =
{ {
{ "input.*", "An image." }, { "input.*", "An image." },
{ "threshold_value", "Global threshold to apply." }, { "threshold_value", "Global threshold to apply." },
{ "output.pbm", "A binary image." }, { "output.*", "A binary image." },
{0, 0} {0, 0}
}; };
...@@ -48,6 +49,8 @@ static const scribo::debug::arg_data arg_desc[] = ...@@ -48,6 +49,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] = static const scribo::debug::toggle_data toggle_desc[] =
{ {
// name, description, default value // name, description, default value
{ "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false} {0, 0, false}
}; };
...@@ -94,8 +97,14 @@ int main(int argc, char *argv[]) ...@@ -94,8 +97,14 @@ int main(int argc, char *argv[])
image2d<value::int_u8> image2d<value::int_u8>
input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>()); input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>());
if (options.is_enabled("negate-input"))
arith::revert_inplace(input_1_gl);
image2d<bool> out = scribo::binarization::global_threshold(input_1_gl, threshold); image2d<bool> out = scribo::binarization::global_threshold(input_1_gl, threshold);
io::pbm::save(out, options.arg("output.pbm")); if (options.is_enabled("negate-output"))
logical::not_inplace(out);
io::magick::save(out, options.arg("output.*"));
} }
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include <mln/io/magick/all.hh> #include <mln/io/magick/all.hh>
#include <mln/data/transform.hh> #include <mln/data/transform.hh>
#include <mln/fun/v2v/rgb_to_luma.hh> #include <mln/fun/v2v/rgb_to_luma.hh>
#include <mln/arith/revert.hh>
#include <mln/logical/not.hh>
#include <scribo/binarization/kim.hh> #include <scribo/binarization/kim.hh>
#include <scribo/debug/option_parser.hh> #include <scribo/debug/option_parser.hh>
#include <scribo/debug/logger.hh> #include <scribo/debug/logger.hh>
...@@ -49,6 +51,8 @@ static const scribo::debug::arg_data arg_desc[] = ...@@ -49,6 +51,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] = static const scribo::debug::toggle_data toggle_desc[] =
{ {
// name, description, default value // name, description, default value
{ "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false} {0, 0, false}
}; };
...@@ -106,8 +110,14 @@ int main(int argc, char *argv[]) ...@@ -106,8 +110,14 @@ int main(int argc, char *argv[])
input_1_gl = data::transform(input_1, input_1_gl = data::transform(input_1,
mln::fun::v2v::rgb_to_luma<value::int_u8>()); mln::fun::v2v::rgb_to_luma<value::int_u8>());
if (options.is_enabled("negate-input"))
arith::revert_inplace(input_1_gl);
image2d<bool> image2d<bool>
output = scribo::binarization::kim(input_1_gl, w_1, k); output = scribo::binarization::kim(input_1_gl, w_1, k);
if (options.is_enabled("negate-output"))
logical::not_inplace(output);
io::magick::save(output, options.arg("output.*")); io::magick::save(output, options.arg("output.*"));
} }
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
static const scribo::debug::arg_data arg_desc[] = static const scribo::debug::arg_data arg_desc[] =
{ {
{ "input.*", "An image." }, { "input.*", "An image." },
{ "output.pbm", "A binary image." }, { "output.*", "A binary image." },
{0, 0} {0, 0}
}; };
...@@ -48,6 +48,8 @@ static const scribo::debug::arg_data arg_desc[] = ...@@ -48,6 +48,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] = static const scribo::debug::toggle_data toggle_desc[] =
{ {
// name, description, default value // name, description, default value
{ "negate-input", "Negate input image before binarizing.", true },
{ "negate-output", "Negate output image after binarizing.", true },
{0, 0, false} {0, 0, false}
}; };
...@@ -97,9 +99,11 @@ int main(int argc, char *argv[]) ...@@ -97,9 +99,11 @@ int main(int argc, char *argv[])
image2d<value::int_u8> image2d<value::int_u8>
input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>()); input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>());
arith::revert_inplace(input_1_gl); if (options.is_enabled("negate-input"))
arith::revert_inplace(input_1_gl);
image2d<bool> out = scribo::binarization::niblack(input_1_gl, w, k); image2d<bool> out = scribo::binarization::niblack(input_1_gl, w, k);
logical::not_inplace(out); if (options.is_enabled("negate-output"))
io::magick::save(out, options.arg("output.pbm")); logical::not_inplace(out);
io::magick::save(out, options.arg("output.*"));
} }
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
static const scribo::debug::arg_data arg_desc[] = static const scribo::debug::arg_data arg_desc[] =
{ {
{ "input.*", "An image." }, { "input.*", "An image." },
{ "output.pbm", "A binary image." }, { "output.*", "A binary image." },
{0, 0} {0, 0}
}; };
...@@ -49,7 +49,7 @@ static const scribo::debug::toggle_data toggle_desc[] = ...@@ -49,7 +49,7 @@ static const scribo::debug::toggle_data toggle_desc[] =
{ {
// name, description, default value // name, description, default value
{ "negate-input", "Negate input image before binarizing.", false }, { "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image before binarizing.", false }, { "negate-output", "Negate output image after binarizing.", false },
{0, 0, false} {0, 0, false}
}; };
...@@ -96,13 +96,13 @@ int main(int argc, char *argv[]) ...@@ -96,13 +96,13 @@ int main(int argc, char *argv[])
input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>()); input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>());
if (options.is_enabled("negate-input")) if (options.is_enabled("negate-input"))
input_1_gl = arith::revert(input_1_gl); arith::revert_inplace(input_1_gl);
image2d<bool> out = scribo::binarization::otsu(input_1_gl); image2d<bool> out = scribo::binarization::otsu(input_1_gl);
if (options.is_enabled("negate-output")) if (options.is_enabled("negate-output"))
logical::not_inplace(out); logical::not_inplace(out);
io::magick::save(out, options.arg("output.pbm")); io::magick::save(out, options.arg("output.*"));
} }
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include <mln/io/magick/all.hh> #include <mln/io/magick/all.hh>
#include <mln/data/transform.hh> #include <mln/data/transform.hh>
#include <mln/fun/v2v/rgb_to_luma.hh> #include <mln/fun/v2v/rgb_to_luma.hh>
#include <mln/arith/revert.hh>
#include <mln/logical/not.hh>
#include <scribo/binarization/sauvola.hh> #include <scribo/binarization/sauvola.hh>
#include <scribo/debug/option_parser.hh> #include <scribo/debug/option_parser.hh>
...@@ -46,6 +48,8 @@ static const scribo::debug::arg_data arg_desc[] = ...@@ -46,6 +48,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] = static const scribo::debug::toggle_data toggle_desc[] =
{ {
// name, description, default value // name, description, default value
{ "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false} {0, 0, false}
}; };
...@@ -95,6 +99,9 @@ int main(int argc, char *argv[]) ...@@ -95,6 +99,9 @@ int main(int argc, char *argv[])
image2d<value::int_u8> image2d<value::int_u8>
input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>()); input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>());
if (options.is_enabled("negate-input"))
arith::revert_inplace(input_1_gl);
scribo::debug::logger().start_time_logging(); scribo::debug::logger().start_time_logging();
// Binarize // Binarize
...@@ -102,6 +109,9 @@ int main(int argc, char *argv[]) ...@@ -102,6 +109,9 @@ int main(int argc, char *argv[])
scribo::debug::logger().stop_time_logging("Binarized in"); scribo::debug::logger().stop_time_logging("Binarized in");
if (options.is_enabled("negate-output"))
logical::not_inplace(out);
io::magick::save(out, options.arg("output.*")); io::magick::save(out, options.arg("output.*"));
} }
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <mln/value/int_u8.hh> #include <mln/value/int_u8.hh>
#include <mln/io/magick/all.hh> #include <mln/io/magick/all.hh>
#include <mln/data/transform.hh> #include <mln/data/transform.hh>
#include <mln/arith/revert.hh>
#include <mln/fun/v2v/rgb_to_luma.hh> #include <mln/fun/v2v/rgb_to_luma.hh>
#include <mln/util/timer.hh> #include <mln/util/timer.hh>
#include <mln/logical/not.hh> #include <mln/logical/not.hh>
...@@ -50,6 +51,8 @@ static const scribo::debug::arg_data arg_desc[] = ...@@ -50,6 +51,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] = static const scribo::debug::toggle_data toggle_desc[] =
{ {
// name, description, default value // name, description, default value
{ "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{ "negate", "Negate output image.", false}, { "negate", "Negate output image.", false},
{0, 0, false} {0, 0, false}
}; };
...@@ -137,6 +140,8 @@ int main(int argc, char *argv[]) ...@@ -137,6 +140,8 @@ int main(int argc, char *argv[])
input_1_gl = data::transform(input_1, input_1_gl = data::transform(input_1,
mln::fun::v2v::rgb_to_luma<value::int_u8>()); mln::fun::v2v::rgb_to_luma<value::int_u8>());
if (options.is_enabled("negate-input"))
arith::revert_inplace(input_1_gl);
scribo::debug::logger().start_time_logging(); scribo::debug::logger().start_time_logging();
...@@ -146,8 +151,8 @@ int main(int argc, char *argv[]) ...@@ -146,8 +151,8 @@ int main(int argc, char *argv[])
scribo::debug::logger().stop_time_logging("Binarized in"); scribo::debug::logger().stop_time_logging("Binarized in");
if (options.is_enabled("negate")) if (options.is_enabled("negate") || options.is_enabled("negate-output"))
io::magick::save(logical::not_(output), options.arg("output.*")); logical::not_inplace(output);
else
io::magick::save(output, options.arg("output.*")); io::magick::save(output, options.arg("output.*"));
} }
...@@ -28,10 +28,11 @@ ...@@ -28,10 +28,11 @@
#include <mln/core/image/image2d.hh> #include <mln/core/image/image2d.hh>
#include <mln/value/rgb8.hh> #include <mln/value/rgb8.hh>
#include <mln/io/magick/load.hh> #include <mln/io/magick/all.hh>
#include <mln/io/pbm/save.hh>
#include <mln/data/transform.hh> #include <mln/data/transform.hh>
#include <mln/fun/v2v/rgb_to_luma.hh> #include <mln/fun/v2v/rgb_to_luma.hh>
#include <mln/arith/revert.hh>
#include <mln/logical/not.hh>
#include <scribo/binarization/sauvola_ms.hh> #include <scribo/binarization/sauvola_ms.hh>
#include <scribo/preprocessing/split_bg_fg.hh> #include <scribo/preprocessing/split_bg_fg.hh>
...@@ -41,7 +42,7 @@ ...@@ -41,7 +42,7 @@
static const scribo::debug::arg_data arg_desc[] = static const scribo::debug::arg_data arg_desc[] =
{ {
{ "input.*", "An image." }, { "input.*", "An image." },
{ "output.pbm", "A binary image." }, { "output.*", "A binary image." },
{0, 0} {0, 0}
}; };
...@@ -50,6 +51,8 @@ static const scribo::debug::arg_data arg_desc[] = ...@@ -50,6 +51,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] = static const scribo::debug::toggle_data toggle_desc[] =
{ {
// name, description, default value // name, description, default value
// { "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false} {0, 0, false}
}; };
...@@ -130,6 +133,11 @@ int main(int argc, char *argv[]) ...@@ -130,6 +133,11 @@ int main(int argc, char *argv[])
image2d<value::rgb8> input_1; image2d<value::rgb8> input_1;
io::magick::load(input_1, options.arg("input.*")); io::magick::load(input_1, options.arg("input.*"));
/*
if (options.is_enabled("negate-input"))
arith::revert_inplace(input_1);
*/
// Split foreground/background // Split foreground/background
image2d<value::rgb8> image2d<value::rgb8>
fg = scribo::preprocessing::split_bg_fg(input_1, lambda, 32).first(); fg = scribo::preprocessing::split_bg_fg(input_1, lambda, 32).first();
...@@ -142,7 +150,10 @@ int main(int argc, char *argv[]) ...@@ -142,7 +150,10 @@ int main(int argc, char *argv[])
image2d<bool> image2d<bool>
output = scribo::binarization::sauvola_ms(fg_gl, w_1, s); output = scribo::binarization::sauvola_ms(fg_gl, w_1, s);
io::pbm::save(output, options.arg("output.pbm")); if (options.is_enabled("negate-output"))
logical::not_inplace(output);
io::magick::save(output, options.arg("output.*"));
} }
...@@ -26,8 +26,10 @@ ...@@ -26,8 +26,10 @@
#include <mln/core/image/image2d.hh> #include <mln/core/image/image2d.hh>
#include <mln/value/rgb8.hh> #include <mln/value/rgb8.hh>
#include <mln/io/magick/load.hh> #include <mln/io/magick/all.hh>
#include <mln/io/pbm/save.hh> #include <mln/arith/revert.hh>
#include <mln/logical/not.hh>
#include <scribo/binarization/sauvola_ms_split.hh> #include <scribo/binarization/sauvola_ms_split.hh>
#include <scribo/debug/option_parser.hh> #include <scribo/debug/option_parser.hh>
...@@ -36,7 +38,7 @@ ...@@ -36,7 +38,7 @@
static const scribo::debug::arg_data arg_desc[] = static const scribo::debug::arg_data arg_desc[] =
{ {
{ "input.*", "An image." }, { "input.*", "An image." },
{ "output.pbm", "A binary image." }, { "output.*", "A binary image." },
{0, 0} {0, 0}
}; };
...@@ -45,6 +47,8 @@ static const scribo::debug::arg_data arg_desc[] = ...@@ -45,6 +47,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] = static const scribo::debug::toggle_data toggle_desc[] =
{ {
// name, description, default value // name, description, default value
// { "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false} {0, 0, false}
}; };
...@@ -124,10 +128,18 @@ int main(int argc, char *argv[]) ...@@ -124,10 +128,18 @@ int main(int argc, char *argv[])
image2d<value::rgb8> input_1; image2d<value::rgb8> input_1;
io::magick::load(input_1, options.arg("input.*")); io::magick::load(input_1, options.arg("input.*"));
/*
if (options.is_enabled("negate-input"))
arith::revert_inplace(input_1);
*/
image2d<bool> image2d<bool>
output = scribo::binarization::sauvola_ms_split(input_1, w_1, s, min_ntrue); output = scribo::binarization::sauvola_ms_split(input_1, w_1, s, min_ntrue);
io::pbm::save(output, options.arg("output.pbm")); if (options.is_enabled("negate-output"))
logical::not_inplace(output);
io::magick::save(output, options.arg("output.*"));
} }
...@@ -26,10 +26,11 @@ ...@@ -26,10 +26,11 @@
#include <mln/core/image/image2d.hh> #include <mln/core/image/image2d.hh>
#include <mln/value/int_u8.hh> #include <mln/value/int_u8.hh>
#include <mln/io/magick/load.hh> #include <mln/io/magick/all.hh>
#include <mln/io/pbm/save.hh>
#include <mln/data/transform.hh> #include <mln/data/transform.hh>
#include <mln/fun/v2v/rgb_to_luma.hh> #include <mln/fun/v2v/rgb_to_luma.hh>
#include <mln/arith/revert.hh>
#include <mln/logical/not.hh>
#include <scribo/binarization/singh.hh> #include <scribo/binarization/singh.hh>
#include <scribo/debug/option_parser.hh> #include <scribo/debug/option_parser.hh>
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
static const scribo::debug::arg_data arg_desc[] = static const scribo::debug::arg_data arg_desc[] =
{ {
{ "input.*", "An image." }, { "input.*", "An image." },
{ "output.pbm", "A binary image." }, { "output.*", "A binary image." },
{0, 0} {0, 0}
}; };
...@@ -47,6 +48,8 @@ static const scribo::debug::arg_data arg_desc[] = ...@@ -47,6 +48,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] = static const scribo::debug::toggle_data toggle_desc[] =
{ {
// name, description, default value // name, description, default value
{ "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false} {0, 0, false}
}; };
...@@ -96,8 +99,14 @@ int main(int argc, char *argv[]) ...@@ -96,8 +99,14 @@ int main(int argc, char *argv[])
image2d<value::int_u8> image2d<value::int_u8>
input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>()); input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>());
if (options.is_enabled("negate-input"))
arith::revert_inplace(input_1_gl);
image2d<bool> out = scribo::binarization::singh(input_1_gl, w, k); image2d<bool> out = scribo::binarization::singh(input_1_gl, w, k);
io::pbm::save(out, options.arg("output.pbm")); if (options.is_enabled("negate-output"))
logical::not_inplace(out);
io::magick::save(out, options.arg("output.*"));
} }
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include <mln/io/magick/all.hh> #include <mln/io/magick/all.hh>
#include <mln/data/transform.hh> #include <mln/data/transform.hh>
#include <mln/fun/v2v/rgb_to_luma.hh> #include <mln/fun/v2v/rgb_to_luma.hh>
#include <mln/arith/revert.hh>
#include <mln/logical/not.hh>
#include <scribo/binarization/wolf.hh> #include <scribo/binarization/wolf.hh>
#include <scribo/debug/option_parser.hh> #include <scribo/debug/option_parser.hh>
...@@ -37,7 +39,7 @@ ...@@ -37,7 +39,7 @@
static const scribo::debug::arg_data arg_desc[] = static const scribo::debug::arg_data arg_desc[] =
{ {
{ "input.*", "An image." }, { "input.*", "An image." },
{ "output.pbm", "A binary image." }, { "output.*", "A binary image." },
{0, 0} {0, 0}
}; };
...@@ -46,6 +48,8 @@ static const scribo::debug::arg_data arg_desc[] = ...@@ -46,6 +48,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] = static const scribo::debug::toggle_data toggle_desc[] =
{ {
// name, description, default value // name, description, default value
{ "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false} {0, 0, false}
}; };
...@@ -95,8 +99,14 @@ int main(int argc, char *argv[]) ...@@ -95,8 +99,14 @@ int main(int argc, char *argv[])
image2d<value::int_u8> image2d<value::int_u8>
input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>()); input_1_gl = data::transform(input, mln::fun::v2v::rgb_to_luma<value::int_u8>());
if (options.is_enabled("negate-input"))
arith::revert_inplace(input_1_gl);
image2d<bool> out = scribo::binarization::wolf(input_1_gl, w, k); image2d<bool> out = scribo::binarization::wolf(input_1_gl, w, k);
io::magick::save(out, options.arg("output.pbm")); if (options.is_enabled("negate-output"))
logical::not_inplace(out);
io::magick::save(out, options.arg("output.*"));