
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox Index: ChangeLog from Alexandre Abraham <abraham@lrde.epita.fr> Add closing, udate filter parameters. * nature/closing.cc: New. * nature/gradient.cc: . * nature/histo_hsi.cc: . * nature/hom.cc: . * nature/opening.cc: . closing.cc | 59 +++++++++++++++++++++++++++++++ gradient.cc | 5 +- histo_hsi.cc | 39 +++++++++++--------- hom.cc | 110 ++++++++++++++++++++++++++++++++++++++++++++++++----------- opening.cc | 10 ++--- 5 files changed, 180 insertions(+), 43 deletions(-) Index: nature/closing.cc --- nature/closing.cc (revision 0) +++ nature/closing.cc (revision 0) @@ -0,0 +1,59 @@ +// Copyright (C) 2007, 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. + +#include <mln/core/image/image2d.hh> +#include <mln/win/rectangle2d.hh> + +#include <mln/io/pgm/load.hh> +#include <mln/io/pgm/save.hh> + +#include <mln/value/int_u8.hh> +#include <mln/morpho/closing.hh> + +int main(int argc, const char * argv[]) +{ + using namespace mln; + using value::int_u8; + + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " in.pgm [other_files.pgm]" << std::endl; + return 1; + } + + for (int i = 1; i < argc; ++i) + { + image2d<int_u8> ima; + io::pgm::load(ima, argv[i]); + + win::rectangle2d rect(5, 5); + border::thickness = 11; + + std::string name(argv[i]); + name.erase(name.length() - 4); + io::pgm::save(morpho::closing(ima, rect), name.append("_opened.pgm")); + } +} Index: nature/gradient.cc --- nature/gradient.cc (revision 2760) +++ nature/gradient.cc (working copy) @@ -53,7 +53,8 @@ win::rectangle2d rect(5, 5); border::thickness = 5; - io::pgm::save( morpho::gradient(ima, rect), - "out.pgm" ); + std::string name(argv[i]); + name.erase(name.length() - 4); + io::pgm::save(morpho::gradient(ima, rect), name.append("_grad.pgm")); } } Index: nature/histo_hsi.cc --- nature/histo_hsi.cc (revision 2760) +++ nature/histo_hsi.cc (working copy) @@ -61,24 +61,28 @@ template <typename I> -void save_histo(Image<I> &i, std::string &name, unsigned width, unsigned height, unsigned npoints) +void save_histo(Image<I> &i, std::string &name) { I& ima = exact(i); - histo::data<u_t> h = histo::compute(ima); + histo::data<float01_8> h = histo::compute(ima); - double norm = (double) npoints / (double) height; + // Compute histo max + size_t max = 0; + mln_viter(mln::value::set<float01_8>) v(h.vset()); - image2d<bool> output(height + 1, width + 1, 0); + for_all(v) + if (h(v) > max) + max = h(v); + + image2d<bool> output(max, mln_card(float01_8), 0); level::fill(output, true); - mln_viter(mln::value::set<u_t>) v(h.vset()); for_all(v) - if (h(v) > 0) - for (u_t i = 0; i < h(v)/norm; ++i) + for (size_t i = 0; i < h(v); ++i) { // std::cout << height - i << ", " << (u_t)v << std::endl; - output(point2d(height - i, (u_t)v)) = false; + output(point2d(max - i - 1, (float01_8)v)) = false; } io::pbm::save(output, name); @@ -91,21 +95,19 @@ return 1; } - for (unsigned i = 1; i < argc; ++i) + for (int i = 1; i < argc; ++i) { image2d<rgb8> input; io::ppm::load(input, argv[i]); - unsigned npoints = input.ncols() * input.nrows(); - image2d<hsi_f> hsi = level::transform(input, fun::v2v::f_rgb_to_hsi_f); thru<mln::meta::hue<hsi_f>, image2d<hsi_f> > h(hsi); - cast_image_<u_t, thru<mln::meta::hue<hsi_f>, image2d<hsi_f> > > hue(h); + cast_image_<float01_8, thru<mln::meta::hue<hsi_f>, image2d<hsi_f> > > hue(h); std::string n(argv[i]); n.erase(n.length() - 4); - io::pgm::save(hue, n.append("_hue.pgm")); + // io::pgm::save(hue, n.append("_hue.pgm")); image2d<hsi_f>::piter p(hsi.domain()); float m = 0; @@ -120,8 +122,10 @@ std::string name(argv[i]); name.erase(name.length() - 4); - save_histo(hue, name.append("_hue.pbm"), 256, 360, npoints); + save_histo(hue, name.append("_hue.pbm")); + + /* thru<mln::meta::sat<hsi_f>, image2d<hsi_f> > s(hsi); cast_image_<u_t, thru<mln::meta::sat<hsi_f>, image2d<hsi_f> > > sat(s); @@ -162,5 +166,6 @@ name = argv[i]; name.erase(name.length() - 4); save_histo(inty, name.append("_inty.pbm"), 256, 256, npoints); + */ } } Index: nature/hom.cc --- nature/hom.cc (revision 2760) +++ nature/hom.cc (working copy) @@ -34,6 +34,7 @@ #include <mln/io/pbm/save.hh> #include <mln/value/int_u8.hh> +#include <mln/value/int_u16.hh> # include <mln/core/alias/window2d.hh> @@ -56,39 +57,110 @@ for (int i = 1; i < argc; ++i) { - image2d<int_u8> ima; + typedef int_u8 int_t; + + image2d<int_t> ima; io::pgm::load(ima, argv[i]); // Compute the mean - int_u8 mean = estim::mean(ima); + int_t mean = estim::mean(ima); + + image2d<bool> imab = binarization::threshold(ima, mean); + + border::thickness = 10; window2d winout; window2d winin; - static const bool matout [] = {0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 0}; - - convert::from_to(matout, winout); - - static const bool matin [] = {0, 1, 0, 0, 0, 0, 0, - 0, 1, 0, 0, 0, 0, 0, - 0, 1, 0, 0, 0, 0, 0, - 0, 1, 0, 0, 0, 0, 0, - 0, 1, 0, 0, 0, 0, 0, - 0, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0}; +// static const bool matout [] = {0, 0, 0, 0, 0, 0, 0, +// 0, 0, 1, 0, 0, 0, 0, +// 0, 0, 1, 0, 0, 0, 0, +// 0, 0, 1, 0, 0, 0, 0, +// 0, 0, 1, 1, 1, 1, 0, +// 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0}; + +// static const bool matout [] = {0, 0, 0, 0, 0, +// 0, 1, 0, 0, 0, +// 0, 1, 0, 0, 0, +// 0, 1, 1, 1, 0, +// 0, 0, 0, 0, 0}; + + static const bool blmatout [] = {0, 0, 0, + 1, 0, 0, + 1, 1, 0}; + + + convert::from_to(blmatout, winout); + +// static const bool matin [] = {0, 0, 0, 1, 0, 0, 0, +// 0, 0, 0, 1, 0, 0, 0, +// 0, 0, 0, 1, 0, 0, 0, +// 0, 0, 0, 1, 1, 1, 1, +// 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0}; + +// static const bool matin [] = {0, 0, 1, 0, 0, +// 0, 0, 1, 0, 0, +// 0, 0, 1, 1, 1, +// 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0}; + + static const bool blmatin [] = {0, 1, 0, + 0, 1, 1, + 0, 0, 0}; + + convert::from_to(blmatin, winin); + image2d<bool> bottom_left = morpho::hit_or_miss(imab, winout, winin); + + + static const bool brmatout [] = {0, 0, 0, + 0, 0, 1, + 0, 1, 1}; + + static const bool brmatin [] = {0, 1, 0, + 1, 1, 0, + 0, 0, 0}; + + convert::from_to(brmatout, winout); + convert::from_to(brmatin, winin); + image2d<bool> bottom_right = morpho::hit_or_miss(imab, winout, winin); + + static const bool urmatout [] = {0, 1, 1, + 0, 0, 1, + 0, 0, 0}; + + static const bool urmatin [] = {0, 0, 0, + 1, 1, 0, + 0, 1, 0}; + + convert::from_to(urmatout, winout); + convert::from_to(urmatin, winin); + image2d<bool> up_right = morpho::hit_or_miss(imab, winout, winin); + + + static const bool ulmatout [] = {1, 1, 0, + 1, 0, 0, + 0, 0, 0}; + + static const bool ulmatin [] = {0, 0, 0, + 0, 1, 1, + 0, 1, 0}; + + convert::from_to(ulmatout, winout); + convert::from_to(ulmatin, winin); + image2d<bool> up_left = morpho::hit_or_miss(imab, winout, winin); - convert::from_to(matin, winin); std::string name(argv[i]); name.erase(name.length() - 4); - io::pbm::save( morpho::hit_or_miss(binarization::threshold(ima, mean), winout, winin), + io::pbm::save( imab, name.append("_bin.pbm")); + + name = argv[i]; + name.erase(name.length() - 4); + io::pbm::save( up_left + up_right + bottom_right + bottom_left, name.append("_hom.pbm")); } } Index: nature/opening.cc --- nature/opening.cc (revision 2760) +++ nature/opening.cc (working copy) @@ -34,7 +34,6 @@ #include <mln/value/int_u8.hh> #include <mln/morpho/opening.hh> - int main(int argc, const char * argv[]) { using namespace mln; @@ -50,10 +49,11 @@ image2d<int_u8> ima; io::pgm::load(ima, argv[i]); - win::rectangle2d rect(1, 51); - border::thickness = 100; + win::rectangle2d rect(5, 5); + border::thickness = 11; - io::pgm::save( morpho::opening(ima, rect), - "out.pgm" ); + std::string name(argv[i]); + name.erase(name.length() - 4); + io::pgm::save(morpho::opening(ima, rect), name.append("_opened.pgm")); } }