Commit b40632da authored by Robert Sachunsky's avatar Robert Sachunsky

scribo-cli binarization: add negate-output toggles uniformly

    - add `negate-input` / `negate-output` toggles from otsu
      to other algorithm CLIs too
      (but keep `negate` as synonym for `negate-output` in sauvola;
       and don't add `negate-input` where this would require
       negation on RGB)
    - use the versatile io::magick::save instead of just io::pbm::save
    - rename output argument to `output.*` to reflect versatility
parent 3bb2737c
......@@ -26,10 +26,11 @@
#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/io/magick/all.hh>
#include <mln/data/transform.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/debug/option_parser.hh>
......@@ -39,7 +40,7 @@ static const scribo::debug::arg_data arg_desc[] =
{
{ "input.*", "An image." },
{ "threshold_value", "Global threshold to apply." },
{ "output.pbm", "A binary image." },
{ "output.*", "A binary image." },
{0, 0}
};
......@@ -48,6 +49,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] =
{
// name, description, default value
{ "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false}
};
......@@ -94,8 +97,14 @@ int main(int argc, char *argv[])
image2d<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);
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 @@
#include <mln/io/magick/all.hh>
#include <mln/data/transform.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/debug/option_parser.hh>
#include <scribo/debug/logger.hh>
......@@ -49,6 +51,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] =
{
// name, description, default value
{ "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false}
};
......@@ -106,8 +110,14 @@ int main(int argc, char *argv[])
input_1_gl = data::transform(input_1,
mln::fun::v2v::rgb_to_luma<value::int_u8>());
if (options.is_enabled("negate-input"))
arith::revert_inplace(input_1_gl);
image2d<bool>
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.*"));
}
......@@ -39,7 +39,7 @@
static const scribo::debug::arg_data arg_desc[] =
{
{ "input.*", "An image." },
{ "output.pbm", "A binary image." },
{ "output.*", "A binary image." },
{0, 0}
};
......@@ -48,6 +48,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] =
{
// name, description, default value
{ "negate-input", "Negate input image before binarizing.", true },
{ "negate-output", "Negate output image after binarizing.", true },
{0, 0, false}
};
......@@ -97,9 +99,11 @@ int main(int argc, char *argv[])
image2d<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::niblack(input_1_gl, w, k);
if (options.is_enabled("negate-output"))
logical::not_inplace(out);
io::magick::save(out, options.arg("output.pbm"));
io::magick::save(out, options.arg("output.*"));
}
......@@ -39,7 +39,7 @@
static const scribo::debug::arg_data arg_desc[] =
{
{ "input.*", "An image." },
{ "output.pbm", "A binary image." },
{ "output.*", "A binary image." },
{0, 0}
};
......@@ -49,7 +49,7 @@ static const scribo::debug::toggle_data toggle_desc[] =
{
// name, description, default value
{ "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}
};
......@@ -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>());
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);
if (options.is_enabled("negate-output"))
logical::not_inplace(out);
io::magick::save(out, options.arg("output.pbm"));
io::magick::save(out, options.arg("output.*"));
}
......@@ -29,6 +29,8 @@
#include <mln/io/magick/all.hh>
#include <mln/data/transform.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/debug/option_parser.hh>
......@@ -46,6 +48,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] =
{
// name, description, default value
{ "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false}
};
......@@ -95,6 +99,9 @@ int main(int argc, char *argv[])
image2d<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();
// Binarize
......@@ -102,6 +109,9 @@ int main(int argc, char *argv[])
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.*"));
}
......@@ -30,6 +30,7 @@
#include <mln/value/int_u8.hh>
#include <mln/io/magick/all.hh>
#include <mln/data/transform.hh>
#include <mln/arith/revert.hh>
#include <mln/fun/v2v/rgb_to_luma.hh>
#include <mln/util/timer.hh>
#include <mln/logical/not.hh>
......@@ -50,6 +51,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] =
{
// 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},
{0, 0, false}
};
......@@ -137,6 +140,8 @@ int main(int argc, char *argv[])
input_1_gl = data::transform(input_1,
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();
......@@ -146,8 +151,8 @@ int main(int argc, char *argv[])
scribo::debug::logger().stop_time_logging("Binarized in");
if (options.is_enabled("negate"))
io::magick::save(logical::not_(output), options.arg("output.*"));
else
if (options.is_enabled("negate") || options.is_enabled("negate-output"))
logical::not_inplace(output);
io::magick::save(output, options.arg("output.*"));
}
......@@ -28,10 +28,11 @@
#include <mln/core/image/image2d.hh>
#include <mln/value/rgb8.hh>
#include <mln/io/magick/load.hh>
#include <mln/io/pbm/save.hh>
#include <mln/io/magick/all.hh>
#include <mln/data/transform.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/preprocessing/split_bg_fg.hh>
......@@ -41,7 +42,7 @@
static const scribo::debug::arg_data arg_desc[] =
{
{ "input.*", "An image." },
{ "output.pbm", "A binary image." },
{ "output.*", "A binary image." },
{0, 0}
};
......@@ -50,6 +51,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] =
{
// name, description, default value
// { "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false}
};
......@@ -130,6 +133,11 @@ int main(int argc, char *argv[])
image2d<value::rgb8> input_1;
io::magick::load(input_1, options.arg("input.*"));
/*
if (options.is_enabled("negate-input"))
arith::revert_inplace(input_1);
*/
// Split foreground/background
image2d<value::rgb8>
fg = scribo::preprocessing::split_bg_fg(input_1, lambda, 32).first();
......@@ -142,7 +150,10 @@ int main(int argc, char *argv[])
image2d<bool>
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 @@
#include <mln/core/image/image2d.hh>
#include <mln/value/rgb8.hh>
#include <mln/io/magick/load.hh>
#include <mln/io/pbm/save.hh>
#include <mln/io/magick/all.hh>
#include <mln/arith/revert.hh>
#include <mln/logical/not.hh>
#include <scribo/binarization/sauvola_ms_split.hh>
#include <scribo/debug/option_parser.hh>
......@@ -36,7 +38,7 @@
static const scribo::debug::arg_data arg_desc[] =
{
{ "input.*", "An image." },
{ "output.pbm", "A binary image." },
{ "output.*", "A binary image." },
{0, 0}
};
......@@ -45,6 +47,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] =
{
// name, description, default value
// { "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false}
};
......@@ -124,10 +128,18 @@ int main(int argc, char *argv[])
image2d<value::rgb8> input_1;
io::magick::load(input_1, options.arg("input.*"));
/*
if (options.is_enabled("negate-input"))
arith::revert_inplace(input_1);
*/
image2d<bool>
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 @@
#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/io/magick/all.hh>
#include <mln/data/transform.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/debug/option_parser.hh>
......@@ -38,7 +39,7 @@
static const scribo::debug::arg_data arg_desc[] =
{
{ "input.*", "An image." },
{ "output.pbm", "A binary image." },
{ "output.*", "A binary image." },
{0, 0}
};
......@@ -47,6 +48,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] =
{
// name, description, default value
{ "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false}
};
......@@ -96,8 +99,14 @@ int main(int argc, char *argv[])
image2d<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);
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 @@
#include <mln/io/magick/all.hh>
#include <mln/data/transform.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/debug/option_parser.hh>
......@@ -37,7 +39,7 @@
static const scribo::debug::arg_data arg_desc[] =
{
{ "input.*", "An image." },
{ "output.pbm", "A binary image." },
{ "output.*", "A binary image." },
{0, 0}
};
......@@ -46,6 +48,8 @@ static const scribo::debug::arg_data arg_desc[] =
static const scribo::debug::toggle_data toggle_desc[] =
{
// name, description, default value
{ "negate-input", "Negate input image before binarizing.", false },
{ "negate-output", "Negate output image after binarizing.", false },
{0, 0, false}
};
......@@ -95,8 +99,14 @@ int main(int argc, char *argv[])
image2d<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);
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.*"));
}
Markdown is supported
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