SemanticSegmentation.tcc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include <stdio.h>
  2. #include <vector>
  3. namespace OBJREC {
  4. template<class SrcP>
  5. void SemanticSegmentation::make3DImage ( const std::vector<std::string> & filelist,
  6. NICE::MultiChannelImage3DT<SrcP> & imgData )
  7. {
  8. bool isInit = false;
  9. for ( int it = 0; it < ( int ) filelist.size(); it++ )
  10. {
  11. if ( imagetype == IMAGETYPE_RGB )
  12. {
  13. NICE::ColorImage img;
  14. try
  15. {
  16. img.read ( filelist[it] );
  17. }
  18. catch ( NICE::ImageException iE )
  19. {
  20. fprintf ( stderr, "Failed to open color image file: %s\n", filelist[it].c_str() );
  21. fprintf ( stderr, "%s\n", iE.what() );
  22. exit ( -1 );
  23. }
  24. if ( !isInit )
  25. {
  26. imgData.reInit ( img.width(),img.height(),filelist.size(),3 );
  27. isInit = true;
  28. }
  29. for ( int y = 0; y < img.height(); y++ )
  30. {
  31. for ( int x = 0; x < img.width(); x++ )
  32. {
  33. for ( int r = 0; r < 3; r++ )
  34. {
  35. imgData.set ( x, y, it, (SrcP)img.getPixel ( x,y,r ), r );
  36. }
  37. }
  38. }
  39. }
  40. else
  41. {
  42. NICE::Image img;
  43. try
  44. {
  45. img.read ( filelist[it] );
  46. }
  47. catch ( NICE::ImageException iE )
  48. {
  49. fprintf ( stderr, "Failed to open image file: %s\n", filelist[it].c_str() );
  50. fprintf ( stderr, "%s\n", iE.what() );
  51. exit ( -1 );
  52. }
  53. if ( !isInit )
  54. {
  55. imgData.reInit ( img.width(),img.height(),filelist.size(),1 );
  56. isInit = true;
  57. }
  58. for ( int y = 0; y < img.height(); y++ )
  59. {
  60. for ( int x = 0; x < img.width(); x++ )
  61. {
  62. imgData.set ( x, y, it, (SrcP)img.getPixel ( x,y ), 0 );
  63. }
  64. }
  65. }
  66. }
  67. if ( imagetype == IMAGETYPE_GRAY )
  68. {
  69. imgData.equalizeHistogram( 0 );
  70. }
  71. }
  72. }