adaptmedfilter.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @file testSegmentation.cpp
  3. * @brief test segmentation algorithm
  4. * @author Björn Fröhlich
  5. * @date 01/20/2010
  6. */
  7. #include <objrec/nice.h>
  8. #include <objrec/baselib/Config.h>
  9. #include <list>
  10. using namespace OBJREC;
  11. using namespace NICE;
  12. using namespace std;
  13. int main (int argc, char **argv)
  14. {
  15. if(argc < 1)
  16. {
  17. cerr << "Bitte Bild angeben" << endl;
  18. return -1;
  19. }
  20. string filename;
  21. filename += argv[1];
  22. //RSMeanShift rg;
  23. NICE::Image img;
  24. img.read(filename);
  25. NICE::Image out(img);
  26. int masksize = 5;
  27. int mh = masksize/2;
  28. int width = img.width();
  29. int height = img.height();
  30. for(int x= 0; x < width; x++)
  31. {
  32. for(int y = 0; y < height; y++)
  33. {
  34. vector<int> nh;
  35. for(int i = -mh; i <= mh; i++)
  36. {
  37. for(int j = -mh; j <= mh; j++)
  38. {
  39. int xpos = x + i;
  40. int ypos = y + j;
  41. if(xpos < 0 || ypos < 0 || xpos >= width || ypos >= height)
  42. continue;
  43. nh.push_back(img.getPixel(xpos,ypos));
  44. }
  45. }
  46. sort(nh.begin(), nh.end());
  47. int val = nh[nh.size()/2];
  48. out.setPixel(x,y,val);
  49. }
  50. }
  51. out.write("res.ppm");
  52. return 0;
  53. }