RSGraphBased.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "RSGraphBased.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #ifdef NICE_USELIB_OPENMP
  5. #include <omp.h>
  6. #endif
  7. #include "felzenszwalb/image.h"
  8. #include "felzenszwalb/misc.h"
  9. #include "felzenszwalb/segment-image.h"
  10. #include "felzenszwalb/pnmfile.h"
  11. using namespace std;
  12. using namespace NICE;
  13. using namespace OBJREC;
  14. using namespace felzenszwalb;
  15. RSGraphBased::RSGraphBased()
  16. {
  17. parameter_k = 500;
  18. parameter_min_size = 200;
  19. parameter_sigma = 1.5;
  20. }
  21. RSGraphBased::RSGraphBased(const Config *conf )
  22. {
  23. //thr = conf->gD( "RSGraphBased", "threshold", 5.0);
  24. parameter_k = conf->gD("RSGraphBased", "k", 500);
  25. parameter_min_size = conf->gI("RSGraphBased", "min_size", 200);
  26. parameter_sigma = conf->gD("RSGraphBased", "sigma", 1.5);
  27. }
  28. RSGraphBased::~RSGraphBased()
  29. {
  30. }
  31. int RSGraphBased::segRegions ( const NICE::Image & img, NICE::Matrix & mask) const
  32. {
  33. cerr << "not implemented yet" << endl;
  34. return -1;
  35. }
  36. int RSGraphBased::segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask) const
  37. {
  38. const unsigned int imageWidth = img.width();
  39. const unsigned int imageHeight = img.height();
  40. // Kopieren der Werte aus dem ColorImage -> image<rgb>
  41. image<rgb> *inputImage = new image<rgb>( imageWidth, imageHeight, false );
  42. #pragma omp parallel for
  43. for ( unsigned int y = 0; y < imageHeight; y++ )
  44. {
  45. for ( unsigned int x = 0; x < imageWidth; x++ )
  46. {
  47. imRef( inputImage, x, y ).r = img.getPixelQuick( x, y, 0 );
  48. imRef( inputImage, x, y ).g = img.getPixelQuick( x, y, 1 );
  49. imRef( inputImage, x, y ).b = img.getPixelQuick( x, y, 2 );
  50. }
  51. }
  52. // Eingabebild segmentieren
  53. int num_ccs; // Anzahl der segmentierten Regionen
  54. image<rgb> *tempResultImage = segment_image( inputImage, parameter_sigma, parameter_k, parameter_min_size, &num_ccs );
  55. // Kopieren der Werte aus dem image<rgb> -> ColorImage
  56. NICE::ColorImage resultImage( imageWidth, imageHeight );
  57. #pragma omp parallel for
  58. for ( unsigned int y = 0; y < imageHeight; y++ )
  59. {
  60. for ( unsigned int x = 0; x < imageWidth; x++ )
  61. {
  62. resultImage.setPixelQuick( x, y, 0, imRef(tempResultImage, x, y ).r );
  63. resultImage.setPixelQuick( x, y, 1, imRef(tempResultImage, x, y ).g );
  64. resultImage.setPixelQuick( x, y, 2, imRef(tempResultImage, x, y ).b );
  65. }
  66. }
  67. // Speicher freigeben
  68. delete inputImage;
  69. inputImage = NULL;
  70. delete tempResultImage;
  71. tempResultImage = NULL;
  72. transformSegmentedImg( resultImage, mask);
  73. return num_ccs;
  74. }