* apps/graph-morpho/make_complex2d.hh: New file.
* apps/graph-morpho/asf-complex1d.cc: Move the construction of
the image2d-based complex...
* apps/graph-morpho/make_complex2d.hh (make_complex2d):
...here (new function).
* apps/graph-morpho/Makefile.am
(noinst_HEADERS): Add make_complex2d.hh.
---
milena/ChangeLog | 12 +++
milena/apps/graph-morpho/Makefile.am | 2 +-
milena/apps/graph-morpho/asf-complex1d.cc | 46 ++----------
.../{asf-complex1d.cc => make_complex2d.hh} | 77 ++++++++------------
4 files changed, 51 insertions(+), 86 deletions(-)
copy milena/apps/graph-morpho/{asf-complex1d.cc => make_complex2d.hh} (59%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index dd21aa6..23e901b 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,15 @@
+2009-09-21 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Reify the construction of image2d-based complex images.
+
+ * apps/graph-morpho/make_complex2d.hh: New file.
+ * apps/graph-morpho/asf-complex1d.cc: Move the construction of
+ the image2d-based complex...
+ * apps/graph-morpho/make_complex2d.hh (make_complex2d):
+ ...here (new function).
+ * apps/graph-morpho/Makefile.am
+ (noinst_HEADERS): Add make_complex2d.hh.
+
2009-09-18 Roland Levillain <roland(a)lrde.epita.fr>
New application: apps/graph-morpho/asf-complex1d.
diff --git a/milena/apps/graph-morpho/Makefile.am b/milena/apps/graph-morpho/Makefile.am
index d05fba6..d87d61b 100644
--- a/milena/apps/graph-morpho/Makefile.am
+++ b/milena/apps/graph-morpho/Makefile.am
@@ -20,7 +20,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/milena -I$(top_builddir)/milena
APPS_CXXFLAGS = @APPS_CXXFLAGS@
AM_CXXFLAGS = $(APPS_CXXFLAGS)
-noinst_HEADERS = io.hh morpho.hh
+noinst_HEADERS = io.hh morpho.hh make_complex2d.hh
noinst_PROGRAMS = samples-complex1d asf-complex1d
samples_complex1d_SOURCES = samples-complex1d.cc
diff --git a/milena/apps/graph-morpho/asf-complex1d.cc
b/milena/apps/graph-morpho/asf-complex1d.cc
index 3a83c87..72ac574 100644
--- a/milena/apps/graph-morpho/asf-complex1d.cc
+++ b/milena/apps/graph-morpho/asf-complex1d.cc
@@ -35,7 +35,9 @@
#include "apps/graph-morpho/morpho.hh"
+#include "apps/graph-morpho/make_complex2d.hh"
#include "apps/graph-morpho/io.hh"
+
#include "apps/data.hh"
@@ -47,46 +49,10 @@ int main()
image2d<bool> input =
io::pbm::load(MLN_APPS_DIR "/graph-morpho/zebra-noisy.pbm");
- // Create a graph image by doubling the resolution of the input
- // image to insert edges between pixels.
- image2d<bool> input_x2(2 * input.nrows() - 1, 2 * input.ncols() - 1);
- mln_piter_(image2d<bool>) p(input_x2.domain());
- for_all(p)
- {
- point2d p_= p;
- if (p_.row() % 2 == 0)
- {
- if (p_.col() % 2 == 0)
- // Pixel site.
- input_x2(p) = input.at_(p_.row() / 2, p_.col() / 2);
- else
- // Horizontal edge site.
- input_x2(p) =
- input.at_(p_.row() / 2, (p_.col() - 1) / 2) &&
- input.at_(p_.row() / 2, (p_.col() + 1) / 2);
- }
- else
- {
- if (p_.col() % 2 == 0)
- // Vertical edge site.
- input_x2(p) =
- input.at_((p_.row() - 1) / 2, p_.col() / 2) &&
- input.at_((p_.row() + 1) / 2, p_.col() / 2);
- else
- // Square site (not handled, but still set for possible
- // debug outputs).
- input_x2(p) =
- input.at_((p_.row() - 1) / 2, (p_.col() - 1) / 2) &&
- input.at_((p_.row() - 1) / 2, (p_.col() + 1) / 2) &&
- input.at_((p_.row() + 1) / 2, (p_.col() - 1) / 2) &&
- input.at_((p_.row() + 1) / 2, (p_.col() + 1) / 2);
- }
- }
-
-// #if 0
- // FIXME: Debug (remove).
- io::pbm::save(input_x2, "output.pbm");
-// #endif
+ // Create an binary 2d image representing a 4-connexity graph image
+ // (actually, a cubical 2-complex) by doubling the resolution of the
+ // input image to insert edges (and squares) between pixels.
+ image2d<bool> input_x2 = make_complex2d(input);
/* Binary graph-based image with vertices aligned on a discrete 2D grid.
diff --git a/milena/apps/graph-morpho/asf-complex1d.cc
b/milena/apps/graph-morpho/make_complex2d.hh
similarity index 59%
copy from milena/apps/graph-morpho/asf-complex1d.cc
copy to milena/apps/graph-morpho/make_complex2d.hh
index 3a83c87..1859ab0 100644
--- a/milena/apps/graph-morpho/asf-complex1d.cc
+++ b/milena/apps/graph-morpho/make_complex2d.hh
@@ -23,45 +23,48 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-/// \file
-/// \brief Alternate Sequential Filters in graph space implemented on
-/// 1-complex images.
-///
-/// \todo There should be a second version of this program, where the
-/// graph structure is implemented with an actual mln::util::graph.
-
-#include <mln/io/pbm/load.hh>
-#include <mln/io/pbm/save.hh>
-
-#include "apps/graph-morpho/morpho.hh"
+#ifndef APPS_GRAPH_MORPHO_MAKE_COMPLEX2D_HH
+# define APPS_GRAPH_MORPHO_MAKE_COMPLEX2D_HH
-#include "apps/graph-morpho/io.hh"
-#include "apps/data.hh"
+/// \file
+/// \brief Cubical 2-complex creation from a 2D image of pixels.
+# include <mln/core/image/image2d.hh>
-int main()
+/** \brief Create an binary 2D image representing a cubical 2-complex
+ by doubling the resolution of the image \a input images to insert
+ edges and squares "between" the pixels of \a input.
+
+ The values set on "edge" sites and "square" sites are a
+ conjunction of the values on the face of the adjacent faces of
+ immediate lower dimension. */
+template <typename I>
+inline
+mln_concrete(I)
+make_complex2d(const mln::Image<I>& input_)
{
using namespace mln;
- // Input image.
- image2d<bool> input =
- io::pbm::load(MLN_APPS_DIR "/graph-morpho/zebra-noisy.pbm");
+ const I& input = exact(input_);
+ /* FIXME: The construction of OUTPUT is obvioulsy not generic, since
+ it expects I's domain to provide the interface of an mln::box2d.
+ There should be a static precondition on I at the beginning of
+ this function. */
+ typedef mln_concrete(I) O;
+ O output(2 * input.nrows() - 1, 2 * input.ncols() - 1);
- // Create a graph image by doubling the resolution of the input
- // image to insert edges between pixels.
- image2d<bool> input_x2(2 * input.nrows() - 1, 2 * input.ncols() - 1);
- mln_piter_(image2d<bool>) p(input_x2.domain());
+ mln_piter(O) p(output.domain());
for_all(p)
{
- point2d p_= p;
+ point2d p_ = p;
if (p_.row() % 2 == 0)
{
if (p_.col() % 2 == 0)
// Pixel site.
- input_x2(p) = input.at_(p_.row() / 2, p_.col() / 2);
+ output(p) = input.at_(p_.row() / 2, p_.col() / 2);
else
// Horizontal edge site.
- input_x2(p) =
+ output(p) =
input.at_(p_.row() / 2, (p_.col() - 1) / 2) &&
input.at_(p_.row() / 2, (p_.col() + 1) / 2);
}
@@ -69,36 +72,20 @@ int main()
{
if (p_.col() % 2 == 0)
// Vertical edge site.
- input_x2(p) =
+ output(p) =
input.at_((p_.row() - 1) / 2, p_.col() / 2) &&
input.at_((p_.row() + 1) / 2, p_.col() / 2);
else
// Square site (not handled, but still set for possible
// debug outputs).
- input_x2(p) =
+ output(p) =
input.at_((p_.row() - 1) / 2, (p_.col() - 1) / 2) &&
input.at_((p_.row() - 1) / 2, (p_.col() + 1) / 2) &&
input.at_((p_.row() + 1) / 2, (p_.col() - 1) / 2) &&
input.at_((p_.row() + 1) / 2, (p_.col() + 1) / 2);
}
}
-
-// #if 0
- // FIXME: Debug (remove).
- io::pbm::save(input_x2, "output.pbm");
-// #endif
-
- /* Binary graph-based image with vertices aligned on a discrete 2D grid.
-
- Of course, it would have been better, simpler and faster to use a
- cubical 1-complex here, but they are not yet available (as of
- 2009-09-10). */
- typedef mln::bin_1complex_image2d ima_t;
- ima_t graph_ima = make_regular_complex1d_image(input_x2);
-
- // ASF.
- ima_t asf_ima = asf(graph_ima, 8);
-
- // FIXME: Dump output.
- // ...
+ return output;
}
+
+#endif // ! APPS_GRAPH_MORPHO_MAKE_COMPLEX2D_HH
--
1.6.4.2