920: Fix CC_tarjan + test, sequential reconstruction.

Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Fix CC_tarjan + test, sequential reconstruction. * tests/algorithms/cc_tarjan.cc: . * oln/morpho/reconstruction.hh: New. * oln/morpho/cc_tarjan.hh: . * oln/io/pnm.hh: . oln/io/pnm.hh | 53 ++++++++++++++-------------- oln/morpho/cc_tarjan.hh | 9 +--- oln/morpho/reconstruction.hh | 78 ++++++++++++++++++++++++++++++++++++++++++ tests/algorithms/cc_tarjan.cc | 52 ++++++++++------------------ 4 files changed, 128 insertions(+), 64 deletions(-) Index: tests/algorithms/cc_tarjan.cc --- tests/algorithms/cc_tarjan.cc (revision 919) +++ tests/algorithms/cc_tarjan.cc (working copy) @@ -4,42 +4,30 @@ #include <oln/morpho/cc_tarjan.hh> -#include <oln/debug/print.hh> - - -template <typename I> -void set(I& ima, - int i, - int j) -{ - oln_point(I) p(i, j); - ima(p) = true; -} - int main() { using namespace oln; typedef image2d<bool> I; I ima(3, 3); - set(ima, 0, 0); - set(ima, 0, 1); - set(ima, 0, 2); - - set(ima, 2, 0); - set(ima, 2, 1); - set(ima, 2, 2); - - I out = morpho::cc_tarjan(ima + c4); - -// for (unsigned i; i < 3; i++) -// for (unsigned j; j < 3; j++) -// { -// if (i == 0) -// assert(ima(i, j) == 1); -// if (i == 1) -// assert(ima(i, j) == 0); -// if (i == 2) -// assert(ima(i, j) == 2); -// } + ima.at(0, 0) = true; + ima.at(0, 1) = true; + ima.at(0, 2) = true; + + ima.at(2, 0) = true; + ima.at(2, 1) = true; + ima.at(2, 2) = true; + + image2d<unsigned int> out = (morpho::cc_tarjan(ima + c4)).image(); + + for (unsigned i = 0; i < 3; i++) + for (unsigned j = 0; j < 3; j++) + { + if (i == 0) + assert(out.at(i, j) == 1); + if (i == 1) + assert(out.at(i, j) == 0); + if (i == 2) + assert(out.at(i, j) == 2); + } } Index: oln/morpho/reconstruction.hh --- oln/morpho/reconstruction.hh (revision 0) +++ oln/morpho/reconstruction.hh (revision 0) @@ -0,0 +1,78 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// 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 OLN_MORPHO_RECONSTRUCTION_HH +# define OLN_MORPHO_RECONSTRUCTION_HH + +#include <oln/accumulator/max.hh> + +namespace oln +{ + + namespace morpho + { + + namespace impl + { + + template <typename I , typename J> + void // FIXME : slow version. + reconstruction_(const Image_with_Nbh<I>& marker, + const Binary_Image<I>& mask) + { + // first + oln_fwd_piter(I) p(input.points()); + for_all(p) + marker(p) = local(max, marker, p) && mask(p); // FIXME : local_sup. + + + // second + oln_bkd_piter(I) p(input.points()); + for_all(p) + marker(p) = local(max, marker, p) && mask(p); // FIXME : local_inf. + } + + } // end of namespace oln::morpho::impl + + template <typename I , typename J> + void + reconstruction(const Image_with_Nbh<I>& marker, + const Binary_Image<J>& mask) + { + impl::reconstruction_(exact(mask), exact(marker)); + } + + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLN_MORPHO_DILATION_HH Index: oln/morpho/cc_tarjan.hh --- oln/morpho/cc_tarjan.hh (revision 919) +++ oln/morpho/cc_tarjan.hh (working copy) @@ -10,7 +10,7 @@ // 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 +// You should have receiv 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. @@ -70,18 +70,15 @@ oln_bkd_piter(I) p(input.points()); for_all(p) { + parent(p) = p; if ( input(p) ) { - parent(p) = p; oln_niter(I) n(p, input); for_all(n) { - if ( input(n) ) - { - if ( is_processed(n) ) + if ( input(n) && is_processed(n) ) do_union(input ,n, p, parent); } - } is_processed(p) = true; } } Index: oln/io/pnm.hh --- oln/io/pnm.hh (revision 919) +++ oln/io/pnm.hh (working copy) @@ -33,8 +33,9 @@ # include <fstream> # include <string> -# include <oln/basics2d.hh> - +# include <oln/core/2d/image2d.hh> +# include <oln/core/2d/window2d.hh> +# include <oln/core/2d/neighb2d.hh> namespace oln { @@ -117,7 +118,7 @@ oln_coord(I) cols = 0; unsigned bits = 0; unsigned char c = 0; - oln_fwd_piter(I) p(ima.topo()); + oln_fwd_piter(I) p(ima.points()); for_all(p) { if (bits == 0) @@ -126,7 +127,7 @@ bits = 8; } ima(p) = (c & (1 << --bits)) ? false : true; - if (++cols >= int(ima.bbox().ncols())) + if (++cols >= int(ima.max_col())) cols = bits = 0; } } @@ -136,7 +137,7 @@ template <typename I> void load_pbm_ascii(std::ifstream& file, I& ima) { - oln_fwd_piter(I) p(ima.topo()); + oln_fwd_piter(I) p(ima.points()); for_all(p) ima(p) = (file.get() == '0'); } @@ -162,7 +163,7 @@ template <typename I> void load_pnm_raw_2d(std::ifstream& file, I& ima) { - int col = ima.pmin().col(); + int col = ima.col(); size_t len = ima.bbox().ncols(); for (int row = ima.pmin().row(); row <= ima.pmax().row(); ++row) file.read((char*)(ima.adr_at(row, col)), @@ -195,26 +196,26 @@ } - image2d<unsigned char> load_pgm(const std::string& filename) - { - std::ifstream file(filename.c_str()); - if (not file) - { - std::cerr << "error: file '" << filename - << "' not found!"; - abort(); - } - char type; - int nrows, ncols; - internal::read_pnm_header('2', '5', file, type, nrows, ncols); - image2d<unsigned char> ima(nrows, ncols); - if (type == '4') - internal::load_pnm_raw_2d(file, ima); - else - // type == '1' - internal::load_pnm_ascii(file, ima); - return ima; - } +// image2d<unsigned char> load_pgm(const std::string& filename) +// { +// std::ifstream file(filename.c_str()); +// if (not file) +// { +// std::cerr << "error: file '" << filename +// << "' not found!"; +// abort(); +// } +// char type; +// int nrows, ncols; +// internal::read_pnm_header('2', '5', file, type, nrows, ncols); +// image2d<unsigned char> ima(nrows, ncols); +// if (type == '4') +// internal::load_pnm_raw_2d(file, ima); +// else +// // type == '1' +// internal::load_pnm_ascii(file, ima); +// return ima; +// } } // end of namespace oln::io
participants (1)
-
Ugo Jardonnet