932: Fix pnm.hh : image loading (pbm, pgm ...).

Enjoy!! Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Fix pnm.hh : image loading (pbm, pgm ...). * oln/morpho/reconstruction.hh: Up. * oln/io/pnm.hh: Fixed. io/pnm.hh | 50 +++++++++++++++++++++++------------------------ morpho/reconstruction.hh | 14 ++++++------- 2 files changed, 32 insertions(+), 32 deletions(-) Index: oln/morpho/reconstruction.hh --- oln/morpho/reconstruction.hh (revision 931) +++ oln/morpho/reconstruction.hh (working copy) @@ -41,7 +41,7 @@ template <typename I , typename J> void - reconstruction(const Mutable_Image<I>& marker, + reconstruction(const Image_with_Nbh<I>& marker, const Binary_Image<J>& mask); # ifndef OLN_INCLUDE_ONLY @@ -51,8 +51,8 @@ template <typename I> bool - stability(const Image_with_Nbh<I>& marker, - const Image_with_Nbh<I>& tmp) + stability(Image_with_Nbh<I>& marker, + I& tmp) { oln_piter(I) p(marker.points()); for_all(p) // FIXME : Concept doesn't own .image()? add != is better @@ -89,22 +89,22 @@ reconstruction_(const Image_with_Nbh<I>& marker, const Binary_Image<J>& mask) { - oln_plain(I) tmp = level::clone(marker); + image2d<int> tmp = level::clone(exact(marker).image()); while ( not stability(marker, tmp) ) { - level::fill(exact(marker).image(), exact(tmp).image()); //add fill version better. + level::fill(marker, tmp); tmp = reconstruction_loop(marker, mask); } - level::fill(exact(marker).image(), exact(tmp).image()); + level::fill(marker, tmp); } } // end of namespace oln::morpho::impl template <typename I , typename J> void - reconstruction(const Mutable_Image<I>& marker, + reconstruction(const Image_with_Nbh<I>& marker, const Binary_Image<J>& mask) { impl::reconstruction_(exact(marker), exact(mask)); Index: oln/io/pnm.hh --- oln/io/pnm.hh (revision 931) +++ oln/io/pnm.hh (working copy) @@ -147,7 +147,7 @@ template <typename I> void load_pnm_ascii(std::ifstream& file, I& ima) { - oln_fwd_piter(I) p(ima.topo()); + oln_fwd_piter(I) p(ima.points()); for_all(p) { oln_value(I) value; @@ -163,10 +163,10 @@ template <typename I> void load_pnm_raw_2d(std::ifstream& file, I& ima) { - 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)), + int col = ima.max_col(); + size_t len = ima.bbox().pmax().col(); + for (int row = ima.min_row(); row <= ima.max_row(); ++row) + file.read((char*)(ima.at(row, col)), len * sizeof(oln_value(I))); } @@ -196,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