Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-05-15 Etienne FOLIO <folio(a)lrde.epita.fr>
Small cleanup.
* README: Howto.
* configure: Cleaned.
* morpho.cc: Cleaned.
---
README | 3 +++
configure | 2 +-
morpho.cc | 23 ++++-------------------
3 files changed, 8 insertions(+), 20 deletions(-)
Index: trunk/milena/sandbox/inim/2010/morpho/configure
===================================================================
--- trunk/milena/sandbox/inim/2010/morpho/configure (revision 3847)
+++ trunk/milena/sandbox/inim/2010/morpho/configure (revision 3848)
@@ -31,7 +31,7 @@
echo 'all: morpho' >> Makefile
echo '' >> Makefile
echo 'clean:' >> Makefile
-echo ' rm -f *~ \#*\# *.o morpho' >> Makefile
+echo ' rm -f *~ \#*\# *.o morpho a.out' >> Makefile
echo '' >> Makefile
echo '' >> Makefile
echo '' >> Makefile
Index: trunk/milena/sandbox/inim/2010/morpho/morpho.cc
===================================================================
--- trunk/milena/sandbox/inim/2010/morpho/morpho.cc (revision 3847)
+++ trunk/milena/sandbox/inim/2010/morpho/morpho.cc (revision 3848)
@@ -20,8 +20,7 @@
void
load_img(image2d<int_u8>& ima, const char* filename)
{
- std::cout << " => loadimag " << filename << "...";
- std::cout.flush();
+ std::cout << " => loadimag " << filename << "..." << std::endl;
// load.
image2d<bool> in;
@@ -31,30 +30,24 @@
int_u8 k = 1;
ima = level::convert(k, in);
ima = level::stretch(k, ima);
-
- std::cout << "................[DONE]" << std::endl;
}
void
revert_img(image2d<int_u8>& ima)
{
- std::cout << " => revert image...";
- std::cout.flush();
+ std::cout << " => revert image..." << std::endl;
// revert.
ima = arith::revert(ima);
- std::cout << "...................[DONE]" << std::endl;
}
void
gaussian_filter(image2d<int_u8>& ima, float gaussian_force)
{
- std::cout << " => applying gaussian filter...";
- std::cout.flush();
+ std::cout << " => applying gaussian filter..." << std::endl;
// gaussian filter.
ima = linear::gaussian(ima, gaussian_force, 1);
- std::cout << ".......[DONE]" << std::endl;
}
void
@@ -63,8 +56,7 @@
const unsigned k,
const unsigned lambda)
{
- std::cout << " => applying rank k filter...";
- std::cout.flush();
+ std::cout << " => applying rank k filter..." << std::endl;
// rank filter.
ima = morpho::rank_filter(ima, it, k);
@@ -75,8 +67,6 @@
ima(p) = mln_min(int_u8);
else
ima(p) = mln_max(int_u8);
-
- std::cout << ".........[DONE]" << std::endl;
}
void
@@ -113,12 +103,9 @@
image2d<int_u8> ima;
load_img(ima, input_filename);
image2d<int_u8> in(ima);
- //revert_img(ima);
- io::pgm::save(ima, "1.pgm");
// apply gaussian filter.
gaussian_filter(ima, gaussian_force);
- io::pgm::save(ima, "2.pgm");
// create window.
window2d window;
@@ -131,12 +118,10 @@
// apply k-rank filter.
rank_filter(ima, window, k, lambda);
- io::pgm::save(ima, "3.pgm");
// labelize.
label_8 nlabels = 0;
image2d<label_8> labels = labeling::regional_maxima(ima, c4(), nlabels);
- io::pgm::save(labels, "4.pgm");
// compute output image.
replace_with_labels(labels, in);
Index: trunk/milena/sandbox/inim/2010/morpho/README
===================================================================
--- trunk/milena/sandbox/inim/2010/morpho/README (revision 3847)
+++ trunk/milena/sandbox/inim/2010/morpho/README (revision 3848)
@@ -13,4 +13,7 @@
- then make
- then ./run.sh <input_image.pbm> <output_image.pgm>
+The input image has to be reverted, meaning that the background has to
+be black and the foreground white.
+
You can customize the input variables by editing the run.sh script.
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-05-15 Etienne FOLIO <folio(a)lrde.epita.fr>
Move a script.
* run.sh: New moved file.
* treat.sh: Remove moved file.
---
run.sh | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
Index: trunk/milena/sandbox/inim/2010/morpho/treat.sh (deleted)
===================================================================
Index: trunk/milena/sandbox/inim/2010/morpho/run.sh
===================================================================
--- trunk/milena/sandbox/inim/2010/morpho/run.sh (revision 0)
+++ trunk/milena/sandbox/inim/2010/morpho/run.sh (revision 3847)
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+gaussian_force=20 # best with values around 20
+k=5 # best with values in [|1..10|]
+window_width=20 # best with small values in [|10..30|]
+lambda=5 # best with small values like 5-10
+
+if [ $# -ne 2 ]
+then
+ echo "Usage: ./run.sh <input_image.pbm> <output_image.pgm>"
+ exit 1
+fi
+
+./morpho \
+ $1 \
+ ${gaussian_force} \
+ ${k} \
+ ${window_width} \
+ ${lambda} \
+ $2 \
+ || exit $?
Property changes on: trunk/milena/sandbox/inim/2010/morpho/run.sh
___________________________________________________________________
Name: svn:mergeinfo
+
Name: svn:executable
+ *
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-05-15 Etienne FOLIO <folio(a)lrde.epita.fr>
Big cleanup.
* Makefile: Remove. Not needed.
* README: New explainations.
* configure: To build the Makefile.
* dilation-n.hh: New algorithm.
* erosion-n.hh: New algorithm.
* main_dilation-n.cc: New test file.
* morpho.cc: Cleanup in here.
* treat.sh: Adaptation.
---
README | 16 +++++
configure | 23 -------
dilation-n.hh | 41 ++++++++++++++
erosion-n.hh | 41 ++++++++++++++
main_dilation-n.cc | 54 ++++++++++++++++++
morpho.cc | 153 +++++++++++++++++++++--------------------------------
treat.sh | 35 ++----------
7 files changed, 224 insertions(+), 139 deletions(-)
Index: trunk/milena/sandbox/inim/2010/morpho/Makefile (deleted)
===================================================================
Index: trunk/milena/sandbox/inim/2010/morpho/configure
===================================================================
--- trunk/milena/sandbox/inim/2010/morpho/configure (revision 3845)
+++ trunk/milena/sandbox/inim/2010/morpho/configure (revision 3846)
@@ -1,34 +1,17 @@
#! /bin/bash
-
-
if [ "$1" = "--debug" ]; then
-
DEBUG_FLAGS=" -g -ggdb "
OPT_FLAGS=""
else
-
OPT_FLAGS=" -DNDEBUG -O3 "
DEBUG_FLAGS=""
fi
-
-
-if [ "$2" = "--duma" ]; then
- LIB_PATH="-L/lrde/beyrouth/lrde-2011/da-mota/utils/duma "
- LIB=" -lduma "
-else
- LIB_PATH=" "
- LIB=" "
-fi
-
-
-CXXFLAGS="-Wall -Wextra -W -Werror -pedantic "
-
+CXXFLAGS="-Wall -Wextra -W -pedantic "
echo -n ' => Generating Makefile... '
-
echo 'CXX=g++' > Makefile
echo 'CXXFLAGS='${CXXFLAGS} >> Makefile
echo '' >> Makefile
@@ -57,8 +40,6 @@
echo '' >> Makefile
echo '' >> Makefile
echo '%.o: %.cc' >> Makefile
-echo ' $(CXX) $(CXXFLAGS) ' -I/work/$USER/milena '-c $< -o $@' >> Makefile
+echo ' $(CXX) $(CXXFLAGS) ' -I../../../../ '-c $< -o $@' >> Makefile
echo '' >> Makefile
-
-
echo ' [DONE]'
\ No newline at end of file
Index: trunk/milena/sandbox/inim/2010/morpho/main_dilation-n.cc
===================================================================
--- trunk/milena/sandbox/inim/2010/morpho/main_dilation-n.cc (revision 0)
+++ trunk/milena/sandbox/inim/2010/morpho/main_dilation-n.cc (revision 3846)
@@ -0,0 +1,54 @@
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <mln/debug/println.hh>
+#include <mln/data/fill.hh>
+
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/level/convert.hh>
+#include <mln/level/stretch.hh>
+
+#include <mln/core/alias/window2d.hh>
+
+#include "dilation-n.hh"
+#include "erosion-n.hh"
+
+int main(int argc, char** argv)
+{
+ using namespace mln;
+
+ // check arguments
+ if (argc != 5)
+ {
+ std::cerr << "Usage:" << std::endl
+ << " ./a.out <in.pbm> <out.pbm> <k> <lambda>" << std::endl;
+ exit(1);
+ }
+
+ // build test image
+ std::cout << " => loading " << argv[1] << "..." << std::endl;
+ image2d<bool> in;
+ io::pbm::load(in, argv[1]);
+
+ value::int_u8 k = 1;
+ image2d<value::int_u8> ima = level::convert(k, in);
+ ima = level::stretch(k, ima);
+
+ std::cout << " => create window..." << std::endl;
+ window2d it;
+ it.insert(0, 0);
+ for (unsigned i = 1; i <= atoi(argv[3]); ++i)
+ {
+ it.insert(0, -i);
+ it.insert(0, i);
+ }
+
+ std::cout << " => applying dilation..." << std::endl;
+ image2d<value::int_u8> out;
+ out = morpho::erosion_n(ima, it, atoi(argv[4]));
+
+ std::cout << " => saving " << argv[2] << "..." << std::endl;
+ io::pgm::save(out, argv[2]);
+}
Index: trunk/milena/sandbox/inim/2010/morpho/erosion-n.hh
===================================================================
--- trunk/milena/sandbox/inim/2010/morpho/erosion-n.hh (revision 0)
+++ trunk/milena/sandbox/inim/2010/morpho/erosion-n.hh (revision 3846)
@@ -0,0 +1,41 @@
+#include <mln/core/concept/image.hh>
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ template <typename I, typename W>
+ inline
+ I
+ erosion_n(const Image<I>& ima_,
+ const W& win,
+ const unsigned lambda)
+ {
+ const I& ima = exact(ima_);
+ mln_precondition(ima.is_valid());
+
+ I out;
+ initialize(out, ima);
+
+ mln_piter(I) p(ima.domain());
+ mln_qiter(W) q(win, p);
+
+ for_all(p)
+ {
+ unsigned i = 0;
+ for_all(q)
+ if (ima.has(q) && ima(q) != mln_max(mln_value(I)))
+ ++i;
+
+ out(p) = (i >= lambda)
+ ? mln_min(mln_value(I))
+ : ima(p);
+ }
+
+ return out;
+ }
+
+ }
+}
Index: trunk/milena/sandbox/inim/2010/morpho/morpho.cc
===================================================================
--- trunk/milena/sandbox/inim/2010/morpho/morpho.cc (revision 3845)
+++ trunk/milena/sandbox/inim/2010/morpho/morpho.cc (revision 3846)
@@ -1,124 +1,93 @@
#include <iostream>
#include <sstream>
#include <string>
-#include <mln/debug/println.hh>
+#include <mln/arith/revert.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/alias/window2d.hh>
#include <mln/io/pbm/load.hh>
#include <mln/io/pgm/save.hh>
-
-
-#include <mln/core/alias/neighb2d.hh>
-#include <mln/accu/max.hh>
-#include <mln/value/label_8.hh>
#include <mln/labeling/regional_maxima.hh>
-#include <mln/data/fill.hh>
-#include <mln/literal/all.hh>
-#include <mln/arith/revert.hh>
#include <mln/level/convert.hh>
#include <mln/level/stretch.hh>
-#include <mln/morpho/closing/structural.hh>
-#include <mln/core/alias/window2d.hh>
-#include <mln/make/win_chamfer.hh>
#include <mln/linear/gaussian.hh>
-
#include <mln/morpho/rank_filter.hh>
+#include <mln/value/label_8.hh>
using namespace mln;
using namespace mln::value;
void
-load_img(image2d<bool>& in, const char* filename)
+load_img(image2d<int_u8>& ima, const char* filename)
{
- using namespace mln;
-
- // build test image
- std::cout << " => loading " << filename << "...";
+ std::cout << " => loadimag " << filename << "...";
std::cout.flush();
+
+ // load.
+ image2d<bool> in;
io::pbm::load(in, filename);
+
+ // convert and stretch.
+ int_u8 k = 1;
+ ima = level::convert(k, in);
+ ima = level::stretch(k, ima);
+
std::cout << "................[DONE]" << std::endl;
}
-
void
-revert_img(image2d<int_u8>& out,
- const image2d<bool>& in)
+revert_img(image2d<int_u8>& ima)
{
- using namespace mln;
-
- int_u8 k = 1;
- out = level::convert(k, in);
- out = level::stretch(k, out);
-
std::cout << " => revert image...";
std::cout.flush();
- out = arith::revert(out);
- std::cout << "...................[DONE]" << std::endl;
+ // revert.
+ ima = arith::revert(ima);
+ std::cout << "...................[DONE]" << std::endl;
}
-
-
-
void
-gaussian_filter(image2d<int_u8>& out, int gaussian_force)
+gaussian_filter(image2d<int_u8>& ima, float gaussian_force)
{
- using namespace mln;
-
std::cout << " => applying gaussian filter...";
std::cout.flush();
- out = linear::gaussian(out, gaussian_force, 1);
- // out = linear::gaussian_1st_derivative(out, gaussian_force, 1);
+
+ // gaussian filter.
+ ima = linear::gaussian(ima, gaussian_force, 1);
std::cout << ".......[DONE]" << std::endl;
}
-
-
-
-
-
-image2d<int_u8>
-rank_filter(const image2d<int_u8>& out,
- window2d it, int k, unsigned int lambda)
+void
+rank_filter(image2d<int_u8>& ima,
+ const window2d& it,
+ const unsigned k,
+ const unsigned lambda)
{
- using namespace mln;
-
std::cout << " => applying rank k filter...";
std::cout.flush();
- image2d<int_u8> rank_filtered = morpho::rank_filter(out, it, k);
+ // rank filter.
+ ima = morpho::rank_filter(ima, it, k);
- for (unsigned int y = 0; y <= rank_filtered.ncols () - 1; ++y)
- for (unsigned int x = 0; x <= rank_filtered.nrows() - 1; ++x)
- {
- if (rank_filtered(point2d(x, y)) < lambda)
- rank_filtered(point2d(x, y)) = 0;
+ mln_fwd_piter_(image2d<int_u8>) p(ima.domain());
+ for_all(p)
+ if (ima(p) < lambda)
+ ima(p) = mln_min(int_u8);
else
- rank_filtered(point2d(x, y)) = 255;
- }
+ ima(p) = mln_max(int_u8);
std::cout << ".........[DONE]" << std::endl;
-
- return rank_filtered;
}
-
-
-
-
void
-look_for_lines(const image2d<label_8>& labels, image2d<int_u8>& ima)
+replace_with_labels(const image2d<label_8>& labels, image2d<int_u8>& ima)
{
mln_fwd_piter_(image2d<int_u8>) p(ima.domain());
for_all(p)
- {
if (ima(p) == mln_max(int_u8))
- {
- ima(p) = labels(p);
- }
- }
+ ima(p) = labels(p); // replace with label at p.
}
-
int
main(int argc, char** argv)
{
@@ -126,46 +95,50 @@
if (argc != 7)
{
std::cerr << "Usage:" << std::endl
- << " ./morpho <in.pbm> <gaussian_force> <k> "
+ << " ./morpho <ima.pbm> <gaussian_force> <k> "
<< "<window_width> <lambda> "
- << "<output_filename>" << std::endl;
+ << "<input_filename>" << std::endl;
exit(1);
}
+ // get argv variables.
const char* input_filename = argv[1];
- float gaussian_force = atof(argv[2]);
-
- unsigned int k = atoi(argv[3]);
- unsigned int w_width = atoi(argv[4]);
- unsigned int lambda = atoi(argv[5]);
+ const float gaussian_force = atof(argv[2]);
+ const unsigned k = atoi(argv[3]);
+ const unsigned w_width = atoi(argv[4]);
+ const unsigned lambda = atoi(argv[5]);
const char* output_filename = argv[6];
+ // load and revert image.
+ image2d<int_u8> ima;
+ load_img(ima, input_filename);
+ image2d<int_u8> in(ima);
+ //revert_img(ima);
+ io::pgm::save(ima, "1.pgm");
+
+ // apply gaussian filter.
+ gaussian_filter(ima, gaussian_force);
+ io::pgm::save(ima, "2.pgm");
- image2d<bool> in;
- load_img(in, input_filename);
-
- int_u8 i = 1;
- image2d<int_u8> in_u8 = level::convert(i, in);
- in_u8 = level::stretch(i, in_u8);
-
- image2d<int_u8> out = in_u8;
- gaussian_filter(out, gaussian_force);
-
+ // create window.
window2d window;
window.insert(0, 0);
-
for (unsigned i = 1; i <= w_width; ++i)
{
window.insert(0, -i);
window.insert(0, i);
}
- image2d<int_u8> ima =
- rank_filter(out, window, k, lambda);
+ // apply k-rank filter.
+ rank_filter(ima, window, k, lambda);
+ io::pgm::save(ima, "3.pgm");
+ // labelize.
label_8 nlabels = 0;
image2d<label_8> labels = labeling::regional_maxima(ima, c4(), nlabels);
+ io::pgm::save(labels, "4.pgm");
- look_for_lines(labels, in_u8);
- io::pgm::save(in_u8, output_filename);
+ // compute output image.
+ replace_with_labels(labels, in);
+ io::pgm::save(in, output_filename);
}
Index: trunk/milena/sandbox/inim/2010/morpho/treat.sh
===================================================================
--- trunk/milena/sandbox/inim/2010/morpho/treat.sh (revision 3845)
+++ trunk/milena/sandbox/inim/2010/morpho/treat.sh (revision 3846)
@@ -1,42 +1,21 @@
#!/bin/sh
-
-
gaussian_force=20 # best with values around 20
k=5 # best with values in [|1..10|]
window_width=20 # best with small values in [|10..30|]
lambda=5 # best with small values like 5-10
-OUTPUT_DIR=output
-
-if [ $# -eq 0 ]
+if [ $# -ne 2 ]
then
+ echo "Usage: ./run.sh <input_image.pbm> <output_image.pgm>"
+ exit 1
+fi
- echo -n 'Cleaning output directory........'
- rm -f /lrde/beyrouth/lrde-2011/da-mota/images_INIM/result/*
- echo '......[DONE]'
-
- mkdir -p ${OUTPUT_DIR}
-
- for filename in `echo *.pbm`
- do
- output_filename=${OUTPUT_DIR}/${filename}
-
- ~/morpho/morpho \
- ${filename} \
+./morpho \
+ $1 \
${gaussian_force} \
${k} \
${window_width} \
${lambda} \
- ${output_filename} \
+ $2 \
|| exit $?
-
- done
-
-fi
-
-
-for i in `ls ${OUTPUT_DIR}/*.pbm`
-do
- display $i
-done
Index: trunk/milena/sandbox/inim/2010/morpho/dilation-n.hh
===================================================================
--- trunk/milena/sandbox/inim/2010/morpho/dilation-n.hh (revision 0)
+++ trunk/milena/sandbox/inim/2010/morpho/dilation-n.hh (revision 3846)
@@ -0,0 +1,41 @@
+#include <mln/core/concept/image.hh>
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ template <typename I, typename W>
+ inline
+ I
+ dilation_n(const Image<I>& ima_,
+ const W& win,
+ const unsigned lambda)
+ {
+ const I& ima = exact(ima_);
+ mln_precondition(ima.is_valid());
+
+ I out;
+ initialize(out, ima);
+
+ mln_piter(I) p(ima.domain());
+ mln_qiter(W) q(win, p);
+
+ for_all(p)
+ {
+ unsigned i = 0;
+ for_all(q)
+ if (ima.has(q) && ima(q) != mln_min(mln_value(I)))
+ ++i;
+
+ out(p) = (i >= lambda)
+ ? mln_max(mln_value(I))
+ : ima(p);
+ }
+
+ return out;
+ }
+
+ }
+}
Index: trunk/milena/sandbox/inim/2010/morpho/README
===================================================================
--- trunk/milena/sandbox/inim/2010/morpho/README (revision 0)
+++ trunk/milena/sandbox/inim/2010/morpho/README (revision 3846)
@@ -0,0 +1,16 @@
+== Dilation and erosion==
+
+Dilation and erosion: how to make a k-rank filter when it already exists:
+
+We developed those algorithms in erosion-n.hh and dilation-n.hh.
+You can test those by running main_dilation-n.cc.
+
+
+== Main morpho work ==
+
+The code is located in morpho.cc. You can run it by following those steps:
+- type ./configure in the shell
+- then make
+- then ./run.sh <input_image.pbm> <output_image.pgm>
+
+You can customize the input variables by editing the run.sh script.
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Update segmentation code.
* theo/igr/segment_2d_t.cc: Replace area by height.
* theo/igr/dump_to_dist.cc: New.
dump_to_dist.cc | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
segment_2d_t.cc | 4 -
2 files changed, 162 insertions(+), 2 deletions(-)
Index: theo/igr/segment_2d_t.cc
--- theo/igr/segment_2d_t.cc (revision 3843)
+++ theo/igr/segment_2d_t.cc (working copy)
@@ -16,7 +16,7 @@
#include <mln/value/label.hh>
#include <mln/level/transform.hh>
-#include <mln/morpho/closing/area.hh>
+#include <mln/morpho/closing/height.hh>
#include <mln/morpho/watershed/flooding.hh>
#include <mln/accu/mean.hh>
#include <mln/labeling/compute.hh>
@@ -96,7 +96,7 @@
// debug_println("d", d);
io_save_edges_int_u12(d, 0, "d.pgm");
- mln_VAR(d_clo, morpho::closing::area(d, e2e(), lambda));
+ mln_VAR(d_clo, morpho::closing::height(d, e2e(), lambda));
// debug_println("d_clo", d_clo);
io_save_edges_int_u12(d_clo, 0, "d_clo.pgm");
Index: theo/igr/dump_to_dist.cc
--- theo/igr/dump_to_dist.cc (revision 0)
+++ theo/igr/dump_to_dist.cc (revision 0)
@@ -0,0 +1,160 @@
+#include <cstdio>
+
+#include <mln/core/var.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/slice_image.hh>
+#include <mln/core/routine/duplicate.hh>
+#include <mln/core/concept/function.hh>
+
+#include <mln/value/int_u12.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/dump/load.hh>
+#include <mln/io/dump/save.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/util/array.hh>
+#include <mln/level/transform.hh>
+#include <mln/data/paste.hh>
+
+#include <mln/morpho/elementary/closing.hh>
+
+#include <mln/world/inter_pixel/immerse.hh>
+#include <mln/world/inter_pixel/is_separator.hh>
+#include <mln/world/inter_pixel/separator_to_pixels.hh>
+#include <mln/world/inter_pixel/display_edge.hh>
+#include <mln/world/inter_pixel/neighb2d.hh>
+
+
+
+
+namespace mln
+{
+
+ const float saturation = 0.5f;
+
+ struct int_u8_from_float : Function_v2v< int_u8_from_float >
+ {
+ typedef value::int_u8 result;
+ result operator()(float f) const
+ {
+ f /= saturation;
+ if (f < 0.f)
+ return 0u;
+ if (f > 1.f)
+ return 255u;
+ return f * 255;
+ }
+ };
+
+
+ // Distance function.
+ struct fun_dist : Function_vv2v< fun_dist >
+ {
+ typedef float result;
+
+ template <typename V>
+ float operator()(const util::array<V>& v1,
+ const util::array<V>& v2) const
+ {
+ const unsigned n = v1.nelements();
+ float
+ sum_min = 0.f,
+ sum_v1 = 0.f, sum_v2 = 0.f;
+
+ for (unsigned i = 0; i < n; ++i)
+ {
+ sum_min += std::min(v1[i], v2[i]);
+ sum_v1 += v1[i];
+ sum_v2 += v2[i];
+ }
+
+ float res = 1.f - sum_min / std::max(sum_v1, sum_v2);
+ if (res < 0.f || res > 1.f)
+ {
+ std::cerr << "oops!" << std::endl;
+ std::abort();
+ }
+ return res;
+ }
+
+ };
+
+} // mln
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u12;
+
+ if (argc != 3)
+ std::abort();
+
+ border::thickness = 0;
+
+ image3d<int_u12> input;
+ io::dump::load(input, argv[1]);
+
+ unsigned n = input.nslices();
+ std::cout << "n = " << n << std::endl;
+
+
+ typedef image2d<util::array<int_u12> > I;
+ I ima;
+
+ mln_VAR(sli_0, slice(input, 0));
+ initialize(ima, sli_0);
+
+ box2d b = sli_0.domain();
+ std::cout << "b = " << b << std::endl;
+
+ // Initialization: resizing of arrays.
+ mln_piter_(box2d) p(b);
+ for_all(p)
+ ima(p).resize(n);
+
+ // Copying.
+ for (unsigned t = 0; t < n; ++t)
+ {
+ image2d<int_u12> sli_t = duplicate(slice(input, t));
+ for_all(p)
+ ima(p)[t] = sli_t(p);
+ }
+
+ if (input.nelements() != n * b.nsites())
+ std::cerr << "oops!" << std::endl;
+
+// FILE* file = std::fopen(argv[2], "w");
+// std::fwrite(ima.buffer(), input.nelements() * sizeof(int_u12), 1, file);
+// std::fclose(file);
+
+ using namespace world::inter_pixel;
+ mln_VAR(ima_, immerse(ima));
+
+ image2d<float> d_(ima_.unmorph_().domain());
+ mln_VAR(d, d_ | is_separator());
+
+ {
+ fun_dist f;
+ mln_piter_(d_t) e(d.domain());
+ for_all(e)
+ {
+ point2d p1, p2;
+ separator_to_pixels(e, p1, p2);
+ d(e) = f(ima_(p1), ima_(p2));
+ }
+
+ }
+
+// data::paste(morpho::elementary::closing(d, e2e()),
+// d);
+
+ io::dump::save(d_, argv[2]);
+
+// mln_VAR(d_8, level::transform(d, int_u8_from_float()));
+
+// io::pgm::save(display_edge(d_8.unmorph_(), 0, 3),
+// argv[2]);
+
+}
1
0
Sorry for my recent messages; git-lrde generated messages from previous
commit I was not the author of. I'll try to resend proper messages
later.
1
0
* mln/make/influence_zone_adjacency_graph.hh,
* mln/make/region_adjacency_graph.hh: make use of this new structure.
* mln/util/adjacency_matrix.hh: new structure.
* tests/util/Makefile.am,
* tests/util/adjacency_matrix.cc: associated test.
---
milena/ChangeLog | 12 +
milena/mln/make/influence_zone_adjacency_graph.hh | 17 +-
milena/mln/make/region_adjacency_graph.hh | 15 +-
milena/mln/util/adjacency_matrix.hh | 335 +++++++++++++++++++++
milena/tests/util/Makefile.am | 3 +
milena/tests/util/adjacency_matrix.cc | 76 +++++
6 files changed, 440 insertions(+), 18 deletions(-)
create mode 100644 milena/mln/util/adjacency_matrix.hh
create mode 100644 milena/tests/util/adjacency_matrix.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index d68a7e9..ff6c707 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,17 @@
2009-05-06 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add adjacency matrix.
+
+ * mln/make/influence_zone_adjacency_graph.hh,
+ * mln/make/region_adjacency_graph.hh: make use of this new structure.
+
+ * mln/util/adjacency_matrix.hh: new structure.
+
+ * tests/util/Makefile.am,
+ * tests/util/adjacency_matrix.cc: associated test.
+
+2009-05-06 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Small fixes.
* doc/tutorial/tutorial.tex: fix compilation.
diff --git a/milena/mln/make/influence_zone_adjacency_graph.hh b/milena/mln/make/influence_zone_adjacency_graph.hh
index 7113962..6cbaa4c 100644
--- a/milena/mln/make/influence_zone_adjacency_graph.hh
+++ b/milena/mln/make/influence_zone_adjacency_graph.hh
@@ -44,6 +44,8 @@
# include <mln/core/alias/box2d.hh>
# include <mln/extension/adjust_fill.hh>
# include <mln/util/graph.hh>
+# include <mln/util/adjacency_matrix.hh>
+
namespace mln
{
@@ -104,8 +106,7 @@ namespace mln
const I& iz = exact(iz_);
const N& nbh = exact(nbh_);
- mln::image2d<bool> adj(mln::box2d(nlabels.next(), nlabels.next()));
- data::fill(adj, false);
+ util::adjacency_matrix<> adj(nlabels.next());
extension::adjust_fill(iz, nbh, 0u);
typedef mln_value(I) L;
@@ -120,13 +121,7 @@ namespace mln
{
L l2 = iz(n);
if (iz(n) != iz((p)))
- {
- // l2 is adjacent to l1
- if (l2 < l1)
- adj(point2d(l1,l2)) = true;
- else
- adj(point2d(l2,l1)) = true;
- }
+ adj.add(l1, l2);
}
}
}
@@ -134,9 +129,9 @@ namespace mln
// Construct graph.
util::graph g;
g.add_vertices(nlabels.next());
- for (unsigned i = 0; i < geom::nrows(adj); ++i)
+ for (unsigned i = 0; i < nlabels.next(); ++i)
for (unsigned j = 0; j < i; ++j)
- if (adj(point2d(i,j)))
+ if (adj.are_adjacent(i, j))
g.add_edge(i, j);
trace::exiting("make::impl::generic::influence_zone_adjacency_graph");
diff --git a/milena/mln/make/region_adjacency_graph.hh b/milena/mln/make/region_adjacency_graph.hh
index 695174d..b930367 100644
--- a/milena/mln/make/region_adjacency_graph.hh
+++ b/milena/mln/make/region_adjacency_graph.hh
@@ -33,6 +33,8 @@
/// Create a region_adjacency_graph from a watershed image.
///
/// \sa morpho::meyer_wst.
+///
+/// \todo add dispatch.
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
@@ -40,6 +42,8 @@
# include <mln/core/alias/box2d.hh>
# include <mln/extension/adjust_fill.hh>
# include <mln/util/graph.hh>
+# include <mln/util/adjacency_matrix.hh>
+
namespace mln
{
@@ -100,8 +104,7 @@ namespace mln
const I& wshd = exact(wshd_);
const N& nbh = exact(nbh_);
- mln::image2d<bool> adj(mln::box2d(nbasins.next(), nbasins.next()));
- data::fill(adj, false);
+ util::adjacency_matrix<> adj(nbasins.next());
extension::adjust_fill(wshd, nbh, 0u);
typedef mln_value(I) L;
@@ -129,19 +132,17 @@ namespace mln
}
if (l2 == 0u || l1 == 0u)
continue;
- if (l2 < l1)
- std::swap(l1, l2);
// adjacency l1 l2
- adj(point2d(l2,l1)) = true;
+ adj.add(l2, l1);
}
// Construct graph.
util::graph g;
g.add_vertices(nbasins.next());
- for (unsigned i = 1; i < geom::nrows(adj); ++i)
+ for (unsigned i = 1; i < nbasins.next(); ++i)
for (unsigned j = 1; j < i; ++j)
- if (adj(point2d(i,j)))
+ if (adj.are_adjacent(i, j))
g.add_edge(i, j);
diff --git a/milena/mln/util/adjacency_matrix.hh b/milena/mln/util/adjacency_matrix.hh
new file mode 100644
index 0000000..dfda26f
--- /dev/null
+++ b/milena/mln/util/adjacency_matrix.hh
@@ -0,0 +1,335 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_UTIL_ADJACENCY_MATRIX_HH
+# define MLN_UTIL_ADJACENCY_MATRIX_HH
+
+/// \file mln/util/adjacency_matrix.hh
+///
+/// A class of adjacency matrix.
+///
+/// FIXME: the underlying data structure is chosen according
+/// to the value type quantification however we may like to make it
+/// depend on the number of elements.
+
+# include <mln/core/image/image2d.hh>
+# include <mln/util/set.hh>
+# include <mln/util/ord_pair.hh>
+# include <mln/trait/value_.hh>
+# include <mln/metal/converts_to.hh>
+# include <mln/debug/println.hh>
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ namespace internal
+ {
+
+ // Implementation for low quantification.
+
+ template <typename V, typename Q>
+ struct adjacency_matrix_impl_selector
+ {
+ /// Data structure used to store adjacency information.
+ typedef image2d<bool> adj_t;
+
+ /// Constructor.
+ adjacency_matrix_impl_selector(const V& nelements);
+
+ /// Make \p e1 and \p e2 adjacent.
+ void add(const V& e1, const V& e2);
+
+ /// Remove adjacency between \p e1 and \p e2.
+ void remove(const V& e1, const V& e2);
+
+ /// Clear all adjacencies.
+ void clear();
+
+ /// Check whether \p e1 and \p e2 are adjacent.
+ bool are_adjacent(const V& e1, const V& e2) const;
+
+ /// Print data to std::out.
+ std::ostream& print_data_(std::ostream& ostr) const;
+
+ protected:
+ adj_t adj_;
+ };
+
+
+ // Implementation for high quantification.
+
+ template <typename V>
+ struct adjacency_matrix_impl_selector<V, metal::bool_<false> >
+ {
+ /// Data structure used to store adjacency information.
+ typedef util::set< util::ord_pair<V> > adj_t;
+
+ /// Constructor.
+ adjacency_matrix_impl_selector(const V& nelements);
+
+ /// Make \p e1 and \p e2 adjacent.
+ void add(const V& e1, const V& e2);
+
+ /// Remove adjacency between \p e1 and \p e2.
+ void remove(const V& e1, const V& e2);
+
+ /// Clear all adjacencies.
+ void clear();
+
+ /// Check whether \p e1 and \p e2 are adjacent.
+ bool are_adjacent(const V& e1, const V& e2) const;
+
+ /// Print data to std::out.
+ std::ostream& print_data_(std::ostream& ostr) const;
+
+ protected:
+ adj_t adj_;
+
+# ifndef NDEBUG
+ unsigned nelements_;
+# endif // ! NDEBUG
+ };
+
+
+ } // end of namespace mln::util::internal
+
+
+ /// A class of adjacency matrix.
+ ///
+ /// Support low and high quantification value types.
+ /// In case of low quantification value type, it uses
+ /// an image2d to store adjacency information.
+ /// In case of high quantification value type, it uses
+ /// a util::set to store the adjacency information.
+ ///
+ /// \ingroup modutil
+ //
+ template <typename V = def::coord>
+ class adjacency_matrix
+ : private mlc_converts_to(V,unsigned)::check_t,
+ public internal::adjacency_matrix_impl_selector<V, typename mlc_equal(mln_trait_value_quant(V),trait::value::quant::low)::eval>
+ {
+ typedef internal::adjacency_matrix_impl_selector<V, typename mlc_equal(mln_trait_value_quant(V),trait::value::quant::low)::eval>
+ impl_t;
+
+ typedef typename impl_t::adj_t adj_t;
+
+ public:
+ /// Constructors.
+ /// \@{
+ ///
+ /// Default
+ adjacency_matrix();
+ /// Construct an adjacency matrix with \p nelements elements
+ /// maximum.
+ adjacency_matrix(const V& nelements);
+ ///
+ /// \@}
+
+ /// Hook member used to retrieve the underlying data structure.
+ const adj_t& hook_data_() const;
+ };
+
+
+ // <<
+
+ template <typename V>
+ std::ostream&
+ operator<<(std::ostream& ostr, const adjacency_matrix<V>& adj);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ // Low quantification.
+
+ template <typename V, typename Q>
+ adjacency_matrix_impl_selector<V, Q>::adjacency_matrix_impl_selector(const V& nelements)
+ : adj_(nelements, nelements)
+ {
+ clear();
+ }
+
+ template <typename V, typename Q>
+ void
+ adjacency_matrix_impl_selector<V, Q>::add(const V& e1, const V& e2)
+ {
+ mln_precondition(adj_.is_valid());
+ mln_precondition(e1 < adj_.nrows());
+ mln_precondition(e2 < adj_.nrows());
+
+ if (e1 > e2)
+ opt::at(adj_, e2, e1) = true;
+ else
+ opt::at(adj_, e1, e2) = true;
+ }
+
+ template <typename V, typename Q>
+ void
+ adjacency_matrix_impl_selector<V, Q>::remove(const V& e1, const V& e2)
+ {
+ mln_precondition(adj_.is_valid());
+ mln_precondition(e1 < adj_.nrows());
+ mln_precondition(e2 < adj_.nrows());
+
+ if (e1 > e2)
+ opt::at(adj_, e2, e1) = false;
+ else
+ opt::at(adj_, e1, e2) = false;
+ }
+
+ template <typename V, typename Q>
+ void
+ adjacency_matrix_impl_selector<V, Q>::clear()
+ {
+ mln_precondition(adj_.is_valid());
+ data::fill(adj_, false);
+ }
+
+ template <typename V, typename Q>
+ bool
+ adjacency_matrix_impl_selector<V, Q>::are_adjacent(const V& e1,
+ const V& e2) const
+ {
+ mln_precondition(adj_.is_valid());
+ mln_precondition(e1 < adj_.nrows());
+ mln_precondition(e2 < adj_.nrows());
+
+ if (e1 > e2)
+ return opt::at(adj_, e2, e1);
+ return opt::at(adj_, e1, e2);
+ }
+
+ template <typename V, typename Q>
+ std::ostream&
+ adjacency_matrix_impl_selector<V, Q>::print_data_(std::ostream& ostr) const
+ {
+ mln_precondition(adj_.is_valid());
+ debug::println(adj_);
+ return ostr;
+ }
+
+
+
+
+ // High quantification.
+
+ template <typename V>
+ adjacency_matrix_impl_selector<V, metal::bool_<false> >
+ ::adjacency_matrix_impl_selector(const V& nelements)
+ {
+ (void) nelements;
+# ifndef DNDEBUG
+ nelements_ = nelements;
+# endif // ! DNDEBUG
+ }
+
+ template <typename V>
+ void
+ adjacency_matrix_impl_selector<V, metal::bool_<false> >
+ ::add(const V& e1, const V& e2)
+ {
+ mln_precondition(e1 < nelements_);
+ mln_precondition(e2 < nelements_);
+ adj_.insert(make::ord_pair(e1, e2));
+ }
+
+ template <typename V>
+ void
+ adjacency_matrix_impl_selector<V, metal::bool_<false> >
+ ::remove(const V& e1, const V& e2)
+ {
+ mln_precondition(e1 < nelements_);
+ mln_precondition(e2 < nelements_);
+ mln_precondition(adj_.has(make::ord_pair(e1, e2)));
+ adj_.remove(make::ord_pair(e1, e2));
+ }
+
+ template <typename V>
+ void
+ adjacency_matrix_impl_selector<V, metal::bool_<false> >::clear()
+ {
+ adj_.clear();
+ }
+
+ template <typename V>
+ bool
+ adjacency_matrix_impl_selector<V, metal::bool_<false> >
+ ::are_adjacent(const V& e1, const V& e2) const
+ {
+ mln_precondition(e1 < nelements_);
+ mln_precondition(e2 < nelements_);
+ return adj_.has(make::ord_pair(e1, e2));
+ }
+
+ template <typename V>
+ std::ostream&
+ adjacency_matrix_impl_selector<V, metal::bool_<false> >::print_data_(std::ostream& ostr) const
+ {
+ return ostr << adj_;
+ }
+
+ } // end of namespace mln::internal
+
+
+ template <typename V>
+ adjacency_matrix<V>::adjacency_matrix()
+ : impl_t()
+ {
+ }
+
+
+ template <typename V>
+ adjacency_matrix<V>::adjacency_matrix(const V& nelements)
+ : impl_t(nelements)
+ {
+ }
+
+
+ template <typename V>
+ std::ostream&
+ operator<<(std::ostream& ostr, const adjacency_matrix<V>& adj)
+ {
+ return adj.print_data_(ostr);
+ }
+
+
+# endif // ! MLN_UTIL_ADJACENCY_MATRIX_HH
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+
+#endif // ! MLN_UTIL_ADJACENCY_MATRIX_HH
diff --git a/milena/tests/util/Makefile.am b/milena/tests/util/Makefile.am
index c1d6c4d..07b6018 100644
--- a/milena/tests/util/Makefile.am
+++ b/milena/tests/util/Makefile.am
@@ -4,6 +4,7 @@ include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
+ adjacency_matrix \
branch_iter \
branch_iter_ind \
eat \
@@ -21,6 +22,8 @@ check_PROGRAMS = \
tree_to_fast \
tree_to_image
+
+adjacency_matrix_SOURCES = adjacency_matrix.cc
branch_iter_SOURCES = branch_iter.cc
branch_iter_ind_SOURCES = branch_iter_ind.cc
eat_SOURCES = eat.cc
diff --git a/milena/tests/util/adjacency_matrix.cc b/milena/tests/util/adjacency_matrix.cc
new file mode 100644
index 0000000..e67f659
--- /dev/null
+++ b/milena/tests/util/adjacency_matrix.cc
@@ -0,0 +1,76 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// \file tests/util/adjacency_matrix.cc
+///
+/// test of mln::util::adjacency_matrix
+
+#include <mln/util/adjacency_matrix.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+
+int main()
+{
+ using namespace mln;
+
+ // The underlying data structure is a image2d.
+ {
+ util::adjacency_matrix<value::int_u8> adj(5);
+ adj.add(3, 4);
+ adj.add(2, 3);
+ adj.add(1, 2);
+
+ mln_assertion(adj.are_adjacent(2,3));
+ mln_assertion(adj.are_adjacent(4,3));
+ mln_assertion(adj.are_adjacent(2,1));
+ mln_assertion(adj.are_adjacent(1,2));
+ mln_assertion(!adj.are_adjacent(1,4));
+
+ adj.remove(2,3);
+ mln_assertion(!adj.are_adjacent(2,3));
+ mln_assertion(!adj.are_adjacent(2,2));
+ }
+
+ // The underlying data structure is a util::set
+ {
+ util::adjacency_matrix<value::int_u16> adj(5);
+ adj.add(3, 4);
+ adj.add(2, 3);
+ adj.add(1, 2);
+
+ mln_assertion(adj.are_adjacent(2,3));
+ mln_assertion(adj.are_adjacent(4,3));
+ mln_assertion(adj.are_adjacent(2,1));
+ mln_assertion(adj.are_adjacent(1,2));
+ mln_assertion(!adj.are_adjacent(1,4));
+
+ adj.remove(2,3);
+ mln_assertion(!adj.are_adjacent(2,3));
+ mln_assertion(!adj.are_adjacent(2,2));
+ }
+
+}
--
1.6.1.2
1
1
* doc/tutorial/tutorial.tex: fix compilation.
* mln/core/internal/neighb_niter_impl.hh: fix ambiguities and add more
doc.
* mln/fun/v2v/rgb_to_hsl.hh: remove duplicate declarations.
* mln/literal/one.hh,
* mln/literal/zero.hh: add 'const' qualification to conversion
operator.
* mln/make/edge_image.hh: update prototype.
* mln/make/rag_and_labeled_wsl.hh: remove useless local variable.
* mln/pw/internal/image_base.hh: add missing include.
* mln/util/vertex.hh: add missing include and forward declaration.
* tests/util/set.cc: update header.
---
milena/ChangeLog | 25 +++++++++++
milena/doc/tutorial/tutorial.tex | 25 +++++++----
milena/mln/core/internal/neighb_niter_impl.hh | 56 ++++++++++++++++++++++---
milena/mln/fun/v2v/rgb_to_hsl.hh | 56 -------------------------
milena/mln/literal/one.hh | 14 +++---
milena/mln/literal/zero.hh | 6 +-
milena/mln/make/edge_image.hh | 9 ++--
milena/mln/make/rag_and_labeled_wsl.hh | 2 -
milena/mln/pw/internal/image_base.hh | 1 +
milena/mln/util/vertex.hh | 2 +
milena/tests/util/set.cc | 1 +
11 files changed, 108 insertions(+), 89 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index a5e7011..d68a7e9 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,28 @@
+2009-05-06 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Small fixes.
+
+ * doc/tutorial/tutorial.tex: fix compilation.
+
+ * mln/core/internal/neighb_niter_impl.hh: fix ambiguities and add more
+ doc.
+
+ * mln/fun/v2v/rgb_to_hsl.hh: remove duplicate declarations.
+
+ * mln/literal/one.hh,
+ * mln/literal/zero.hh: add 'const' qualification to conversion
+ operator.
+
+ * mln/make/edge_image.hh: update prototype.
+
+ * mln/make/rag_and_labeled_wsl.hh: remove useless local variable.
+
+ * mln/pw/internal/image_base.hh: add missing include.
+
+ * mln/util/vertex.hh: add missing include and forward declaration.
+
+ * tests/util/set.cc: update header.
+
2009-05-06 Frederic Bour <bour(a)lrde.epita.fr>
Correct typo errors, rename storage_ to state, update thrubin morpher.
diff --git a/milena/doc/tutorial/tutorial.tex b/milena/doc/tutorial/tutorial.tex
index b07b170..509a002 100644
--- a/milena/doc/tutorial/tutorial.tex
+++ b/milena/doc/tutorial/tutorial.tex
@@ -1118,7 +1118,7 @@ A list of available site sets is available in section \ref{siteset}.
%--------------------------
-\doxysubsection{Creating a site set}
+\doxysubsection{tuto4createsiteset}{Creating a site set}
In this section, we will detail how to create common site sets.
@@ -1126,7 +1126,7 @@ This is actually simple.
%--------------------------
-\doxysubsection{Getting access to sites}
+\doxysubsection{tuto4accesstosites}{Getting access to sites}
@@ -1137,15 +1137,15 @@ In milena, an image is seen as a composition of both a site set and a function
mapping a site to a value.
%--------------------------
-\doxysubsection{Creating an image}
+\doxysubsection{tuto4createimate}{Creating an image}
In this section, we will detail how to create common images.
%--------------------------
-\doxysubsection{Reading an image from a file}
+\doxysubsection{tuto4readimage}{Reading an image from a file}
%--------------------------
-\doxysubsection{Accessing data}
+\doxysubsection{tuto4accessdata}{Accessing data}
@@ -1224,7 +1224,8 @@ Finally, you may want to save the image. Since we use bool as image value, the
PBM format is the best choice. Therefore, we use io::pbm::save.
\doxycode[4]{tuto2_first_image}
-The output image looks like the following:
+The output image looks like the following: \\
+
\doxyfigure{tuto2_first_image}{3cm}
In this first step we used a boolean image. Many other value types are available
@@ -1262,25 +1263,29 @@ Updating a site value is also possible using \code{operator()} or the
\doxycode[3]{tuto3_rw_image}
\doxycode[4]{tuto3_rw_image}
-The corresponding image:
+The corresponding image: \\
+
\doxyfigure[1]{tuto3_rw_image}{3cm}
An image can also be initialized/modified thanks to another image.
Let's load a new image.
\doxycode[5]{tuto3_rw_image}
-\var{lena} looks like:
+\var{lena} looks like: \\
+
\doxyimg{small-enlarged}{3cm}
If we want to initialize \var{ima} with \var{lena}, we can use \code{data::fill}:
\doxycode[6]{tuto3_rw_image}
-Output:
+Output: \\
+
\doxyfigure[2]{tuto3_rw_image}{3cm}
Note that to fill an image with some data, the image domain \must be smaller
or equal to the data.
Likewise, it is possible to paste data from an image to another:
\doxycode[7]{tuto3_rw_image}
-Output:
+Output: \\
+
\doxyfigure[3]{tuto3_rw_image}{3cm}
More details can be found in sections \doxyref{imaaccessmodval}, \doxyref{fillop} and \doxyref{pasteop} in
diff --git a/milena/mln/core/internal/neighb_niter_impl.hh b/milena/mln/core/internal/neighb_niter_impl.hh
index a21f690..060f574 100644
--- a/milena/mln/core/internal/neighb_niter_impl.hh
+++ b/milena/mln/core/internal/neighb_niter_impl.hh
@@ -44,6 +44,11 @@ namespace mln
template <typename G, typename F> class graph_elt_window;
template <typename G, typename F, typename I> class graph_elt_window_if;
template <typename G, typename F> class line_graph_elt_window;
+ namespace util
+ {
+ template <typename G> class vertex;
+ template <typename G> class edge;
+ }
namespace internal
@@ -56,11 +61,54 @@ namespace mln
};
+ /// Add more implementation for neighborhoods made from
+ /// graph_window_base windows.
+ ///
+ /// FIXME: we need to redeclare the graph element interface.
+ /// Here, a neighb niter iterator encapsulates a window qiter iterator.
+ /// A window qiter iterator is a Proxy on a site P and can convert towards
+ /// a graph element through its member element().
+ ///
+ /// The window qiter iterator cannot have an automatic conversion towards
+ /// a graph element since there would be an ambiguity between this
+ /// conversion and the conversion to a psite P, if P is also a graph
+ /// element.
+ template <typename P, typename E>
+ struct neighb_niter_impl_graph_window
+ {
+ unsigned id() const
+ {
+ return internal::force_exact<E>(*this).compute_p_().id();
+ }
+
+ };
+
+ /// In this case, The site P is a util::vertex which means this iterator
+ /// can automatically converts towards this type.
+ /// There would be an ambiguity between util::vertex members and the one
+ /// declared in neighb_niter_impl_graph_window<P,E> if this
+ /// specialization did not exist.
+ template <typename G, typename E>
+ struct neighb_niter_impl_graph_window< util::vertex<G>, E >
+ {
+ };
+
+ /// In this case, The site P is a util::vertex which means this iterator
+ /// can automatically converts towards this type.
+ /// There would be an ambiguity between util::edge members and the one
+ /// declared in neighb_niter_impl_graph_window<P,E> if this
+ /// specialization did not exist.
+ template <typename G, typename E>
+ struct neighb_niter_impl_graph_window< util::edge<G>, E >
+ {
+ };
+
/// Add more implementation for neighborhoods made from
/// graph_window_base windows.
template <typename P, typename T, typename E>
- struct neighb_niter_impl<graph_window_base<P,T>, E>
+ struct neighb_niter_impl< graph_window_base<P, T>, E >
+ : neighb_niter_impl_graph_window<P,E>
{
typedef typename T::target S;
@@ -69,14 +117,10 @@ namespace mln
return internal::force_exact<E>(*this).compute_p_().element();
}
- unsigned id() const
- {
- return internal::force_exact<E>(*this).compute_p_().id();
- }
-
};
+
/// Add more implementation for neighborhoods made from a
/// graph_window_piter.
template <typename G, typename S, typename E>
diff --git a/milena/mln/fun/v2v/rgb_to_hsl.hh b/milena/mln/fun/v2v/rgb_to_hsl.hh
index a27e80c..7645750 100644
--- a/milena/mln/fun/v2v/rgb_to_hsl.hh
+++ b/milena/mln/fun/v2v/rgb_to_hsl.hh
@@ -69,31 +69,11 @@ namespace mln
extern f_rgb_to_hsl_f_t f_rgb_to_hsl_f;
- template <typename T_rgb>
- struct f_hsl_to_rgb_ : public Function_v2v< f_hsl_to_rgb_<T_rgb> >
- {
- typedef T_rgb result;
-
- template <typename T_hsl>
- T_rgb operator()(const T_hsl& hsl) const;
-
- };
-
- typedef f_hsl_to_rgb_< value::rgb<8> > f_hsl_to_rgb_3x8_t;
- typedef f_hsl_to_rgb_< value::rgb<16> > f_hsl_to_rgb_3x16_t;
-
- extern f_hsl_to_rgb_3x8_t f_hsl_to_rgb_3x8;
- extern f_hsl_to_rgb_3x16_t f_hsl_to_rgb_3x16;
-
-
# ifndef MLN_INCLUDE_ONLY
/// Global variables.
/// \{
f_rgb_to_hsl_f_t f_rgb_to_hsl_f;
-
- f_hsl_to_rgb_3x8_t f_hsl_to_rgb_3x8;
- f_hsl_to_rgb_3x16_t f_hsl_to_rgb_3x16;
/// \}
@@ -144,42 +124,6 @@ namespace mln
}
- template <typename T_rgb>
- template <typename T_hsl>
- inline
- T_rgb
- f_hsl_to_rgb_<T_rgb>::operator()(const T_hsl& hsl) const
- {
- typedef typename T_rgb::red_t red_t;
- typedef typename T_rgb::green_t green_t;
- typedef typename T_rgb::blue_t blue_t;
-
- static math::round<red_t> to_r;
- static math::round<green_t> to_g;
- static math::round<blue_t> to_b;
-
- static const float
- sqrt3_3 = std::sqrt(3) / 3,
- inv_sqrt6 = 1 / std::sqrt(6),
- inv_sqrt2 = 1 / std::sqrt(2);
-
- float
- h = hsl.hue() / 180.0 * 3.1415,
- alpha = hsl.sat() * std::cos(h),
- beta = hsl.sat() * std::sin(h);
-
-
- red_t r = to_r(sqrt3_3 * hsl.lum() + 2 * inv_sqrt6 * beta);
- green_t g =
- to_g(sqrt3_3 * hsl.lum() + inv_sqrt2 * alpha - inv_sqrt6 * beta);
- blue_t b =
- to_b(sqrt3_3 * hsl.lum() - inv_sqrt2 * alpha - inv_sqrt6 * beta);
-
- T_rgb rgb(r, g, b);
-
- return rgb;
- }
-
# endif // !MLN_INCLUDE_ONLY
} // end of namespace fun::v2v
diff --git a/milena/mln/literal/one.hh b/milena/mln/literal/one.hh
index 8176ce2..68fde6d 100644
--- a/milena/mln/literal/one.hh
+++ b/milena/mln/literal/one.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -28,10 +29,9 @@
#ifndef MLN_LITERAL_ONE_HH
# define MLN_LITERAL_ONE_HH
-/*! \file mln/literal/one.hh
- *
- * \brief Definition of the literal of mln::one.
- */
+/// \file mln/literal/one.hh
+///
+/// Definition of the literal of mln::one.
# include <mln/core/concept/literal.hh>
# include <mln/metal/converts_to.hh>
@@ -49,7 +49,7 @@ namespace mln
// FIXME: Cf. comments in literal/zero.hh.
template <typename T>
- operator T () const;
+ operator const T () const;
};
@@ -61,7 +61,7 @@ namespace mln
template <typename T>
inline
- one_t::operator T () const
+ one_t::operator const T () const
{
mlc_converts_to(int, T)::check();
return 1;
diff --git a/milena/mln/literal/zero.hh b/milena/mln/literal/zero.hh
index b6b4e48..62acfbf 100644
--- a/milena/mln/literal/zero.hh
+++ b/milena/mln/literal/zero.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of the Olena Library. This library is free
@@ -51,7 +51,7 @@ namespace mln
// FIXME: (for the record) Add "friend class Literal<zero_t>;" and a protected ctor.
template <typename T>
- operator T () const;
+ operator const T () const;
};
/// Literal zero.
@@ -61,7 +61,7 @@ namespace mln
template <typename T>
inline
- zero_t::operator T () const
+ zero_t::operator const T () const
{
mlc_converts_to(int, T)::check();
return 0;
diff --git a/milena/mln/make/edge_image.hh b/milena/mln/make/edge_image.hh
index d4510c1..bd03162 100644
--- a/milena/mln/make/edge_image.hh
+++ b/milena/mln/make/edge_image.hh
@@ -94,16 +94,15 @@ namespace mln
/// Construct an edge image.
///
/// \param[in] v_ima_ A vertex image.
- /// \param[in] pe A p_edges mapping graph element to themselves.
/// \param[in] fv A function mapping two vertex ids to a value.
/// The result is associated to the corresponding edge.
///
- /// \return an edge image.
+ /// \return an edge image without localization information mapped to
+ /// graph elements.
//
template <typename P, typename V, typename G, typename FV>
mln::edge_image<void,mln_result(FV),G>
edge_image(const vertex_image<P,V,G>& v_ima_,
- const p_edges<G,util::internal::id2element<G,util::edge<G> > > pe,
const Function_vv2v<FV>& fv_);
@@ -174,7 +173,6 @@ namespace mln
template <typename P, typename V, typename G, typename FV>
mln::edge_image<void,mln_result(FV),G>
edge_image(const vertex_image<P,V,G>& v_ima_,
- const p_edges<G,util::internal::id2element<G,util::edge<G> > > pe,
const Function_vv2v<FV>& fv_)
{
trace::entering("make::edge_image");
@@ -183,12 +181,13 @@ namespace mln
const vertex_image<P,V,G>& v_ima = exact(v_ima_);
mln_precondition(v_ima.is_valid());
+ p_edges<G> pe(v_ima.graph());
typedef mln::edge_image<void,mln_result(FV),G> edge_ima_t;
edge_ima_t ima_e(pe);
mln_piter(edge_ima_t) e(ima_e.domain());
for_all(e)
- ima_e(e) = fv(e.element().v1(), e.element().v2());
+ ima_e(e) = fv(v_ima(e.element().v1()), v_ima(e.element().v2()));
trace::exiting("make::edge_image");
return ima_e;
diff --git a/milena/mln/make/rag_and_labeled_wsl.hh b/milena/mln/make/rag_and_labeled_wsl.hh
index 774c78a..60f2824 100644
--- a/milena/mln/make/rag_and_labeled_wsl.hh
+++ b/milena/mln/make/rag_and_labeled_wsl.hh
@@ -140,8 +140,6 @@ namespace mln
const N& nbh = exact(nbh_);
typedef mln_value(I) L;
- mln::image2d<bool> adj(mln::box2d(nbasins.next(), nbasins.next()));
- data::fill(adj, false);
extension::adjust_fill(wshd, nbh, 0u);
mln_concrete(I) output(wshd.domain());
diff --git a/milena/mln/pw/internal/image_base.hh b/milena/mln/pw/internal/image_base.hh
index b6571b9..d1dd608 100644
--- a/milena/mln/pw/internal/image_base.hh
+++ b/milena/mln/pw/internal/image_base.hh
@@ -33,6 +33,7 @@
/// Definition of the common base class for all point-wise images.
# include <mln/core/internal/image_primary.hh>
+# include <mln/core/routine/init.hh>
# include <mln/metal/unqualif.hh>
# include <mln/metal/not_equal.hh>
# include <mln/value/set.hh>
diff --git a/milena/mln/util/vertex.hh b/milena/mln/util/vertex.hh
index 0cde7a1..4f0c5ad 100644
--- a/milena/mln/util/vertex.hh
+++ b/milena/mln/util/vertex.hh
@@ -35,6 +35,7 @@
# include <mln/core/concept/proxy.hh>
# include <mln/core/concept/site.hh>
# include <mln/util/graph_ids.hh>
+# include <mln/util/edge.hh>
/// \file mln/util/vertex.hh
///
@@ -47,6 +48,7 @@ namespace mln
// Forward declaration.
namespace util { template<typename G> class vertex; }
+ namespace util { template<typename G> class edge; }
/// Vertex category flag type.
template <typename E>
diff --git a/milena/tests/util/set.cc b/milena/tests/util/set.cc
index f97449f..988a397 100644
--- a/milena/tests/util/set.cc
+++ b/milena/tests/util/set.cc
@@ -1,4 +1,5 @@
// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
--
1.6.1.2
1
1
* scribo/deskew/all.hh: rename as...
* scribo/preprocessing/all.hh: ... this.
* scribo/preprocessing/unskew.hh: new routine.
---
milena/sandbox/ChangeLog | 9 ++
.../scribo/{deskew => preprocessing}/all.hh | 18 ++--
milena/sandbox/scribo/preprocessing/unskew.hh | 111 ++++++++++++++++++++
3 files changed, 129 insertions(+), 9 deletions(-)
rename milena/sandbox/scribo/{deskew => preprocessing}/all.hh (79%)
create mode 100644 milena/sandbox/scribo/preprocessing/unskew.hh
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 058d82f..8421040 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,5 +1,14 @@
2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add the unskew routine.
+
+ * scribo/deskew/all.hh: rename as...
+ * scribo/preprocessing/all.hh: ... this.
+
+ * scribo/preprocessing/unskew.hh: new routine.
+
+2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add routines for primitive extraction.
* scribo/extract/primitive/canvas.hh,
diff --git a/milena/sandbox/scribo/deskew/all.hh b/milena/sandbox/scribo/preprocessing/all.hh
similarity index 79%
rename from milena/sandbox/scribo/deskew/all.hh
rename to milena/sandbox/scribo/preprocessing/all.hh
index 8e15e9c..145d6f4 100644
--- a/milena/sandbox/scribo/deskew/all.hh
+++ b/milena/sandbox/scribo/preprocessing/all.hh
@@ -25,24 +25,24 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef SCRIBO_DESKEW_ALL_HH
-# define SCRIBO_DESKEW_ALL_HH
+#ifndef SCRIBO_PREPROCESSING_ALL_HH
+# define SCRIBO_PREPROCESSING_ALL_HH
-/// \file scribo/deskew/all.hh
+/// \file scribo/preprocessing/all.hh
///
-/// Include all headers located in scribo/deskew.
+/// Include all headers located in scribo/preprocessing.
namespace scribo
{
- /// Namespace of deskew routines.
- namespace deskew
+ /// Namespace of preprocessing routines.
+ namespace preprocessing
{
- } // end of namespace scribo::deskew
+ } // end of namespace scribo::preprocessing
} // end of namespace scribo
-# include <scribo/deskew/hough.hh>
+# include <scribo/preprocessing/hough.hh>
-#endif // ! SCRIBO_DESKEW_ALL_HH
+#endif // ! SCRIBO_PREPROCESSING_ALL_HH
diff --git a/milena/sandbox/scribo/preprocessing/unskew.hh b/milena/sandbox/scribo/preprocessing/unskew.hh
new file mode 100644
index 0000000..bb71505
--- /dev/null
+++ b/milena/sandbox/scribo/preprocessing/unskew.hh
@@ -0,0 +1,111 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_UNSKEW_HOUGH_HH
+# define SCRIBO_UNSKEW_HOUGH_HH
+
+/// \file scribo/preprocessing/unskew.hh
+///
+/// Unskew an image.
+
+# include <mln/core/image/image2d.hh>
+
+# include <mln/accu/compute.hh>
+# include <mln/accu/max_site.hh>
+
+# include <mln/transform/hough.hh>
+# include <mln/transformation/rotate.hh>
+
+namespace scribo
+{
+
+ namespace preprocessing
+ {
+
+ using namespace mln;
+
+ /// Unskew a document.
+ /// Based on the Hough transform.
+ ///
+ /// \param[in] input_ A binary image. Objects to be unskewed must be set
+ /// to "true".
+ ///
+ /// \return A binary image.
+ //
+ template <typename I>
+ mln_concrete(I)
+ unskew(const Image<I>& input_);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ mln_concrete(I)
+ unskew(const Image<I>& input_)
+ {
+ trace::entering("scribo::preprocessing::unskew");
+
+ const I& input = exact(input_);
+ mlc_equal(mln_value(I), bool)::check();
+ mln_precondition(input.is_valid());
+
+ image2d<float> hough_ima = transform::hough(input);
+
+ point2d max_p = accu::compute(accu::max_site<image2d<float> >(), hough_ima);
+
+ std::cout << max_p.col() << std::endl;
+ double angle = 0;
+ int max_angle = max_p.col();
+
+ if (max_angle > 180)
+ max_angle = - max_angle % 180;
+
+ if (max_angle < 90 && max_angle > 0)
+ angle = - max_angle;
+ else if (max_angle < 0 && max_angle > -90)
+ angle = max_angle;
+ else if (max_angle < 180 && max_angle > 90)
+ angle = 180 - max_angle;
+ else if (max_angle < -90 && max_angle > -180)
+ angle = 180 + max_angle;
+
+ mln_concrete(I) output = transformation::rotate(input, angle);
+
+ trace::exiting("scribo::preprocessing::unskew");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::preprocessing
+
+} // end of namespace mln
+
+# endif // SCRIBO_UNSKEW_HOUGH_HH
--
1.5.6.5
1
0
* scribo/extract/primitive/canvas.hh,
* scribo/extract/primitive/cells.hh,
* scribo/extract/primitive/lines_discontinued.hh,
* scribo/extract/primitive/lines_h_discontinued.hh,
* scribo/extract/primitive/lines_thick.hh,
* scribo/extract/primitive/lines_v_discontinued.hh,
* scribo/extract/primitive/objects.hh: new routines.
---
milena/sandbox/ChangeLog | 12 ++
milena/sandbox/scribo/extract/primitive/canvas.hh | 132 ++++++++++++++
milena/sandbox/scribo/extract/primitive/cells.hh | 121 ++++++++++++
.../scribo/extract/primitive/lines_discontinued.hh | 192 ++++++++++++++++++++
.../extract/primitive/lines_h_discontinued.hh | 160 ++++++++++++++++
.../scribo/extract/primitive/lines_thick.hh | 178 ++++++++++++++++++
.../extract/primitive/lines_v_discontinued.hh | 161 ++++++++++++++++
milena/sandbox/scribo/extract/primitive/objects.hh | 158 ++++++++++++++++
8 files changed, 1114 insertions(+), 0 deletions(-)
create mode 100644 milena/sandbox/scribo/extract/primitive/canvas.hh
create mode 100644 milena/sandbox/scribo/extract/primitive/cells.hh
create mode 100644 milena/sandbox/scribo/extract/primitive/lines_discontinued.hh
create mode 100644 milena/sandbox/scribo/extract/primitive/lines_h_discontinued.hh
create mode 100644 milena/sandbox/scribo/extract/primitive/lines_thick.hh
create mode 100644 milena/sandbox/scribo/extract/primitive/lines_v_discontinued.hh
create mode 100644 milena/sandbox/scribo/extract/primitive/objects.hh
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 17196d9..058d82f 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,3 +1,15 @@
+2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Add routines for primitive extraction.
+
+ * scribo/extract/primitive/canvas.hh,
+ * scribo/extract/primitive/cells.hh,
+ * scribo/extract/primitive/lines_discontinued.hh,
+ * scribo/extract/primitive/lines_h_discontinued.hh,
+ * scribo/extract/primitive/lines_thick.hh,
+ * scribo/extract/primitive/lines_v_discontinued.hh,
+ * scribo/extract/primitive/objects.hh: new routines.
+
2009-05-15 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Move inim project to sandbox/inim.
diff --git a/milena/sandbox/scribo/extract/primitive/canvas.hh b/milena/sandbox/scribo/extract/primitive/canvas.hh
new file mode 100644
index 0000000..07387d9
--- /dev/null
+++ b/milena/sandbox/scribo/extract/primitive/canvas.hh
@@ -0,0 +1,132 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_EXTRACT_PRIMITIVE_CANVAS_HH
+# define SCRIBO_EXTRACT_PRIMITIVE_CANVAS_HH
+
+/// \file scribo/primitive/canvas.hh
+///
+/// Rebuild a table from its line bounding boxes.
+
+# include <mln/core/concept/image.hh>
+# include <mln/labeling/background.hh>
+# include <mln/util/array.hh>
+# include <mln/util/couple.hh>
+# include <mln/value/label_8.hh>
+
+# include <scribo/table/align_lines_verticaly.hh>
+# include <scribo/table/align_lines_horizontaly.hh>
+# include <scribo/table/connect_vertical_lines.hh>
+# include <scribo/table/connect_horizontal_lines.hh>
+# include <scribo/table/repair_horizontal_lines.hh>
+# include <scribo/table/repair_vertical_lines.hh>
+
+# include <scribo/debug/save_table_image.hh>
+
+
+
+namespace scribo
+{
+
+ namespace extract
+ {
+
+ namespace primitive
+ {
+
+
+ /// Rebuild a table from its line bounding boxes.
+ /*!
+ ** \param[in] input_ A binary image.
+ ** \param[in] hlines_ Vorizontal line bounding boxes.
+ ** \param[in] vlines_ vertical line bounding boxes.
+ ** \param[in] max_dist_lines The maximum distance allowed between
+ ** vertical and horizontal lines to connect
+ ** them eachother.
+ **
+ ** \return The canvas as a binary image. canvas lines are set to true.
+ */
+ template <typename I, typename V>
+ mln_ch_value(I,bool)
+ canvas(const Image<I>& input_,
+ const util::array<box<mln_site(I)> >& hlines_,
+ const util::array<box<mln_site(I)> >& vlines_,
+ unsigned max_dist_lines);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I, typename V>
+ mln_ch_value(I,bool)
+ canvas(const Image<I>& input_,
+ const util::array<box<mln_site(I)> >& hlines,
+ const util::array<box<mln_site(I)> >& vlines,
+ unsigned max_dist_lines);
+ {
+ trace::entering("scribo::primitive::canvas");
+ const I& input = exact(input_);
+
+ mlc_equal(mln_value(I), bool)::check();
+ mln_precondition(input.is_valid());
+
+ typedef util::array<box<mln_site(I)> > lines_t;
+ util::couple<lines_t, lines_t> lines = make::couple(hlines, vlines);
+
+ util::array<int> rows = align_lines_horizontaly(input, hlines, 5);
+ util::array<int> cols = align_lines_verticaly(input, vlines, 5);
+
+ repair_vertical_lines(input, lines, 30);
+ repair_horizontal_lines(input, lines, 30);
+
+ // Connect vertical lines with horizontal lines.
+ connect_vertical_lines(rows, lines, input, max_dist_lines);
+ connect_horizontal_lines(cols, lines, input, max_dist_lines);
+
+ mln_ch_value(I,bool) res;
+ initialize(res, input);
+ data::fill(res, false);
+ for_all_elements(i, lines.first())
+ mln::draw::box(res, lines.first()[i], true);
+ for_all_elements(i, lines.second())
+ mln::draw::box(res, lines.second()[i], true);
+
+ trace::exiting("scribo::primitive::canvas");
+ return res;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::extract::primitive
+
+ } // end of namespace scribo::extract
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_EXTRACT_PRIMITIVE_CANVAS_HH
diff --git a/milena/sandbox/scribo/extract/primitive/cells.hh b/milena/sandbox/scribo/extract/primitive/cells.hh
new file mode 100644
index 0000000..91d9c59
--- /dev/null
+++ b/milena/sandbox/scribo/extract/primitive/cells.hh
@@ -0,0 +1,121 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_EXTRACT_PRIMITIVE_CELLS_HH
+# define SCRIBO_EXTRACT_PRIMITIVE_CELLS_HH
+
+/// \file scribo/primitive/cells.hh
+///
+/// Extract canvas cells from a binary image.
+
+# include <mln/core/concept/image.hh>
+
+# include <mln/accu/bbox.hh>
+
+# include <mln/util/couple.hh>
+# include <mln/util/array.hh>
+
+# include <mln/labeling/compute.hh>
+
+# include <scribo/table/rebuild.hh>
+# include <scribo/table/erase.hh>
+
+# include <scribo/primitive/discontinued_lines.hh>
+
+# include <scribo/make/debug_filename.hh>
+
+
+namespace scribo
+{
+
+ namespace extract
+ {
+
+ namespace primitive
+ {
+
+ /// Extract canvas cells from a binary image.
+ /// Use arbitrary criterions.
+ /*
+ ** \param[in] input_ A binary image.
+ ** \param[in,out] ncells Will store the number of cells found.
+ **
+ ** \return A list of cell bounding boxes.
+ */
+ template <typename I, typename V>
+ util::couple<util::array<box<mln_site(I)> >
+ cells(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, const V& label_type);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename N, typename V>
+ inline
+ util::couple<util::array<box<mln_site(I)> >
+ cells(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, const V& label_type)
+ {
+ trace::entering("scribo::primitive::cells");
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ mln_precondition(input.is_valid());
+ mln_precondition(nbh.is_valid());
+ mlc_equal(mln_value(I), bool)::check();
+
+ typedef util::array< box<mln_site(I)> > boxarray_t;
+
+ V ncells;
+ win::line<mln_grid(I::site), 0, mln_coord(I::site)> vline(51);
+ win::line<mln_grid(I::site), 1, mln_coord(I::site)> hline(51);
+ boxarray_t
+ vlines = primitive::discontinued_lines(input, nbh, ncells, vline, 6),
+ hlines = primitive::discontinued_lines(input, nbh, ncells, hline, 6);
+
+ typedef mln_ch_value(I,V) cells_ima_t;
+
+ cells_ima_t
+ cells = scribo::table::rebuild(input, make::couple(vlines,hlines),
+ 30, ncells).first();
+ util::array<box<mln_site(I)> >
+ cellbboxes = labeling::compute(accu::meta::bbox(), cells, ncells);
+
+ trace::exiting("scribo::primitive::cells");
+ return cellbboxes;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::extract::primitive
+
+ } // end of namespace scribo::extract
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_EXTRACT_PRIMITIVE_CELLS_HH
diff --git a/milena/sandbox/scribo/extract/primitive/lines_discontinued.hh b/milena/sandbox/scribo/extract/primitive/lines_discontinued.hh
new file mode 100644
index 0000000..5730fcc
--- /dev/null
+++ b/milena/sandbox/scribo/extract/primitive/lines_discontinued.hh
@@ -0,0 +1,192 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+
+#ifndef SCRIBO_EXTRACT_PRIMITIVE_LINES_DISCONTINUED_HH
+# define SCRIBO_EXTRACT_PRIMITIVE_LINES_DISCONTINUED_HH
+
+/// \file scribo/primitive/lines/discontinued.hh
+///
+/// Extract discontinued lines in a binary image.
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/window.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/site_set/box.hh>
+
+# include <mln/labeling/blobs.hh>
+
+# include <mln/morpho/rank_filter.hh>
+
+# include <mln/accu/bbox.hh>
+
+# include <mln/util/array.hh>
+# include <mln/util/couple.hh>
+
+# include <scribo/core/macros.hh>
+# include <scribo/core/component_bboxes.hh>
+
+namespace scribo
+{
+
+ namespace extract
+ {
+
+ namespace primitive
+ {
+
+ using namespace mln;
+
+
+ /// Extract discontinued lines in a binary image.
+ /*!
+ * Based on a rank filter.
+ *
+ * \param[in] input_ A binary image.
+ * \param[in] nbh_ The neighborhood used for labeling image
+ * components.
+ * \param[in,out] nlines The label type used for labeling.
+ * \param[in] win_ A Window used to extract lines.
+ * \param[in] rank_k Rank used for filtering.
+ * \param[in,out] line_bboxes line bounding boxes.
+ *
+ * \return An image in which lines are labeled.
+ */
+ template <typename I, typename N, typename V, typename W>
+ mln_ch_value(I,V)
+ discontinued(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_, unsigned rank_k,
+ util::array<box<mln_site(I)> >& line_bboxes);
+
+
+ /// \overload
+ template <typename I, typename N, typename V, typename W>
+ mln_ch_value(I,V)
+ discontinued(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_, unsigned rank_k);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ template <typename I, typename N, typename V, typename W>
+ void
+ discontinued_tests(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_, unsigned rank_k)
+ {
+ mlc_equal(mln_value(I),bool)::check();
+ mlc_equal(mln_site(I)::dim, 2)::check();
+ mlc_is_a(V, mln::value::Symbolic)::check();
+
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(exact(nbh).is_valid());
+ mln_precondition(exact(win).is_valid());
+
+ (void) nlines;
+ (void) rank_k;
+ }
+
+ } // end of namespace scribo::primitive::internal
+
+
+
+ template <typename I, typename N, typename V, typename W>
+ inline
+ mln_ch_value(I,V)
+ discontinued(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_, unsigned rank_k)
+ {
+ trace::entering("scribo::primitive::discontinued");
+
+ internal::discontinued_tests(input_, nbh_, nlines, win_, rank_k);
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ const W& win = exact(win_);
+
+ mln_ch_value(I,bool) filter = morpho::rank_filter(input, win, vrank_k);
+ mln_ch_value(I,V) output = labeling::blobs(filter, nbh, nlines);
+
+ trace::exiting("scribo::primitive::discontinued");
+ return output;
+ }
+
+
+
+
+ template <typename I, typename N, typename V, typename W>
+ inline
+ mln_ch_value(I,V)
+ discontinued(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_, unsigned rank_k,
+ util::array<box<mln_site(I)> >& line_bboxes)
+ {
+ trace::entering("scribo::primitive::discontinued");
+
+ internal::discontinued_tests(input_, nbh_, nlines, win_, rank_k);
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ const W& win = exact(win_);
+
+ mln_ch_value(I,V)
+ output = discontinued(input, nbh, nlines, win, rank_k);
+
+ line_bboxes = labeling::compute(accu::meta::bbox(), output, nlines);
+ mln_postcondition(line_bboxes.nelements() == nlines.next());
+ // for_all_components(i, line_bboxes)
+ // {
+ // line_bboxes[i].enlarge(0, win.length() / 2);
+ // line_bboxes[i].crop_wrt(input.domain());
+ // }
+
+ trace::exiting("scribo::primitive::discontinued");
+ return output;
+ }
+
+# endif // !MLN_INCLUDE_ONLY
+
+
+ } // end of namespace scribo::extract::primitive
+
+ } // end of namespace scribo::extract
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_EXTRACT_PRIMITIVE_LINES_DISCONTINUED_HH
diff --git a/milena/sandbox/scribo/extract/primitive/lines_h_discontinued.hh b/milena/sandbox/scribo/extract/primitive/lines_h_discontinued.hh
new file mode 100644
index 0000000..7f31bff
--- /dev/null
+++ b/milena/sandbox/scribo/extract/primitive/lines_h_discontinued.hh
@@ -0,0 +1,160 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_EXTRACT_PRIMITIVE_LINES_H_DISCONTINUED_HH
+# define SCRIBO_EXTRACT_PRIMITIVE_LINES_H_DISCONTINUED_HH
+
+/// \file scribo/primitive/lines_h_discontinued.hh
+///
+/// Extract horizontal discontinued lines.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/win/hline2d.hh>
+
+namespace scribo
+{
+
+ namespace extract
+ {
+
+ namespace primitive
+ {
+
+
+ /// Extract horizontal discontinued lines.
+ /*!
+ * \param[in] input A binary image.
+ * \param[in] nbh A neighborhood used to label lines.
+ * \param[in,out] nlines The number of lines found.
+ * \param[in] line_length The minimum line length expected. (must be
+ * odd).
+ * \param[in] rank_k Rank filter parameter.
+ *
+ * \result An image in which lines are labeled with a value different
+ * from 0.
+ */
+ template <typename I, typename N, typename V>
+ mln_ch_value(I,V)
+ lines_h_discontinued(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned line_length, unsigned rank_k);
+
+
+ /// \overload
+ template <typename I, typename N, typename V>
+ mln_ch_value(I,V)
+ lines_h_discontinued(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned line_length, unsigned rank_k,
+ util::array<box<mln_site(I)> >& line_bboxes);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ template <typename I, typename N, typename V, typename W>
+ void
+ lines_h_discontinued_tests(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ unsigned line_length, unsigned rank_k)
+ {
+ mlc_equal(mln_value(I),bool)::check();
+ mlc_equal(mln_site(I)::dim, 2)::check();
+ mlc_is_a(V, mln::value::Symbolic)::check();
+
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(exact(nbh).is_valid());
+ mln_precondition(exact(win).is_valid());
+ mln_precondition(!(line_length % 2));
+
+ (void) nlines;
+ (void) rank_k;
+ }
+
+ } // end of namespace scribo::primitive::internal
+
+
+
+ template <typename I, typename N, typename V>
+ mln_ch_value(I,V)
+ lines_h_discontinued(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned line_length, unsigned rank_k)
+ {
+ trace::entering("scribo::primitive::lines_h_discontinued");
+
+ internal::line_h_discontinued_tests(input, nbh, nlines,
+ line_length, rank_k);
+
+ win::hline2d win(line_length);
+
+ mln_ch_value(I,V)
+ output = lines_discontinued(input, nh, nlines, win, rank_k);
+
+ trace::exiting("scribo::primitive::lines_h_discontinued");
+ return output;
+ }
+
+
+
+ template <typename I, typename N, typename V>
+ mln_ch_value(I,V)
+ lines_h_discontinued(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned line_length, unsigned rank_k,
+ util::array<box<mln_site(I)> >& line_bboxes)
+ {
+ trace::entering("scribo::primitive::lines_h_discontinued");
+
+ internal::line_h_discontinued_tests(input, nbh, nlines,
+ line_length, rank_k);
+
+ win::hline2d win(line_length);
+ mln_ch_value(I,V)
+ output = internal::line_h_discontinued_tests(input, nbh, nlines,
+ line_length, rank_k,
+ line_bboxes);
+
+ trace::exiting("scribo::primitive::lines_h_discontinued");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::extract::primitive
+
+ } // end of namespace scribo::extract
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_EXTRACT_PRIMITIVE_LINES_H_DISCONTINUED_HH
diff --git a/milena/sandbox/scribo/extract/primitive/lines_thick.hh b/milena/sandbox/scribo/extract/primitive/lines_thick.hh
new file mode 100644
index 0000000..ea5e8d1
--- /dev/null
+++ b/milena/sandbox/scribo/extract/primitive/lines_thick.hh
@@ -0,0 +1,178 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+
+#ifndef SCRIBO_EXTRACT_PRIMITIVE_LINES_THICK_HH
+# define SCRIBO_EXTRACT_PRIMITIVE_LINES_THICK_HH
+
+/// \file scribo/primitive/lines_thick.hh
+///
+/// Extract thick lines in a binary image.
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/window.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/site_set/box.hh>
+
+# include <mln/morpho/erosion.hh>
+
+# include <mln/accu/bbox.hh>
+
+# include <mln/util/array.hh>
+# include <mln/util/couple.hh>
+
+# include <scribo/core/macros.hh>
+# include <scribo/core/component_bboxes.hh>
+
+namespace scribo
+{
+
+ namespace extract
+ {
+
+ namespace primitive
+ {
+
+
+ using namespace mln;
+
+ /// Extract thick lines in a binary image.
+ /*!
+ * Only non discontinued lines are correctly extracted with this routine.
+ *
+ * \param[in] input_ A binary image.
+ * \param[in] nbh_ The neighborhood used for labeling image
+ * components.
+ * \param[in,out] nlines Type used for labeling.
+ * \param[in] win_ Window used to extract the lines
+ * \param[in,out] line_bboxes Line bounding boxes.
+ *
+ * \return An image in which lines are labeled.
+ */
+ template <typename I, typename N, typename V, typename W>
+ mln_ch_value(I,V)
+ lines_thick(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_,
+ util::array<box<mln_site(I)>& line_bboxes);
+
+ /// \overload
+ template <typename I, typename N, typename V, typename W>
+ mln_ch_value(I,V)
+ lines_thick(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ template <typename I, typename N, typename V, typename W>
+ void
+ lines_thick_tests(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_)
+ {
+ mlc_equal(mln_value(I),bool)::check();
+ mlc_equal(mln_site(I)::dim, 2)::check();
+ mlc_is_a(V, mln::value::Symbolic)::check();
+
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(exact(nbh).is_valid());
+ mln_precondition(exact(win).is_valid());
+
+ (void) nlines;
+ }
+
+ } // end of namespace scribo::primitive::internal
+
+
+
+ template <typename I, typename N, typename V, typename W>
+ inline
+ mln_ch_value(I,V)
+ lines_thick(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_)
+ {
+ trace::entering("scribo::primitive::lines_thick");
+
+ internal::lines_thick_tests(input_, nbh_, nlines, win_);
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ const W& win = exact(win_);
+
+ mln_ch_value(I,bool) filter = morpho::opening::structural(input, win);
+ mln_ch_value(I,V) output = labeling::blobs(filter, nbh, nlines);
+
+ trace::exiting("scribo::primitive::lines_thick");
+ return output;
+ }
+
+
+
+ template <typename I, typename N, typename V, typename W>
+ inline
+ mln_ch_value(I,V)
+ lines_thick(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_,
+ util::array<box<mln_site(I)>& line_bboxes)
+ {
+ trace::entering("scribo::primitive::lines_thick");
+
+ internal::lines_thick_tests(input_, nbh_, nlines, win_);
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ const W& win = exact(win_);
+
+ mln_ch_value(I,V) output = lines_thick(input, nbh, nlines, win);
+
+ line_bboxes = labeling::compute(accu::meta::bbox(), output, nlines);
+ mln_postcondition(line_bboxes.nelements() == nlines.next());
+
+ trace::exiting("scribo::primitive::lines_thick");
+ return output;
+ }
+
+# endif // !MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::extract::primitive
+
+ } // end of namespace scribo::extract::primitive
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_EXTRACT_PRIMITIVE_VERTICAL_LINES_THICK_HH
diff --git a/milena/sandbox/scribo/extract/primitive/lines_v_discontinued.hh b/milena/sandbox/scribo/extract/primitive/lines_v_discontinued.hh
new file mode 100644
index 0000000..26edbb4
--- /dev/null
+++ b/milena/sandbox/scribo/extract/primitive/lines_v_discontinued.hh
@@ -0,0 +1,161 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_EXTRACT_PRIMITIVE_LINES_V_DISCONTINUED_HH
+# define SCRIBO_EXTRACT_PRIMITIVE_LINES_V_DISCONTINUED_HH
+
+/// \file scribo/primitive/lines_v_discontinued.hh
+///
+/// Extract vertical discontinued lines.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+
+
+namespace scribo
+{
+
+ namespace extract
+ {
+
+ namespace primitive
+ {
+
+
+ /// Extract vertical discontinued lines.
+ /*!
+ * \param[in] input A binary image.
+ * \param[in] nbh A neighborhood used to label lines.
+ * \param[in,out] nlines The number of lines found.
+ * \param[in] line_length The minimum line length expected. (must be
+ * odd).
+ * \param[in] rank_k Rank filter parameter.
+ * \param[in,out] line_bboxes Will store the line bounding boxes.
+ *
+ * \result An image in which lines are labeled with a value different
+ * from 0.
+ */
+ template <typename I, typename N, typename V>
+ mln_ch_value(I,V)
+ lines_v_discontinued(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned line_length, unsigned rank_k,
+ util::array<box<mln_site(I)> >& line_bboxes);
+
+ /// \overload
+ template <typename I, typename N, typename V>
+ mln_ch_value(I,V)
+ lines_v_discontinued(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned line_length, unsigned rank_k);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ template <typename I, typename N, typename V, typename W>
+ void
+ lines_v_discontinued_tests(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ unsigned line_length, unsigned rank_k)
+ {
+ mlc_equal(mln_value(I),bool)::check();
+ mlc_equal(mln_site(I)::dim, 2)::check();
+ mlc_is_a(V, mln::value::Symbolic)::check();
+
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(exact(nbh).is_valid());
+ mln_precondition(exact(win).is_valid());
+ mln_precondition(!(line_length % 2));
+
+ (void) nlines;
+ (void) rank_k;
+ }
+
+ } // end of namespace scribo::primitive::internal
+
+
+
+ template <typename I, typename N, typename V>
+ mln_ch_value(I,V)
+ lines_v_discontinued(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned line_length, unsigned rank_k)
+ {
+ trace::entering("scribo::primitive::lines_v_discontinued");
+
+ internal::line_v_discontinued_tests(input, nbh, nlines,
+ line_length, rank_k);
+
+ win::hline2d win(line_length);
+
+ mln_ch_value(I,V)
+ output = lines_discontinued(input, nh, nlines, win, rank_k);
+
+ trace::exiting("scribo::primitive::lines_v_discontinued");
+ return output;
+ }
+
+
+
+ template <typename I, typename N, typename V>
+ mln_ch_value(I,V)
+ lines_v_discontinued(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned line_length, unsigned rank_k,
+ util::array<box<mln_site(I)> >& line_bboxes)
+ {
+ trace::entering("scribo::primitive::lines_v_discontinued");
+
+ internal::line_v_discontinued_tests(input, nbh, nlines,
+ line_length, rank_k);
+
+ win::vline2d win(line_length);
+ mln_ch_value(I,V)
+ output = internal::line_v_discontinued_tests(input, nbh, nlines,
+ line_length, rank_k,
+ line_bboxes);
+
+ trace::exiting("scribo::primitive::lines_v_discontinued");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::extract::primitive
+
+ } // end of namespace scribo::extract
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_EXTRACT_PRIMITIVE_LINES_V_DISCONTINUED_HH
diff --git a/milena/sandbox/scribo/extract/primitive/objects.hh b/milena/sandbox/scribo/extract/primitive/objects.hh
new file mode 100644
index 0000000..cc55d72
--- /dev/null
+++ b/milena/sandbox/scribo/extract/primitive/objects.hh
@@ -0,0 +1,158 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+
+#ifndef SCRIBO_EXTRACT_PRIMITIVE_OBJECTS_HH
+# define SCRIBO_EXTRACT_PRIMITIVE_OBJECTS_HH
+
+/// \file scribo/core/objects.hh
+///
+/// Extract objects in a binary image.
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/site_set/box.hh>
+
+# include <mln/labeling/blobs.hh>
+# include <mln/labeling/compute.hh>
+
+# include <mln/util/array.hh>
+
+# include <mln/debug/println.hh>
+
+namespace scribo
+{
+
+ namespace extract
+ {
+
+ namespace primitive
+ {
+
+ using namespace mln;
+
+ /// Extract objects in a binary image.
+ ///
+ /// \param[in] input A binary image. Objects are must be set to 'true'
+ /// and background to 'false'.
+ /// \param[in] nbh A neighborhood to be used for labeling.
+ /// \param[in,out] nobjects Will store the numbers of objects found.
+ /// \param[in,out] bboxes Will store the objects bounding boxes.
+ ///
+ /// \return An image of labeled objects.
+ //
+ template <typename I, typename N, typename V>
+ inline
+ mln_ch_value(I,V)
+ objects(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nobjects,
+ util::array< box<mln_site(I)> >& bboxes);
+
+
+ /// Extract objects in a binary image.
+ /// \overload
+ //
+ template <typename I, typename N, typename V>
+ inline
+ mln_ch_value(I,V)
+ objects(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nobjects);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ template <typename I, typename N, typename V>
+ inline
+ void
+ objects_tests(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nobjects)
+ {
+ mlc_equal(mln_value(I),bool)::check();
+ mlc_is_a(V, mln::value::Symbolic)::check();
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(exact(nbh).is_valid());
+ (void) input;
+ (void) nbh;
+ (void) nobjects;
+ }
+
+
+ } // end of namespace scribo::extract::primitive::internal
+
+
+ template <typename I, typename N, typename V>
+ inline
+ mln_ch_value(I,V)
+ objects(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nobjects,
+ util::array< box<mln_site(I)> >& bboxes)
+ {
+ trace::entering("scribo::objects");
+
+ internal::objects_tests(input, nbh, nobjects);
+
+ mln_ch_value(I,V) object = objects(input, nbh, nobjects);
+
+ bboxes = labeling::compute(accu::meta::bbox(), lbl, nobjects);
+
+ trace::exiting("scribo::objects");
+ return output;
+ }
+
+
+ template <typename I, typename N, typename V>
+ inline
+ mln_ch_value(I,V)
+ objects(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nobjects)
+ {
+ trace::entering("scribo::objects");
+
+ internal::objects_tests(input, nbh, nobjects);
+
+ mln_ch_value(I,V) object = labeling::blobs(input, nbh, nobjects);
+
+ trace::exiting("scribo::objects");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::extract::primitive
+
+ } // end of namespace scribo::extract
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_EXTRACT_PRIMITIVE_OBJECTS_HH
--
1.5.6.5
1
0
* tests/accu/bbox.cc: update doc.
* tests/fun/v2v/Makefile.am,
* tests/fun/v2v/hsl_to_rgb.cc,
* tests/fun/v2v/rgb_to_hsl.cc: new tests.
* tests/io/magick/Makefile.am: add specific ldflags.
* tests/morpho/attribute/card.cc,
* tests/morpho/attribute/height.cc,
* tests/morpho/attribute/volume.cc: avoid warnings.
---
milena/ChangeLog | 16 ++++
milena/tests/accu/bbox.cc | 10 +-
milena/tests/fun/v2v/Makefile.am | 6 +-
.../attribute/volume.cc => fun/v2v/hsl_to_rgb.cc} | 35 ++++++--
milena/tests/fun/v2v/rgb_hsi_conversion.cc | 95 --------------------
.../attribute/volume.cc => fun/v2v/rgb_to_hsl.cc} | 41 ++++++---
milena/tests/morpho/attribute/card.cc | 2 +-
milena/tests/morpho/attribute/height.cc | 8 +-
milena/tests/morpho/attribute/volume.cc | 2 +-
9 files changed, 87 insertions(+), 128 deletions(-)
copy milena/tests/{morpho/attribute/volume.cc => fun/v2v/hsl_to_rgb.cc} (66%)
delete mode 100644 milena/tests/fun/v2v/rgb_hsi_conversion.cc
copy milena/tests/{morpho/attribute/volume.cc => fun/v2v/rgb_to_hsl.cc} (62%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index bf45e27..06ccdcd 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,21 @@
2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Fix tests.
+
+ * tests/accu/bbox.cc: update doc.
+
+ * tests/fun/v2v/Makefile.am,
+ * tests/fun/v2v/hsl_to_rgb.cc,
+ * tests/fun/v2v/rgb_to_hsl.cc: new tests.
+
+ * tests/io/magick/Makefile.am: add specific ldflags.
+
+ * tests/morpho/attribute/card.cc,
+ * tests/morpho/attribute/height.cc,
+ * tests/morpho/attribute/volume.cc: avoid warnings.
+
+2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Fix a bug in util::pix.
* mln/util/pix.hh: Do not store a const reference of a psite, but a
diff --git a/milena/tests/accu/bbox.cc b/milena/tests/accu/bbox.cc
index 8b911f5..b7cb411 100644
--- a/milena/tests/accu/bbox.cc
+++ b/milena/tests/accu/bbox.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,10 +26,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/accu/nil.cc
- *
- * \brief Tests on mln::accu::nil.
- */
+/// \file tests/accu/nil.cc
+///
+/// Tests on mln::accu::nil.
#include <mln/core/alias/point2d.hh>
diff --git a/milena/tests/fun/v2v/Makefile.am b/milena/tests/fun/v2v/Makefile.am
index 9627a2d..a01be1c 100644
--- a/milena/tests/fun/v2v/Makefile.am
+++ b/milena/tests/fun/v2v/Makefile.am
@@ -3,14 +3,16 @@
include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
+ hsl_to_rgb \
norm \
projection \
- rgb_hsi_conversion \
+ rgb_to_hsl \
wrap
norm_SOURCES = norm.cc
projection_SOURCES = projection.cc
-rgb_hsi_conversion_SOURCES = rgb_hsi_conversion.cc
+rgb_to_hsl_SOURCES = rgb_to_hsl.cc
+hsl_to_rgb_SOURCES = hsl_to_rgb.cc
wrap_SOURCES = wrap.cc
TESTS = $(check_PROGRAMS)
diff --git a/milena/tests/morpho/attribute/volume.cc b/milena/tests/fun/v2v/hsl_to_rgb.cc
similarity index 66%
copy from milena/tests/morpho/attribute/volume.cc
copy to milena/tests/fun/v2v/hsl_to_rgb.cc
index 9360fec..0f02e28 100644
--- a/milena/tests/morpho/attribute/volume.cc
+++ b/milena/tests/fun/v2v/hsl_to_rgb.cc
@@ -25,24 +25,41 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/morpho/attribute/volume.cc
+/// \file tests/fun/v2v/hsl_to_rgb.cc
///
-/// Test on mln::morpho::attribute::volume.
+/// Test HSL-to-RGB conversion.
#include <mln/core/image/image2d.hh>
-#include <mln/morpho/attribute/volume.hh>
+#include <mln/fun/v2v/hsl_to_rgb.hh>
+
+#include <mln/level/compare.hh>
+#include <mln/level/transform.hh>
+
+#include <mln/value/hsl.hh>
+#include <mln/value/rgb8.hh>
+
+#include <mln/debug/println.hh>
+
+using mln::value::rgb8;
+using mln::value::hsl_f;
+
+rgb8 ref[][2] = { { rgb8(0,0,0), rgb8(255,255,255) },
+ { rgb8(128,128,128), rgb8(90,90, 90) } };
+
+hsl_f dat[][2] = { { hsl_f(0,0,0), hsl_f(0,0,255) },
+ { hsl_f(0,0,128), hsl_f(0,0,90) } };
int main()
{
using namespace mln;
- typedef image2d<int> I;
- I ima(3, 3);
+ image2d<rgb8> ref_ima = make::image(ref);
+ image2d<hsl_f> ima = make::image(dat);
- util::pix<I> px(ima, point2d(0,0));
+ image2d<value::rgb8> ima_rgb = level::transform(ima,
+ fun::v2v::f_hsl_to_rgb_3x8);
- morpho::attribute::volume<I> v;
- v.take(px);
- mln_assertion(v == 1);
+ mln_assertion(ima_rgb == ref_ima);
}
+
diff --git a/milena/tests/fun/v2v/rgb_hsi_conversion.cc b/milena/tests/fun/v2v/rgb_hsi_conversion.cc
deleted file mode 100644
index f760fa1..0000000
--- a/milena/tests/fun/v2v/rgb_hsi_conversion.cc
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
-// Boston, MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-/// \file tests/fun/v2v/rgb_hsi_conversion.cc
-///
-/// Test RGB-to-HSI conversion.
-
-#include <cmath>
-
-#include <mln/value/hsi.hh>
-#include <mln/fun/v2v/rgb_to_hsi.hh>
-
-#include <mln/core/image/image2d.hh>
-#include <mln/value/rgb8.hh>
-
-#include <mln/io/ppm/load.hh>
-#include <mln/io/ppm/save.hh>
-#include <mln/math/round.hh>
-#include <mln/level/transform.hh>
-
-#include "tests/data.hh"
-
-
-template <typename I1, typename I2>
-float rms(const mln::Image<I1>& ima1_, const mln::Image<I2>& ima2_)
-{
- const I1& ima1 = exact(ima1_);
- const I2& ima2 = exact(ima2_);
-
- mln_precondition(ima1.is_valid() && ima2.is_valid());
-
- double sum = 0, nb = 0;
-
- mln_piter(I1) p(ima1.domain());
- for_all(p)
- {
- mln_value(I1) c1 = ima1(p);
- mln_value(I2) c2 = ima2(p);
- double
- distred = c2.red() - c1.red(),
- distgreen = c2.green() - c1.green(),
- distblue = c2.blue() - c1.blue();
-
- ++nb;
- sum += distred * distred + distblue * distblue + distgreen * distgreen;
- }
-
- if (nb == 0)
- return 0;
-
- return std::sqrt(sum / nb);
-}
-
-
-int main()
-{
- using namespace mln;
-
- image2d<value::rgb8> lena;
- io::ppm::load(lena, MLN_IMG_DIR "/lena.ppm");
-
- image2d<value::hsi_f> lena_hsi = level::transform(lena,
- fun::v2v::f_rgb_to_hsi_f);
-
- image2d<value::rgb8> lena_rgb = level::transform(lena_hsi,
- fun::v2v::f_hsi_to_rgb_3x8);
-
- double err = rms(lena, lena_rgb);
- std::cout << "err: " << err << std::endl;
-}
-
diff --git a/milena/tests/morpho/attribute/volume.cc b/milena/tests/fun/v2v/rgb_to_hsl.cc
similarity index 62%
copy from milena/tests/morpho/attribute/volume.cc
copy to milena/tests/fun/v2v/rgb_to_hsl.cc
index 9360fec..45d6d77 100644
--- a/milena/tests/morpho/attribute/volume.cc
+++ b/milena/tests/fun/v2v/rgb_to_hsl.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,24 +26,42 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/morpho/attribute/volume.cc
+/// \file tests/fun/v2v/rgb_to_hsl.cc
///
-/// Test on mln::morpho::attribute::volume.
+/// Test RGB-to-HSL conversion.
#include <mln/core/image/image2d.hh>
-#include <mln/morpho/attribute/volume.hh>
+#include <mln/value/hsl.hh>
+#include <mln/value/rgb8.hh>
+
+#include <mln/fun/v2v/rgb_to_hsl.hh>
+
+#include <mln/level/compare.hh>
+#include <mln/level/transform.hh>
+
+#include <mln/make/image.hh>
+
+#include <mln/debug/println.hh>
+
+using mln::value::rgb8;
+using mln::value::hsl_f;
+
+rgb8 dat[][2] = { { rgb8(0,0,0), rgb8(255,255,255) },
+ { rgb8(128,128,128), rgb8(90,90, 90) } };
+
+hsl_f ref[][2] = { { hsl_f(0,0,0), hsl_f(0,0,255) },
+ { hsl_f(0,0,128), hsl_f(0,0,90) } };
int main()
{
using namespace mln;
- typedef image2d<int> I;
- I ima(3, 3);
+ image2d<value::rgb8> ima = make::image(dat);
+ image2d<hsl_f> ref_ima = make::image(ref);
+ image2d<hsl_f> ima_hsl = level::transform(ima,
+ fun::v2v::f_rgb_to_hsl_f);
- util::pix<I> px(ima, point2d(0,0));
-
- morpho::attribute::volume<I> v;
- v.take(px);
- mln_assertion(v == 1);
+ mln_assertion(ima_hsl == ref_ima);
}
+
diff --git a/milena/tests/morpho/attribute/card.cc b/milena/tests/morpho/attribute/card.cc
index afdaaaf..6bc5b4e 100644
--- a/milena/tests/morpho/attribute/card.cc
+++ b/milena/tests/morpho/attribute/card.cc
@@ -46,5 +46,5 @@ int main()
c.take();
c.take(p);
c.take(px);
- mln_assertion(c == 3);
+ mln_assertion(c == 3u);
}
diff --git a/milena/tests/morpho/attribute/height.cc b/milena/tests/morpho/attribute/height.cc
index 4b2a2d0..63be89e 100644
--- a/milena/tests/morpho/attribute/height.cc
+++ b/milena/tests/morpho/attribute/height.cc
@@ -44,7 +44,7 @@ int main()
for (int i = 0; i < 5; i++)
accu.take(t[i]);
- mln_assertion(accu.to_result() == 7);
+ mln_assertion(accu.to_result() == 7u);
A accu2;
@@ -54,9 +54,9 @@ int main()
accu.take(t[i] + 2);
accu2.take(t[i] - 2);
}
- mln_assertion(accu.to_result() == 7);
- mln_assertion(accu2.to_result() == 7);
+ mln_assertion(accu.to_result() == 7u);
+ mln_assertion(accu2.to_result() == 7u);
accu.take(accu2);
- mln_assertion(accu.to_result() == 11);
+ mln_assertion(accu.to_result() == 11u);
}
diff --git a/milena/tests/morpho/attribute/volume.cc b/milena/tests/morpho/attribute/volume.cc
index 9360fec..3bb8af2 100644
--- a/milena/tests/morpho/attribute/volume.cc
+++ b/milena/tests/morpho/attribute/volume.cc
@@ -44,5 +44,5 @@ int main()
morpho::attribute::volume<I> v;
v.take(px);
- mln_assertion(v == 1);
+ mln_assertion(v == 1u);
}
--
1.5.6.5
1
0