RSSlic.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "RSSlic.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #ifdef NICE_USELIB_OPENMP
  5. #include <omp.h>
  6. #endif
  7. #include "SLIC/SLIC.h"
  8. using namespace std;
  9. using namespace NICE;
  10. using namespace OBJREC;
  11. RSSlic::RSSlic()
  12. {
  13. //spcount = 100000;
  14. spcount = 200;
  15. compactness = 10.0;
  16. }
  17. RSSlic::RSSlic(const Config *conf )
  18. {
  19. spcount = conf->gI("RSSlic", "m_spcount", 2000);
  20. compactness = conf->gD("RSSlic", "compactness", 10.0);
  21. }
  22. RSSlic::~RSSlic()
  23. {
  24. }
  25. int RSSlic::segRegions ( const NICE::Image & img, NICE::Matrix & mask) const
  26. {
  27. cerr << "not implemented yet" << endl;
  28. return -1;
  29. }
  30. int RSSlic::segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask) const
  31. {
  32. const unsigned int imageWidth = img.width();
  33. const unsigned int imageHeight = img.height();
  34. // Kopieren der Werte aus dem ColorImage -> image<rgb>
  35. uint *inputImage = new uint[3*imageWidth*imageHeight];
  36. //#pragma omp parallel for
  37. unsigned long int counter = 0;
  38. for (int c = 0; c < 3; c++)
  39. {
  40. for ( unsigned int y = 0; y < imageHeight; y++ )
  41. {
  42. for ( unsigned int x = 0; x < imageWidth; x++, counter++)
  43. {
  44. inputImage[counter] = img.getPixelQuick( x, y, c );
  45. }
  46. }
  47. }
  48. int* labels = new int[imageWidth*imageHeight];
  49. // Eingabebild segmentieren
  50. SLIC slic;
  51. int numlabels = 0;
  52. slic.DoSuperpixelSegmentation_ForGivenNumberOfSuperpixels(inputImage, imageWidth, imageHeight, labels, numlabels, spcount, compactness);
  53. slic.DrawContoursAroundSegments(inputImage, labels, imageWidth, imageHeight, 0);
  54. NICE::ColorImage resultImage( imageWidth, imageHeight );
  55. /*
  56. counter = 0;
  57. for (int c = 0; c < 3; c++)
  58. {
  59. for ( unsigned int y = 0; y < imageHeight; y++ )
  60. {
  61. for ( unsigned int x = 0; x < imageWidth; x++, counter++ )
  62. {
  63. resultImage.setPixelQuick( x, y, c, inputImage[counter] );
  64. }
  65. }
  66. }
  67. resultImage.write("tmp.ppm");
  68. */
  69. mask.resize(imageWidth, imageHeight);
  70. counter = 0;
  71. for ( unsigned int y = 0; y < imageHeight; y++ )
  72. {
  73. for ( unsigned int x = 0; x < imageWidth; x++, counter++ )
  74. {
  75. mask(x, y) = labels[counter];
  76. }
  77. }
  78. /*
  79. counter = 0;
  80. for ( unsigned int y = 0; y < imageHeight; y++ )
  81. {
  82. for ( unsigned int x = 0; x < imageWidth; x++, counter++ )
  83. {
  84. for(int c = 0; c < 3; c++)
  85. {
  86. resultImage.setPixelQuick( x, y, c, labels[counter]);
  87. }
  88. }
  89. }
  90. transformSegmentedImg( resultImage, mask);*/
  91. // Speicher freigeben
  92. delete inputImage;
  93. inputImage = NULL;
  94. delete labels;
  95. labels = NULL;
  96. return numlabels -1;
  97. }