testMarkov.txt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <segmentation/RSMarkovCluster.h>
  2. #include <core/basics/Config.h>
  3. #include <core/image/DeprecatedConverter.h>
  4. #include <iostream>
  5. #include <iomanip>
  6. #include <deque>
  7. #include <stdlib.h>
  8. #include <time.h>
  9. using namespace OBJREC;
  10. using namespace NICE;
  11. using namespace std;
  12. int main ( int argc, char** argv ) {
  13. if ( argc < 3 ) return -1;
  14. Config* conf = new Config ( argv[1] );
  15. RSMarkovCluster clusterAlg ( conf );
  16. ColorImage cimg ( argv[2] );
  17. ColorImage segImage ( cimg.width(), cimg.height() );
  18. //clusterAlg.findAttractorsOfGraph();
  19. Matrix clusterMatrix ( cimg.height(), cimg.width(), 0 );
  20. int count = clusterAlg.segRegions ( cimg, clusterMatrix );
  21. printf ( "%d Regionen gefunden\n", count );
  22. if ( count != 0 )
  23. {
  24. /* initialize random seed: */
  25. srand ( time ( NULL ) );
  26. VVector colors;
  27. colors.resize ( ( cimg.height() *cimg.width() ) );
  28. for ( uint i = 0;i < ( cimg.height() *cimg.width() );i++ )
  29. {
  30. Vector colors_i ( 3 );
  31. for ( uint c = 0;c < 3;c++ ) colors_i[c] = ( rand() % 255 + 1 );
  32. colors[i] = colors_i;
  33. }
  34. for ( uint y = 0;y < cimg.height();y++ )
  35. {
  36. for ( uint x = 0;x < cimg.width();x++ )
  37. {
  38. int indexP = clusterMatrix ( y, x );
  39. //int R=round((double(clusterMatrix(y,x)))/255.0);//rand() % 255 + 1;
  40. //int G=R;//rand() % 255 + 1;
  41. //int B=G;//rand() % 255 + 1;
  42. segImage.setPixel ( x, y, 0, colors[indexP][0] );
  43. segImage.setPixel ( x, y, 1, colors[indexP][1] );
  44. segImage.setPixel ( x, y, 2, colors[indexP][2] );
  45. }
  46. }
  47. showImage ( segImage );
  48. }
  49. delete conf;
  50. return 0;
  51. }