https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add source for command executables.
* theo/igr/dump2pgm.cc: Move and rename as...
* theo/exec/dump2pnm.cc: ...this.
Update to also handle pbm and ppm.
* theo/igr/pgms2dump.cc: Move and rename as...
* theo/exec/pnms2dump.cc: ...this.
Update to also handle pbm and ppm.
* theo/exec/clean_holes.cc: New.
* theo/exec/threshold_low.cc: New.
* theo/exec/dump2cloud.cc: New.
* theo/exec/closing_area.cc: New.
* theo/exec/closing_isotropic.cc: New.
clean_holes.cc | 66 +++++++++++++++++++++++++++++++++++++++++++
closing_area.cc | 60 +++++++++++++++++++++++++++++++++++++++
closing_isotropic.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++++
dump2cloud.cc | 34 ++++++++++++++++++++++
dump2pnm.cc | 77 +++++++++++++++++++++++++++++++++++++++++++++------
pnms2dump.cc | 71 +++++++++++++++++++++++++++++++++++++++++++----
threshold_low.cc | 69 +++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 433 insertions(+), 15 deletions(-)
Index: theo/exec/clean_holes.cc
--- theo/exec/clean_holes.cc (revision 0)
+++ theo/exec/clean_holes.cc (revision 0)
@@ -0,0 +1,66 @@
+#include "filetype.hh"
+
+#include <mln/value/label_16.hh>
+#include <mln/labeling/fill_holes.hh>
+#include <mln/logical/not.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.xxx
output.xxx" << std::endl
+ << " Clean holes." << std::endl
+ << " xxx is pbm (2D) or dump (3D)." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc != 3)
+ usage(argv);
+
+ trace::entering("main");
+
+ std::string filename = argv[1];
+
+ switch (get_filetype(argv[1]))
+ {
+ case filetype::pbm:
+ {
+ image2d<bool> ima, out;
+ io::pbm::load(ima, argv[1]);
+ value::label_16 n;
+ out = labeling::fill_holes(ima, c4(), n);
+ out = labeling::fill_holes(logical::not_(out), c4(), n);
+ io::pbm::save(out, argv[2]);
+ }
+ break;
+
+ case filetype::dump:
+ {
+ image3d<bool> ima, out;
+ io::dump::load(ima, argv[1]);
+ value::label_16 n;
+ out = labeling::fill_holes(ima, c6(), n);
+ out = labeling::fill_holes(logical::not_(out), c6(), n);
+ io::dump::save(out, argv[2]);
+ }
+ break;
+
+ case filetype::unknown:
+ std::cerr << "unknown filename extension!" << std::endl;
+ usage(argv);
+ break;
+
+ default:
+ std::cerr << "file type not handled!" << std::endl;
+ usage(argv);
+ }
+
+ trace::exiting("main");
+}
Index: theo/exec/threshold_low.cc
--- theo/exec/threshold_low.cc (revision 0)
+++ theo/exec/threshold_low.cc (revision 0)
@@ -0,0 +1,69 @@
+#include "filetype.hh"
+
+#include <mln/core/routine/duplicate.hh>
+#include <mln/pw/all.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.xxx low
output.xxx" << std::endl
+ << " Low threshold." << std::endl
+ << " xxx is pbm (2D) or dump (3D)." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc != 4)
+ usage(argv);
+
+
+ trace::entering("main");
+
+ std::string filename = argv[1];
+
+ int low = std::atoi(argv[2]);
+ if (low < 0 || low > 255)
+ {
+ std::cerr << "bad threshold!" << std::endl;
+ usage(argv);
+ }
+
+
+
+ switch (get_filetype(argv[1]))
+ {
+ case filetype::pgm:
+ {
+ image2d<int_u8> ima;
+ io::pgm::load(ima, argv[1]);
+ io::pbm::save(duplicate((pw::value(ima) < pw::cst(low)) | ima.domain()), argv[3]);
+ }
+ break;
+
+ case filetype::dump:
+ {
+ image3d<int_u8> ima;
+ io::dump::load(ima, argv[1]);
+ io::dump::save(duplicate((pw::value(ima) < pw::cst(low)) | ima.domain()), argv[3]);
+ }
+ break;
+
+ case filetype::unknown:
+ std::cerr << "unknown filename extension!" << std::endl;
+ usage(argv);
+ break;
+
+ default:
+ std::cerr << "file type not handled!" << std::endl;
+ usage(argv);
+ }
+
+ trace::exiting("main");
+}
Index: theo/exec/dump2cloud.cc
--- theo/exec/dump2cloud.cc (revision 0)
+++ theo/exec/dump2cloud.cc (revision 0)
@@ -0,0 +1,34 @@
+#include "filetype.hh"
+
+#include <mln/io/cloud/save.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.dump
output.txt" << std::endl
+ << " Dump (binary, 3D) to cloud." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+
+ if (argc != 3)
+ usage(argv);
+
+ trace::entering("main");
+
+ std::string filename = argv[1];
+
+ image3d<bool> vol;
+ io::dump::load(vol, argv[1]);
+ p_array<point3d> arr;
+ convert::from_to(vol, arr);
+ io::cloud::save(arr, argv[2]);
+
+ trace::exiting("main");
+}
Index: theo/exec/dump2pnm.cc
--- theo/exec/dump2pnm.cc (revision 3368)
+++ theo/exec/dump2pnm.cc (working copy)
@@ -1,17 +1,15 @@
+#include "filetype.hh"
-#include <mln/core/image/image2d.hh>
-#include <mln/make/image3d.hh>
+#include <mln/literal/black.hh>
#include <mln/debug/slices_2d.hh>
-#include <mln/value/int_u8.hh>
-#include <mln/io/dump/load.hh>
-#include <mln/io/pgm/save.hh>
-
void usage(char* argv[])
{
- std::cerr << "usage: " << argv[0] << " input.dump
output.pgm" << std::endl;
+ std::cerr << "usage: " << argv[0] << " input.dump
output.pnm" << std::endl;
+ std::cerr << " It works with binary (pbm), gray-level (int_u8), and color
(rgb8) images." << std::endl;
+ std::cerr << " Sample use: binary input.dump -> output.pbm"
<< std::endl;
abort();
}
@@ -20,15 +18,76 @@
int main(int argc, char* argv[])
{
using namespace mln;
- using value::int_u8;
if (argc != 3)
usage(argv);
- image3d<int_u8> vol;
+ trace::entering("main");
+
+ std::string filename = argv[2];
+
+ switch (get_filetype(argv[2]))
+ {
+ case filetype::pbm:
+ {
+ image3d<bool> vol;
io::dump::load(vol, argv[1]);
+ bool bg = false;
+ image2d<bool> ima = debug::slices_2d(vol, 1.f, bg);
+ io::pbm::save(ima, argv[2]);
+ }
+ break;
+ case filetype::pgm:
+ {
+ using value::int_u8;
+ image3d<int_u8> vol;
+ io::dump::load(vol, argv[1]);
int_u8 bg = 0;
image2d<int_u8> ima = debug::slices_2d(vol, 1.f, bg);
io::pgm::save(ima, argv[2]);
}
+ break;
+
+ case filetype::ppm:
+ {
+ using value::rgb8;
+ image3d<rgb8> vol;
+ io::dump::load(vol, argv[1]);
+ rgb8 bg = literal::black;
+ image2d<rgb8> ima = debug::slices_2d(vol, 1.f, bg);
+ io::ppm::save(ima, argv[2]);
+ }
+ break;
+
+ case filetype::dump:
+ {
+ std::cerr << "Output shall not be a dump file!" << std::endl;
+ usage(argv);
+ }
+ break;
+
+ case filetype::unknown:
+ std::cerr << "unknown filename extension!" << std::endl;
+ usage(argv);
+ break;
+
+ default:
+ std::cerr << "file type not handled!" << std::endl;
+ usage(argv);
+ }
+
+ trace::exiting("main");
+
+
+
+
+// using namespace mln;
+// using value::int_u8;
+
+// if (argc != 3)
+// usage(argv);
+
+// std::string filename = argv[2];
+
+}
Property changes on: theo/exec/dump2pnm.cc
___________________________________________________________________
Added: svn:mergeinfo
Index: theo/exec/pnms2dump.cc
--- theo/exec/pnms2dump.cc (revision 3368)
+++ theo/exec/pnms2dump.cc (working copy)
@@ -1,16 +1,14 @@
+#include "filetype.hh"
-#include <mln/core/image/image2d.hh>
#include <mln/make/image3d.hh>
-#include <mln/value/int_u8.hh>
-#include <mln/io/pgm/load.hh>
-#include <mln/io/dump/save.hh>
void usage(char* argv[])
{
- std::cerr << "usage: " << argv[0] << " output.dump
input1.pgm .. inputn.pgm" << std::endl;
+ std::cerr << "usage: " << argv[0] << " output.dump
input1.xxx .. inputn.xxx" << std::endl;
+ std::cerr << " It works with binary (pbm), gray-level (int_u8), and color
(rgb8) images." << std::endl;
abort();
}
@@ -20,12 +18,35 @@
{
using namespace mln;
using value::int_u8;
- typedef image2d<int_u8> I;
if (argc < 3)
usage(argv);
+ trace::entering("main");
+
+ std::string filename = argv[2];
+ switch (get_filetype(argv[2]))
+ {
+ case filetype::pbm:
+ {
+ typedef image2d<bool> I;
+ util::array<I> arr;
+ for (int i = 2; i < argc; ++i)
+ {
+ I ima;
+ io::pbm::load(ima, argv[i]);
+ arr.append(ima);
+ }
+ image3d<bool> vol = make::image3d(arr);
+ io::dump::save(vol, argv[1]);
+ }
+ break;
+
+ case filetype::pgm:
+ {
+ using value::int_u8;
+ typedef image2d<int_u8> I;
util::array<I> arr;
for (int i = 2; i < argc; ++i)
{
@@ -36,3 +57,41 @@
image3d<int_u8> vol = make::image3d(arr);
io::dump::save(vol, argv[1]);
}
+ break;
+
+ case filetype::ppm:
+ {
+ using value::rgb8;
+ typedef image2d<rgb8> I;
+ util::array<I> arr;
+ for (int i = 2; i < argc; ++i)
+ {
+ I ima;
+ io::ppm::load(ima, argv[i]);
+ arr.append(ima);
+ }
+ image3d<rgb8> vol = make::image3d(arr);
+ io::dump::save(vol, argv[1]);
+ }
+ break;
+
+ case filetype::dump:
+ {
+ std::cerr << "Output shall not be a dump file!" << std::endl;
+ usage(argv);
+ }
+ break;
+
+ case filetype::unknown:
+ std::cerr << "unknown filename extension!" << std::endl;
+ usage(argv);
+ break;
+
+ default:
+ std::cerr << "file type not handled!" << std::endl;
+ usage(argv);
+ }
+
+ trace::exiting("main");
+
+}
Property changes on: theo/exec/pnms2dump.cc
___________________________________________________________________
Added: svn:mergeinfo
Index: theo/exec/closing_area.cc
--- theo/exec/closing_area.cc (revision 0)
+++ theo/exec/closing_area.cc (revision 0)
@@ -0,0 +1,60 @@
+#include "filetype.hh"
+#include <mln/morpho/closing_area.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.xxx
lambda output.xxx" << std::endl
+ << " Area closing." << std::endl
+ << " xxx in { pgm, dump }" << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc != 4)
+ usage(argv);
+
+ trace::entering("main");
+
+ std::string filename = argv[1];
+ unsigned lambda = atoi(argv[2]);
+
+ switch (get_filetype(argv[1]))
+ {
+ case filetype::pgm:
+ {
+ image2d<int_u8> ima, clo;
+ io::pgm::load(ima, argv[1]);
+ clo = morpho::closing_area(ima, c4(), lambda);
+ io::pgm::save(clo, argv[3]);
+ }
+ break;
+
+ case filetype::dump:
+ {
+ image3d<int_u8> ima, clo;
+ io::dump::load(ima, argv[1]);
+ clo = morpho::closing_area(ima, c6(), lambda);
+ io::dump::save(clo, argv[3]);
+ }
+ break;
+
+ case filetype::unknown:
+ std::cerr << "unknown filename extension!" << std::endl;
+ usage(argv);
+ break;
+
+ default:
+ std::cerr << "file type not handled!" << std::endl;
+ usage(argv);
+ }
+
+ trace::exiting("main");
+}
Index: theo/exec/closing_isotropic.cc
--- theo/exec/closing_isotropic.cc (revision 0)
+++ theo/exec/closing_isotropic.cc (revision 0)
@@ -0,0 +1,71 @@
+#include "filetype.hh"
+
+#include <mln/morpho/closing.hh>
+#include <mln/win/disk2d.hh>
+#include <mln/win/ball3d.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.xxx r
output.xxx" << std::endl
+ << " Closing with an isotropic structuring element." <<
std::endl
+ << " xxx is pbm (2D) or dump (3D)." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+
+ if (argc != 4)
+ usage(argv);
+
+ trace::entering("main");
+
+ int r = std::atoi(argv[2]);
+ if (r < 0)
+ {
+ std::cerr << "bad radius!" << std::endl;
+ usage(argv);
+ }
+
+
+ std::string filename = argv[1];
+
+ switch (get_filetype(argv[1]))
+ {
+ case filetype::pbm:
+ {
+ image2d<bool> ima, out;
+ io::pbm::load(ima, argv[1]);
+ out = morpho::closing(ima, win::disk2d(2 * r + 1));
+ io::pbm::save(out, argv[3]);
+ }
+ break;
+
+ case filetype::dump:
+ {
+ image3d<bool> ima, out;
+ io::dump::load(ima, argv[1]);
+ out = morpho::closing(ima, win::ball3d(2 * r + 1));
+ io::dump::save(out, argv[3]);
+ }
+ break;
+
+ case filetype::unknown:
+ std::cerr << "unknown filename extension!" << std::endl;
+ usage(argv);
+ break;
+
+ default:
+ std::cerr << "file type not handled!" << std::endl;
+ usage(argv);
+ }
+
+
+
+ trace::exiting("main");
+}