segment.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. Copyright (C) 2006 Pedro Felzenszwalb
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. */
  15. #include <cstdio>
  16. #include <cstdlib>
  17. #include <segmentation/felzenszwalb/image.h>
  18. #include <segmentation/felzenszwalb/misc.h>
  19. #include <segmentation/felzenszwalb/pnmfile.h>
  20. #include "segmentation/felzenszwalb/segment-image.h"
  21. using namespace felzenszwalb;
  22. int main(int argc, char **argv) {
  23. if (argc != 6) {
  24. fprintf(stderr, "usage: %s sigma k min input(ppm) output(ppm)\n", argv[0]);
  25. return 1;
  26. }
  27. float sigma = atof(argv[1]);
  28. float k = atof(argv[2]);
  29. int min_size = atoi(argv[3]);
  30. printf("loading input image.\n");
  31. image<rgb> *input = loadPPM(argv[4]);
  32. printf("processing\n");
  33. int num_ccs;
  34. image<rgb> *seg = segment_image(input, sigma, k, min_size, &num_ccs);
  35. savePPM(seg, argv[5]);
  36. printf("got %d components\n", num_ccs);
  37. printf("done! uff...thats hard work.\n");
  38. return 0;
  39. }