https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox
Index: ChangeLog
from Alexandre Abraham <abraham(a)lrde.epita.fr>
Updating filters.
* nature/erosion.cc: More user friendly.
* nature/gradient.cc: .
* nature/hom.cc: Now working.
* nature/mco.cc: Now working on every images.
* nature/opening.cc: .
erosion.cc | 7 ++++---
gradient.cc | 2 +-
hom.cc | 40 +++++++++++++++++++++++++++++++---------
mco.cc | 53 ++++++++++++++++++++++++++---------------------------
opening.cc | 2 +-
5 files changed, 63 insertions(+), 41 deletions(-)
Index: nature/erosion.cc
--- nature/erosion.cc (revision 2754)
+++ nature/erosion.cc (working copy)
@@ -45,7 +45,7 @@
return 1;
}
- for (unsigned i = 1; i < argc; ++i)
+ for (int i = 1; i < argc; ++i)
{
image2d<int_u8> ima;
io::pgm::load(ima, argv[i]);
@@ -53,7 +53,8 @@
win::hline2d f(31);
border::thickness = 16;
- io::pgm::save( morpho::erosion(ima, f),
- "out.pgm" );
+ std::string name(argv[i]);
+ name.erase(name.length() - 4);
+ io::pgm::save(morpho::erosion(ima, f), name.append("_eroded.pgm"));
}
}
Index: nature/gradient.cc
--- nature/gradient.cc (revision 2754)
+++ nature/gradient.cc (working copy)
@@ -45,7 +45,7 @@
return 1;
}
- for (unsigned i = 1; i < argc; ++i)
+ for (int i = 1; i < argc; ++i)
{
image2d<int_u8> ima;
io::pgm::load(ima, argv[i]);
Index: nature/hom.cc
--- nature/hom.cc (revision 2754)
+++ nature/hom.cc (working copy)
@@ -35,7 +35,7 @@
#include <mln/value/int_u8.hh>
-
+# include <mln/core/alias/window2d.hh>
#include <mln/level/transform.hh>
#include <mln/binarization/threshold.hh>
@@ -47,26 +47,48 @@
int main(int argc, const char * argv[])
{
using namespace mln;
- using value::int_u16;
+ using namespace value;
if (argc < 2) {
std::cerr << "usage: " << argv[0] << " in.pgm
[other_files.pgm]" << std::endl;
return 1;
}
- for (unsigned i = 1; i < argc; ++i)
+ for (int i = 1; i < argc; ++i)
{
- image2d<int_u16> ima;
+ image2d<int_u8> ima;
io::pgm::load(ima, argv[i]);
// Compute the mean
- int_u16 mean = estim::mean(ima);
-
- win::rectangle2d rectout(3, 3);
- win::rectangle2d rectin(5, 5);
+ int_u8 mean = estim::mean(ima);
+ window2d winout;
+ window2d winin;
- io::pbm::save( morpho::hit_or_miss(binarization::threshold(ima, mean), rectout,
rectin),
- "out.pbm" );
+ static const bool matout [] = {0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 0};
+
+ convert::from_to(matout, winout);
+
+ static const bool matin [] = {0, 1, 0, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0};
+
+ convert::from_to(matin, winin);
+
+
+ std::string name(argv[i]);
+ name.erase(name.length() - 4);
+ io::pbm::save( morpho::hit_or_miss(binarization::threshold(ima, mean), winout,
winin),
+ name.append("_hom.pbm"));
}
}
Index: nature/mco.cc
--- nature/mco.cc (revision 2754)
+++ nature/mco.cc (working copy)
@@ -1,45 +1,44 @@
#include <iostream>
-#include <mln/value/int_u.hh>
#include <mln/core/image/image2d.hh>
+#include <mln/core/image/cast_image.hh>
+#include <mln/value/int_u16.hh>
#include "co_occurence.hh"
#include <mln/core/alias/dpoint2d.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/estim/min_max.hh>
-int main ()
+int main(int argc, const char * argv[])
{
using namespace mln;
using namespace value;
- typedef image2d< int_u<3> > I;
-
- int_u<3> vs[6][5] = {
-
- { 3, 3, 4, 4, 4 },
- { 2, 1, 1, 1, 1 },
- { 1, 4, 4, 4, 6 },
- { 1, 4, 3, 4, 1 },
- { 7, 4, 5, 3, 1 },
- { 7, 7, 1, 1, 0 }
-
- };
-
- I ima(make::image2d(vs));
+ if (argc < 2) {
+ std::cerr << "usage: " << argv[0] << " in.pgm
[other_files.pgm]" << std::endl;
+ return 1;
+ }
dpoint2d d(0, 1);
- // std::cout << co_occurence(ima, d) << std::endl;
+ for (int i = 1; i < argc; ++i)
+ {
+ image2d<int_u8> ima;
+ io::pgm::load(ima, argv[i]);
+
+ std::string name(argv[i]);
+ name.erase(name.length() - 4);
image2d<unsigned> co(co_occurence(ima, d));
- unsigned cpt = 0;
-
+ // Normalization
+ unsigned m, M;
+ estim::min_max(co, m, M);
+ double norm = 255./M;
mln_piter_(image2d<unsigned>) p(co.domain());
for_all(p)
- {
- std::cout << p << " = " << co(p) << std::endl;
- cpt += co(p);
- }
-
- std::cout << cpt << std::endl;
+ co(p) *= norm;
+ io::pgm::save(cast_image<int_u<8> >(co),
name.append("_mco.pgm"));
+ }
}
Index: nature/opening.cc
--- nature/opening.cc (revision 2754)
+++ nature/opening.cc (working copy)
@@ -45,7 +45,7 @@
return 1;
}
- for (unsigned i = 1; i < argc; ++i)
+ for (int i = 1; i < argc; ++i)
{
image2d<int_u8> ima;
io::pgm::load(ima, argv[i]);