00001 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of the Olena Library. This library is free 00004 // software; you can redistribute it and/or modify it under the terms 00005 // of the GNU General Public License version 2 as published by the 00006 // Free Software Foundation. 00007 // 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this library; see the file COPYING. If not, write to 00015 // the Free Software Foundation, 51 Franklin Street, Fifth Floor, 00016 // Boston, MA 02111-1307, USA. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software library without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to 00022 // produce an executable, this file does not by itself cause the 00023 // resulting executable to be covered by the GNU General Public 00024 // License. This exception does not however invalidate any other 00025 // reasons why the executable file might be covered by the GNU General 00026 // Public License. 00027 00028 #include <cstdlib> 00029 00030 #include <string> 00031 00032 #include <mln/core/image/image2d.hh> 00033 #include <mln/core/alias/neighb2d.hh> 00034 #include <mln/core/alias/window2d.hh> 00035 00036 #include <mln/value/int_u8.hh> 00037 #include <mln/value/label_8.hh> 00038 00039 #include <mln/morpho/gradient.hh> 00040 00041 #include <mln/io/pgm/load.hh> 00042 #include <mln/io/pgm/save.hh> 00043 #include <mln/io/ppm/save.hh> 00044 #include <mln/labeling/colorize.hh> 00045 00046 #include "chain.hh" 00047 00048 int main(int argc, char* argv[]) 00049 { 00050 if (argc != 4) 00051 { 00052 std::cerr << "usage: " << argv[0] << " input.pgm lambda output.ppm" 00053 << std::endl; 00054 std::exit(1); 00055 } 00056 std::string input_filename = argv[1]; 00057 unsigned lambda = atoi(argv[2]); 00058 std::string output_filename = argv[3]; 00059 00060 using namespace mln; 00061 00062 typedef value::int_u8 val; 00063 typedef value::label_8 label; 00064 // Input and output types. 00065 typedef image2d<val> input; 00066 typedef mln_ch_value_(input, label) output; 00067 neighb2d nbh = c4(); 00068 window2d win = win_c4p(); 00069 label nbasins; 00070 00071 std::cout << c4() << std::endl; 00072 std::cout << win_c4p() << std::endl; 00073 00074 // Load, process, save. 00075 input ima = io::pgm::load<val>(input_filename); 00076 // Gradient. 00077 /* FIXME: Unfortunately, we cannot write 00078 00079 morpho::gradient(ima, win) 00080 00081 here, since MM only uses windows (yet?), not neighborhoods. And 00082 we cannot either write 00083 00084 morpho::gradient(ima, nbh.win()), 00085 00086 since that window would not contain the center site... 00087 Therefore, this function asks for a window WIN matching the 00088 neighborhood NBH, plus the center site. 00089 00090 A neighborhood `n' should provide a method `win_p()' returning a 00091 window corresponding to `n' plus the center site. */ 00092 input g = morpho::gradient(ima, win); 00093 00094 #if 0 00095 // FIXME: get the name as argument. 00096 io::pgm::save(g, "apps/lena-g.pgm"); 00097 #endif 00098 00099 // Chain. 00100 output s = chain(g, nbh, lambda, nbasins); 00101 io::ppm::save(labeling::colorize(value::rgb8(), s, nbasins), 00102 output_filename); 00103 }