segment.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. int main(int argc, char **argv) {
  22. if (argc != 6) {
  23. fprintf(stderr, "usage: %s sigma k min input(ppm) output(ppm)\n", argv[0]);
  24. return 1;
  25. }
  26. float sigma = atof(argv[1]);
  27. float k = atof(argv[2]);
  28. int min_size = atoi(argv[3]);
  29. printf("loading input image.\n");
  30. image<rgb> *input = loadPPM(argv[4]);
  31. printf("processing\n");
  32. int num_ccs;
  33. image<rgb> *seg = segment_image(input, sigma, k, min_size, &num_ccs);
  34. savePPM(seg, argv[5]);
  35. printf("got %d components\n", num_ccs);
  36. printf("done! uff...thats hard work.\n");
  37. return 0;
  38. }