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