ICETools.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * @file ICETools.cpp
  3. * @brief simple ICE GUI tools
  4. * @author Erik Rodner
  5. * @date 03/13/2008
  6. */
  7. #include "core/basics/Exception.h"
  8. #include "core/vector/VectorT.h"
  9. #include "core/vector/MatrixT.h"
  10. #include "core/image/ImageT.h"
  11. #include "core/image/Convert.h"
  12. #include "core/image/RectT.h"
  13. #include "core/imagedisplay/ImageDisplay.h"
  14. #include "vislearning/baselib/ICETools.h"
  15. #include <iostream>
  16. using namespace OBJREC;
  17. using namespace std;
  18. //using namespace NICE;
  19. ICETools::ICETools()
  20. {
  21. }
  22. ICETools::~ICETools()
  23. {
  24. }
  25. void ICETools::selectRectangles ( const NICE::Image & panel, NICE::Image & overlay, vector<NICE::Vector> & x, int color )
  26. {
  27. fthrow ( NICE::Exception, "ICETools::selectRectangles -- not yet implemented due to old ICE version." );
  28. }
  29. void ICETools::selectPoints ( const NICE::Image & panel, NICE::Image & overlay, vector<NICE::Vector> & x, int color )
  30. {
  31. fthrow ( NICE::Exception, "ICETools::selectPoints -- not yet implemented due to old ICE version." );
  32. }
  33. void ICETools::convertToRGB ( const NICE::Matrix & m, NICE::ColorImage & img )
  34. {
  35. matrixToPseudoColor(m, img);
  36. }
  37. void ICETools::convertToRGB ( const NICE::FloatImage & m, NICE::ColorImage & img )
  38. {
  39. imageToPseudoColor(m, img);
  40. }
  41. void ICETools::calcGrayImage ( const NICE::ColorImage & img, NICE::Image & imgg )
  42. {
  43. imgg.resize ( img.width(), img.height() );
  44. for ( int y = 0 ; y < img.height(); y++ )
  45. for ( int x = 0 ; x < img.width() ; x++ )
  46. {
  47. unsigned char g = ( unsigned char ) ( 0.299 * img.getPixel ( x, y, 0 ) +
  48. 0.587 * img.getPixel ( x, y, 1 ) + 0.114 * img.getPixel ( x, y, 2 ) );
  49. imgg.setPixel ( x, y, g );
  50. }
  51. }
  52. double *ICETools::convertICE2M ( const NICE::Matrix & M )
  53. {
  54. double *raw = new double [ M.rows() * M.cols() ];
  55. long index = 0;
  56. for ( uint i = 0 ; i < M.rows() ; i++ )
  57. for ( uint j = 0 ; j < M.cols() ; j++, index++ )
  58. raw[index] = M ( i, j );
  59. return raw;
  60. }
  61. void ICETools::convertM2ICE ( NICE::Matrix & M, double *raw )
  62. {
  63. long index = 0;
  64. for ( int i = 0 ; i < ( int ) M.rows() ; i++ )
  65. for ( int j = 0 ; j < ( int ) M.cols() ; j++, index++ )
  66. M ( i, j ) = raw[index];
  67. }
  68. #ifndef NOVISUAL
  69. int ICETools::markImage ( const NICE::Image & img, NICE::Image & mark, int marksize, int color )
  70. {
  71. fprintf ( stderr, "ICETools::markImage: reimplement this function for NICE\n" );
  72. exit ( -1 );
  73. return 0;
  74. }
  75. int ICETools::showImages ( vector<NICE::Image> & imagelist )
  76. {
  77. #ifndef NOVISUAL
  78. for ( size_t j = 0 ; j < imagelist.size() ; j++ )
  79. {
  80. showImage ( imagelist[j] );
  81. }
  82. #endif
  83. int xsize = imagelist[0].width();
  84. int ysize = imagelist[0].height();
  85. int n = imagelist.size();
  86. int n1 = ( int ) sqrt ( (double)n );
  87. int n2 = n / n1 + 1;
  88. NICE::Image img ( n1*xsize, n2*ysize );
  89. img.set ( 0 );
  90. int k = 0;
  91. for ( int j = 0 ; j < n2 ; j++ )
  92. for ( int i = 0 ; i < n1 ; i++, k++ )
  93. if ( k >= n ) break;
  94. else {
  95. for ( int y = 0 ; y < imagelist[k].height(); y++ )
  96. for ( int x = 0 ; x < imagelist[k].width(); x++ )
  97. {
  98. img.setPixel ( i*xsize + x, j*ysize + y,
  99. imagelist[k].getPixel ( x, y ) );
  100. }
  101. }
  102. img.write ( "display.bmp" );
  103. getchar();
  104. return 0;
  105. }
  106. #endif