ICETools.cpp 3.2 KB

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