5 #include <boost/lexical_cast.hpp>
6 #include <boost/foreach.hpp>
8 #include <mln/io/ppm/save.hh>
13 using namespace mln::value
;
15 /// \file Find a vertical seam in an image.
17 int main (int argc
, char** argv
)
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";
29 nseam
= boost::lexical_cast
<unsigned> (argv
[1]);
31 catch (const boost::bad_lexical_cast
&)
33 std::cerr
<< "invalid 1st argument" << std::endl
;
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 ());
50 io::ppm::save (img
, argv
[3]);
51 for (unsigned i
= 0; i
< nseam
; ++i
)
53 img
= uncarve_vertical_seam (img
, seams
.top ());
57 io::ppm::save (img
, argv
[4]);
58 std::cerr
<< std::endl
;