Enhance the interface of carve_seam.
[seam-carving.git] / src / seam_main.cc
blob52bb941f9c6033df8b080206cd71115b1048eb0f
1 #include <iostream>
2 #include <stack>
3 #include <vector>
5 #include <boost/lexical_cast.hpp>
6 #include <boost/foreach.hpp>
8 #include <mln/io/ppm/save.hh>
10 #include "all.hh"
12 using namespace mln;
13 using namespace mln::value;
15 /// \file Find a vertical seam in an image.
17 int main (int argc, char** argv)
19 if (argc != 5)
21 std::cerr << "usage: " << *argv << " N in.ppm carved.ppm seams.ppm\n"
22 "where N is an integer > 0: the number of seams to carve.\n";
23 return 1;
26 unsigned nseam = 1;
28 try {
29 nseam = boost::lexical_cast<unsigned> (argv[1]);
31 catch (const boost::bad_lexical_cast&)
33 std::cerr << "invalid 1st argument" << std::endl;
34 return 2;
37 std::cerr << "initializing ... ";
38 image2d<rgb8> img = load (argv[2]);
39 image2d<float> nrg = get_nrg (img);
40 std::stack<std::vector<unsigned> > seams;
42 for (unsigned i = 0; i < nseam; ++i)
44 std::cerr << (i + 1) << "..";
45 seams.push (find_vertical_seam (nrg));
46 img = carve_vertical_seam (img, seams.top ());
47 nrg = carve_vertical_seam (nrg, seams.top ());
49 std::cerr << '.';
50 io::ppm::save (img, argv[3]);
51 for (unsigned i = 0; i < nseam; ++i)
53 img = uncarve_vertical_seam (img, seams.top ());
54 seams.pop ();
56 std::cerr << '.';
57 io::ppm::save (img, argv[4]);
58 std::cerr << std::endl;