Changeset 112:d539a99a6bdc


Ignore:
Timestamp:
01/28/2010 07:49:22 PM (9 years ago)
Author:
Dmitry Fedorov <fedorov@…>
Branch:
default
Phase:
public
Message:

bioview3d: support for float and signed images in 8-64 bits, small UI fixes

Location:
bioView3D
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • bioView3D/TODO.txt

    r41 r112  
    77XXX 9) fix all gobjects
    88XXX 8) live movie export
    9 4) alfa mapping per channel
     9XXX 4) alfa mapping per channel
     10XXX 10) per/ channel mapping looses values when selected back
  • bioView3D/libsrc/libbioimg/formats/biorad_pic/dim_biorad_pic_format.cpp

    r95 r112  
    212212  if (val == 1)   {
    213213    info->depth = 8;
    214     info->pixelType = DIM_TAG_BYTE;
     214    info->pixelType = D_FMT_UNSIGNED;
    215215  }  else   {
    216216    info->depth = 16;
    217     info->pixelType = DIM_TAG_SHORT;
     217    info->pixelType = D_FMT_UNSIGNED;
    218218  }
    219219
  • bioView3D/libsrc/libbioimg/formats/ibw/dim_ibw_format.cpp

    r95 r112  
    172172  // by now we'll normalize all data
    173173  info->depth     = 8;
    174   info->pixelType = DIM_TAG_BYTE;
     174  info->pixelType = D_FMT_UNSIGNED;
    175175
    176176
  • bioView3D/libsrc/libbioimg/formats/oib/dim_oib_format.cpp

    r95 r112  
    238238
    239239  if (info->depth != 16)
    240     info->pixelType = DIM_TAG_BYTE;
     240    info->pixelType = D_FMT_UNSIGNED;
    241241  else
    242     info->pixelType = DIM_TAG_SHORT;
     242    info->pixelType = D_FMT_UNSIGNED;
    243243
    244244  info->resUnits = DIM_RES_um;
  • bioView3D/libsrc/libbioimg/formats/ome/dim_ome_format.cpp

    r43 r112  
    6060  // by now we'll normalize all data
    6161  info->depth     = 8;
    62   info->pixelType = DIM_TAG_BYTE;
     62  info->pixelType = D_FMT_UNSIGNED;
    6363
    6464
  • bioView3D/libsrc/libbioimg/formats/ome/dim_ome_format_io.cpp

    r43 r112  
    3434//FLT_MIN FLT_MAX DBL_MAX DBL_MIN INT_MAX INT_MIN SHRT_MAX SHRT_MIN
    3535
    36 const char *ome_types[13] = { "Uint8", "Uint8", "int8", "Uint16",
    37                               "Uint32", "double", "int8", "Uint8",
    38                               "int16", "int32", "double", "float", "double" };
     36//const char *ome_types[13] = { "Uint8", "Uint8", "int8", "Uint16",
     37//                              "Uint32", "double", "int8", "Uint8",
     38//                              "int16", "int32", "double", "float", "double" };
    3939
    4040const char *bool_types[2] = { "false", "true" };
     
    7373//----------------------------------------------------------------------------
    7474
     75const char* omePixelType( TDimImageBitmap *img ) {
     76  std::string pt = "Uint8";
     77  if (img->i.depth==16 && img->i.pixelType==D_FMT_UNSIGNED) pt = "Uint16";
     78  if (img->i.depth==32 && img->i.pixelType==D_FMT_UNSIGNED) pt = "Uint32";
     79  if (img->i.depth==8  && img->i.pixelType==D_FMT_SIGNED) pt = "int8";
     80  if (img->i.depth==16 && img->i.pixelType==D_FMT_SIGNED) pt = "int16";
     81  if (img->i.depth==32 && img->i.pixelType==D_FMT_SIGNED) pt = "int32";
     82  if (img->i.depth==32 && img->i.pixelType==D_FMT_FLOAT)  pt = "float";
     83  if (img->i.depth==64 && img->i.pixelType==D_FMT_FLOAT)  pt = "double";
     84  return pt.c_str();
     85}
    7586
    7687void omeWriteImageInfo( TDimFormatHandle *fmtHndl )
     
    108119  str += "    <Pixels DimensionOrder = \"XYCZT\" ";
    109120 
    110   sprintf(buf, "PixelType = \"%s\" ", ome_types[img->i.pixelType] );
     121  sprintf(buf, "PixelType = \"%s\" ", omePixelType(img) );
    111122  str += buf;
    112123
  • bioView3D/libsrc/libbioimg/formats/tiff/dim_fluoview_format_io.cpp

    r95 r112  
    363363 
    364364  ii->depth = bitspersample;
    365   if (bitspersample == 16) ii->pixelType = DIM_TAG_SHORT;
     365  if (bitspersample == 16) ii->pixelType = D_FMT_UNSIGNED;
    366366
    367367  unsigned int sample;
  • bioView3D/libsrc/libbioimg/formats/tiff/dim_ometiff_format_io.cpp

    r109 r112  
    289289  uint32 width = 0;
    290290  uint16 samplesperpixel = 1;
     291  uint16 sampleformat = 1;
    291292
    292293  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
     
    294295  TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);
    295296  TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample);
     297  TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &sampleformat);
    296298
    297299  if( TIFFIsTiled(tif) ) return 1;
     
    308310    info->width = width;
    309311    info->height = height;
    310     if (bitspersample == 16) info->pixelType = DIM_TAG_SHORT;
     312    info->pixelType = D_FMT_UNSIGNED;
     313    if (sampleformat == SAMPLEFORMAT_INT)
     314      info->pixelType = D_FMT_SIGNED;
     315    else
     316    if (sampleformat == SAMPLEFORMAT_IEEEFP)
     317      info->pixelType = D_FMT_FLOAT;
     318
    311319    if ( allocImg( fmtHndl, info, img) != 0 ) return 1;
    312320  }
     
    524532//----------------------------------------------------------------------------
    525533
    526 std::string omePixelType( TDimImageBitmap *img ) {
    527   //int8 | int16 | int32 | Uint8 | Uint16 | Uint32 | float
     534std::string omeTiffPixelType( TDimImageBitmap *img ) {
    528535  std::string pt = "Uint8";
    529   if (img->i.depth == 16) pt = "Uint16";
    530   if (img->i.depth == 32) pt = "Uint32";
    531  
    532   if (img->i.pixelType == DIM_TAG_FLOAT)  pt = "float";
    533   if (img->i.pixelType == DIM_TAG_SLONG)  pt = "int32";
    534   if (img->i.pixelType == DIM_TAG_SSHORT) pt = "int16";
    535   if (img->i.pixelType == DIM_TAG_SBYTE)  pt = "int8";
    536 
     536  if (img->i.depth==16 && img->i.pixelType==D_FMT_UNSIGNED) pt = "Uint16";
     537  if (img->i.depth==32 && img->i.pixelType==D_FMT_UNSIGNED) pt = "Uint32";
     538  if (img->i.depth==8  && img->i.pixelType==D_FMT_SIGNED) pt = "int8";
     539  if (img->i.depth==16 && img->i.pixelType==D_FMT_SIGNED) pt = "int16";
     540  if (img->i.depth==32 && img->i.pixelType==D_FMT_SIGNED) pt = "int32";
     541  if (img->i.depth==32 && img->i.pixelType==D_FMT_FLOAT)  pt = "float";
     542  if (img->i.depth==64 && img->i.pixelType==D_FMT_FLOAT)  pt = "double";
    537543  return pt;
    538544}
     
    550556  str += "<Pixels ID=\"openmicroscopy.org:Pixels:1-1\"";
    551557  str += " DimensionOrder=\"XYCZT\"";
    552   str += xstring::xprintf(" PixelType=\"%s\"", omePixelType(img).c_str() );
     558  str += xstring::xprintf(" PixelType=\"%s\"", omeTiffPixelType(img).c_str() );
    553559  str += " BigEndian=\"false\"";
    554560  str += xstring::xprintf(" SizeX=\"%d\"", img->i.width );
     
    677683    TIFFSetField(out, TIFFTAG_SOFTWARE, "DIMIN TIFF WRAPPER <www.dimin.net>");
    678684
     685    // set pixel format
     686    uint16 sampleformat = SAMPLEFORMAT_UINT;
     687    if (img->i.pixelType == D_FMT_SIGNED) sampleformat = SAMPLEFORMAT_INT;
     688    if (img->i.pixelType == D_FMT_FLOAT)  sampleformat = SAMPLEFORMAT_IEEEFP;
     689    TIFFSetField(out, TIFFTAG_SAMPLEFORMAT, sampleformat);
     690
    679691    //if( TIFFGetField( out, TIFFTAG_DOCUMENTNAME, &pszText ) )
    680692    //if( TIFFGetField( out, TIFFTAG_DATETIME, &pszText ) )
     
    695707    case 16 :
    696708    case 32 :
     709    case 64 :
    697710      if ( (compression != COMPRESSION_LZW) && (compression != COMPRESSION_PACKBITS) )
    698711        compression = COMPRESSION_NONE; 
  • bioView3D/libsrc/libbioimg/formats/tiff/dim_psia_format_io.cpp

    r95 r112  
    163163
    164164  img->i.depth   = 16;
    165   img->i.pixelType = DIM_TAG_SHORT;
     165  img->i.pixelType = D_FMT_UNSIGNED;
    166166  img->i.samples = 1;
    167167  img->i.width   = tiffParams->psiaInfo.nWidth;
  • bioView3D/libsrc/libbioimg/formats/tiff/dim_tiff_format.cpp

    r95 r112  
    241241  uint16 bitspersample = 1;
    242242  uint16 samplesperpixel = 1;
     243  uint16 sampleformat = 1;
    243244
    244245  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
     
    246247  TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);
    247248  TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample);
     249  TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &sampleformat);
    248250
    249251  info->width = width;
     
    252254  info->samples = samplesperpixel;
    253255  info->depth = bitspersample;
    254   if (bitspersample != 16)
    255     info->pixelType = DIM_TAG_BYTE;
     256  info->pixelType = D_FMT_UNSIGNED;
     257
     258  if (sampleformat == SAMPLEFORMAT_INT)
     259    info->pixelType = D_FMT_SIGNED;
    256260  else
    257     info->pixelType = DIM_TAG_SHORT;
     261  if (sampleformat == SAMPLEFORMAT_IEEEFP)
     262    info->pixelType = D_FMT_FLOAT;
    258263
    259264
  • bioView3D/libsrc/libbioimg/formats/tiff/dim_tiff_format_io.cpp

    r95 r112  
    795795  TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
    796796
     797 
     798  // set pixel format
     799  uint16 sampleformat = SAMPLEFORMAT_UINT;
     800  if (img->i.pixelType == D_FMT_SIGNED) sampleformat = SAMPLEFORMAT_INT;
     801  if (img->i.pixelType == D_FMT_FLOAT)  sampleformat = SAMPLEFORMAT_IEEEFP;
     802  TIFFSetField(out, TIFFTAG_SAMPLEFORMAT, sampleformat);
     803
     804
     805  // set planar config
    797806  planarConfig = PLANARCONFIG_SEPARATE; // separated planes
    798   if (samplesperpixel == 3)
     807  if (samplesperpixel==3 && bitspersample==8)
    799808    planarConfig = PLANARCONFIG_CONTIG;
    800809
     
    835844  case 16 :
    836845  case 32 :
     846  case 64 :
    837847    if ( (compression != COMPRESSION_LZW) && (compression != COMPRESSION_PACKBITS) )
    838848      compression = COMPRESSION_NONE; 
  • bioView3D/libsrc/libbioimg/formats_api/dim_histogram.cpp

    r103 r112  
    88    10/20/2006 20:21 - First creation
    99    2007-06-26 12:18 - added lut class
    10 
    11   ver: 2
     10    2010-01-22 17:06 - changed interface to support floating point data
     11
     12  ver: 3
    1213       
    1314*******************************************************************************/
     
    1718
    1819#include "cmath"
     20
     21#include <limits>
    1922
    2023//******************************************************************************
     
    2225//******************************************************************************
    2326
    24 DimHistogram::DimHistogram( int bpp ) {
    25   init( bpp );
    26 }
    27 
    28 DimHistogram::DimHistogram( int bpp, void *data, unsigned int num_data_points ) {
    29   init( bpp );
     27DimHistogram::DimHistogram( const unsigned int &bpp, const D_DataFormat &fmt ) {
     28  default_size = DimHistogram::defaultSize;
     29  init( bpp, fmt );
     30}
     31
     32DimHistogram::DimHistogram( const unsigned int &bpp, void *data, const unsigned int &num_data_points, const D_DataFormat &fmt ) {
     33  default_size = DimHistogram::defaultSize;
     34  init( bpp, fmt );
    3035  addData( data, num_data_points );
    3136}
     
    3540}
    3641
    37 void DimHistogram::init( int bpp ) {
     42void DimHistogram::init( const unsigned int &bpp, const D_DataFormat &fmt ) {
    3843  data_bpp = bpp;
    39   if (bpp == 0)
    40     hist.resize( 0 ); 
    41   else
     44  data_fmt = fmt;
     45
     46  shift=0; scale=1;
     47  value_min=0; value_max=0;
     48  reversed_min_max = false;
     49  hist.resize(0);
     50
     51  if (bpp==0) return;
     52  else
     53  if ( bpp<=16 && (data_fmt==D_FMT_UNSIGNED || data_fmt==D_FMT_SIGNED) ) {
    4254    hist.resize( (unsigned int) pow(2.0, fabs((double) bpp)), 0 );
     55  } else
     56  if (bpp>16 || data_fmt==D_FMT_FLOAT) {
     57    hist.resize( default_size );
     58  }
     59  initStats();
    4360}
    4461
     
    4764}
    4865
    49 void DimHistogram::newData( int bpp, void *data, unsigned int num_data_points ) {
    50   init( bpp );
     66void DimHistogram::newData( const unsigned int &bpp, void *data, const unsigned int &num_data_points, const D_DataFormat &fmt ) {
     67  init( bpp, fmt );
    5168  clear( );
     69  getStats( data, num_data_points );
    5270  addData( data, num_data_points );
    5371}
    5472
     73template <typename T>
     74void DimHistogram::init_stats() {
     75  value_min = std::numeric_limits<T>::min();
     76  value_max = std::numeric_limits<T>::max();
     77  reversed_min_max = false;
     78  recompute_shift_scale();
     79}
     80
     81void DimHistogram::initStats() {
     82  if (data_bpp==8  && data_fmt==D_FMT_UNSIGNED) init_stats<DIM_UINT8>();
     83  else
     84  if (data_bpp==16 && data_fmt==D_FMT_UNSIGNED) init_stats<DIM_UINT16>();
     85  else   
     86  if (data_bpp==32 && data_fmt==D_FMT_UNSIGNED) init_stats<DIM_UINT32>();
     87  else
     88  if (data_bpp==8  && data_fmt==D_FMT_SIGNED)   init_stats<DIM_INT8>();
     89  else
     90  if (data_bpp==16 && data_fmt==D_FMT_SIGNED)   init_stats<DIM_INT16>();
     91  else
     92  if (data_bpp==32 && data_fmt==D_FMT_SIGNED)   init_stats<DIM_INT32>();
     93  else
     94  if (data_bpp==32 && data_fmt==D_FMT_FLOAT)    init_stats<DIM_FLOAT32>();
     95  else
     96  if (data_bpp==64 && data_fmt==D_FMT_FLOAT)    init_stats<DIM_FLOAT64>();
     97  else
     98  if (data_bpp==80 && data_fmt==D_FMT_FLOAT)    init_stats<DIM_FLOAT80>();
     99}
     100
     101inline void DimHistogram::recompute_shift_scale() {
     102  shift = value_min;
     103  scale = ((double) bin_number()-1) / (value_max-value_min);
     104}
     105
    55106template <typename T>
    56 void DimHistogram::add_from_data( T *data, unsigned int num_data_points ) {
     107void DimHistogram::update_data_stats( T *data, const unsigned int &num_data_points ) {
     108  if (!data) return;
     109  if (num_data_points==0) return;
     110  if (!reversed_min_max) {
     111    value_min = std::numeric_limits<T>::max();
     112    value_max = std::numeric_limits<T>::min();
     113    reversed_min_max = true;
     114  }
     115
     116  T *p = (T *) data; 
     117  for (unsigned int i=0; i<num_data_points; ++i) {
     118    if (*p<value_min) value_min = *p;
     119    if (*p>value_max) value_max = *p;
     120    ++p;
     121  }
     122 
     123  recompute_shift_scale();
     124}
     125
     126template <typename T>
     127void DimHistogram::get_data_stats( T *data, const unsigned int &num_data_points ) {
     128  init_stats<T>();
     129  value_min = std::numeric_limits<T>::max();
     130  value_max = std::numeric_limits<T>::min();
     131  reversed_min_max = true;
     132  update_data_stats(data, num_data_points);
     133}
     134
     135void DimHistogram::getStats( void *data, const unsigned int &num_data_points ) {
     136  if (data_fmt==D_FMT_UNSIGNED) {
     137    if (data_bpp == 32) get_data_stats<DIM_UINT32>( (DIM_UINT32*)data, num_data_points );
     138  } else
     139  if (data_fmt==D_FMT_SIGNED) {
     140    if (data_bpp == 32) get_data_stats<DIM_INT32>( (DIM_INT32*)data, num_data_points );
     141  } else
     142  if (data_fmt==D_FMT_FLOAT) {
     143    if (data_bpp == 32) get_data_stats<DIM_FLOAT32>( (DIM_FLOAT32*)data, num_data_points );
     144    else
     145    if (data_bpp == 64) get_data_stats<DIM_FLOAT64>( (DIM_FLOAT64*)data, num_data_points );
     146    else
     147    if (data_bpp == 80) get_data_stats<DIM_FLOAT80>( (DIM_FLOAT80*)data, num_data_points );
     148  }
     149}
     150
     151template <typename T>
     152inline unsigned int DimHistogram::bin_from( const T &data_point ) const {
     153  return dim::trim<unsigned int, double>( (data_point - shift) * scale, 0, bin_number() );
     154}
     155
     156template <typename T>
     157void DimHistogram::add_from_data( T *data, const unsigned int &num_data_points ) {
    57158  if (!data) return;
    58159  if (num_data_points==0) return;
     
    65166}
    66167
    67 void DimHistogram::addData( void *data, unsigned int num_data_points ) {
    68 
    69   if (data_bpp == 8)
    70     add_from_data<unsigned char>( (unsigned char*)data, num_data_points );
    71 
    72   if (data_bpp == -8)
    73     add_from_data<char>( (char*)data, num_data_points );
    74 
    75   if (data_bpp == 16)
    76     add_from_data<unsigned short>( (unsigned short*)data, num_data_points );
    77 
    78   if (data_bpp == -16)
    79     add_from_data<short>( (short*)data, num_data_points );
    80 }
    81 
    82 int DimHistogram::last_pos() const {
     168template <typename T>
     169void DimHistogram::add_from_data_scale( T *data, const unsigned int &num_data_points ) {
     170  if (!data) return;
     171  if (num_data_points==0) return;
     172  //get_data_stats( data, num_data_points );
     173
     174  T *p = (T *) data;
     175  unsigned int bn = bin_number();
     176  for (unsigned int i=0; i<num_data_points; ++i) {
     177    double v = (((double)*p) - shift) * scale;
     178    unsigned int bin = dim::trim<unsigned int, double>( v, 0, bn-1 );
     179    ++hist[bin];
     180    ++p;
     181  }
     182}
     183
     184void DimHistogram::updateStats( void *data, const unsigned int &num_data_points ) {
     185  if (data_fmt==D_FMT_UNSIGNED) {
     186    if (data_bpp == 32) update_data_stats<DIM_UINT32>( (DIM_UINT32*)data, num_data_points );
     187  } else
     188  if (data_fmt==D_FMT_SIGNED) {
     189    if (data_bpp == 32) update_data_stats<DIM_INT32>( (DIM_INT32*)data, num_data_points );
     190  } else
     191  if (data_fmt==D_FMT_FLOAT) {
     192    if (data_bpp == 32) update_data_stats<DIM_FLOAT32>( (DIM_FLOAT32*)data, num_data_points );
     193    else
     194    if (data_bpp == 64) update_data_stats<DIM_FLOAT64>( (DIM_FLOAT64*)data, num_data_points );
     195    else
     196    if (data_bpp == 80) update_data_stats<DIM_FLOAT80>( (DIM_FLOAT80*)data, num_data_points );
     197  }
     198}
     199
     200void DimHistogram::addData( void *data, const unsigned int &num_data_points ) {
     201
     202  if (data_fmt==D_FMT_UNSIGNED) {
     203    if (data_bpp==8)    add_from_data<DIM_UINT8>( (DIM_UINT8*)data, num_data_points );
     204    else
     205    if (data_bpp == 16) add_from_data<DIM_UINT16>( (DIM_UINT16*)data, num_data_points );
     206    else
     207    if (data_bpp == 32) add_from_data_scale<DIM_UINT32>( (DIM_UINT32*)data, num_data_points );
     208  } else
     209  if (data_fmt==D_FMT_SIGNED) {
     210    if (data_bpp==8)    add_from_data_scale<DIM_INT8>( (DIM_INT8*)data, num_data_points );
     211    else
     212    if (data_bpp == 16) add_from_data_scale<DIM_INT16>( (DIM_INT16*)data, num_data_points );
     213    else
     214    if (data_bpp == 32) add_from_data_scale<DIM_INT32>( (DIM_INT32*)data, num_data_points );
     215  } else
     216  if (data_fmt==D_FMT_FLOAT) {
     217    if (data_bpp == 32) add_from_data_scale<DIM_FLOAT32>( (DIM_FLOAT32*)data, num_data_points );
     218    else
     219    if (data_bpp == 64) add_from_data_scale<DIM_FLOAT64>( (DIM_FLOAT64*)data, num_data_points );
     220    else
     221    if (data_bpp == 80) add_from_data_scale<DIM_FLOAT80>( (DIM_FLOAT80*)data, num_data_points );
     222  }
     223}
     224
     225
     226
     227int DimHistogram::bin_of_last_nonzero() const {
    83228  for (int i=hist.size()-1; i>=0; --i)
    84229    if (hist[i] != 0)
     
    87232}
    88233
    89 int DimHistogram::first_pos() const {
     234int DimHistogram::bin_of_first_nonzero() const {
    90235  for (unsigned int i=0; i<hist.size(); ++i)
    91236    if (hist[i] != 0)
     
    94239}
    95240
    96 int DimHistogram::max_pos() const {
    97   int pos = 0;
     241int DimHistogram::bin_of_max_value() const {
     242  int bin = 0;
    98243  unsigned int val = hist[0];
    99244  for (unsigned int i=0; i<hist.size(); ++i)
    100245    if (hist[i] > val) {
    101246      val = hist[i];
    102       pos = i;
     247      bin = i;
    103248    }
    104   return pos;
    105 }
    106 
    107 int DimHistogram::min_pos() const {
    108   int pos = 0;
     249  return bin;
     250}
     251
     252int DimHistogram::bin_of_min_value() const {
     253  int bin = 0;
    109254  unsigned int val = hist[0];
    110255  for (unsigned int i=0; i<hist.size(); ++i)
    111256    if (hist[i] < val) {
    112257      val = hist[i];
    113       pos = i;
     258      bin = i;
    114259    }
    115   return pos;
    116 }
    117 
    118 int DimHistogram::num_unique() const {
     260  return bin;
     261}
     262
     263double DimHistogram::max_value() const {
     264  if (data_fmt==D_FMT_UNSIGNED && data_bpp<=16)
     265    return bin_of_max_value();
     266  else
     267    return value_max;
     268}
     269
     270double DimHistogram::min_value() const {
     271  if (data_fmt==D_FMT_UNSIGNED && data_bpp<=16)
     272    return bin_of_min_value();
     273  else
     274    return value_min;
     275}
     276
     277int DimHistogram::bin_number_nonzero() const {
    119278  int unique = 0;
    120279  for (unsigned int i=0; i<hist.size(); ++i)
     
    133292}
    134293
    135 unsigned int DimHistogram::cumsum( unsigned int pos ) const {
    136   if ( pos >= hist.size() ) pos = hist.size()-1;
     294unsigned int DimHistogram::cumsum( const unsigned int &bin ) const {
     295  unsigned int b = bin;
     296  if ( b >= hist.size() ) b = hist.size()-1;
    137297  unsigned int sum=0;
    138   for (unsigned int i=0; i<=pos; ++i)
     298  for (unsigned int i=0; i<=b; ++i)
    139299    sum += hist[i];
    140300  return sum;
    141301}
    142302
    143 unsigned int DimHistogram::get_value( unsigned int pos ) const {
    144   if ( pos < hist.size() )
    145     return hist[pos];
     303unsigned int DimHistogram::get_value( const unsigned int &bin ) const {
     304  if ( bin < hist.size() )
     305    return hist[bin];
    146306  else
    147307    return 0;
    148308}
    149309
    150 void DimHistogram::set_value( unsigned int pos, unsigned int val ) {
    151   if ( pos < hist.size() )
    152     hist[pos] = val;
    153 }
    154 
    155 void DimHistogram::append_value( unsigned int pos, unsigned int val ) {
    156   if ( pos < hist.size() )
    157     hist[pos] += val;
     310void DimHistogram::set_value( const unsigned int &bin, const unsigned int &val ) {
     311  if ( bin < hist.size() )
     312    hist[bin] = val;
     313}
     314
     315void DimHistogram::append_value( const unsigned int &bin, const unsigned int &val ) {
     316  if ( bin < hist.size() )
     317    hist[bin] += val;
    158318}
    159319
     
    163323
    164324DimLut::DimLut( ) {
    165   in_depth=0; out_depth=0;
    166325  lut.resize( 0 );
    167326  this->generator = linear_full_range_generator;
     
    172331}
    173332
    174 DimLut::DimLut( const DimHistogram &in, const DimHistogram &out, LutType type ) {
     333DimLut::DimLut( const DimHistogram &in, const DimHistogram &out, const LutType &type ) {
    175334  init( in, out, type );
    176335}
     
    187346  lut.resize( in.size() );
    188347  clear( );
     348  h_in = in;
     349  h_out = out;
    189350  if (generator) generator( in, lut, out.size(), NULL );
    190   in_depth  = (int) fabs((double)in.dataBpp());
    191   out_depth = (int) fabs((double)out.dataBpp());
    192 }
    193 
    194 void DimLut::init( const DimHistogram &in, const DimHistogram &out, LutType type ) {
     351}
     352
     353void DimLut::init( const DimHistogram &in, const DimHistogram &out, const LutType &type ) {
    195354  if (type == ltLinearFullRange)     generator = linear_full_range_generator;
    196355  if (type == ltLinearDataRange)     generator = linear_data_range_generator;
     
    206365
    207366void DimLut::clear( ) {
    208   lut = std::vector<unsigned int>(lut.size(), 0);
     367  lut = std::vector<DimLut::StorageType>(lut.size(), 0);
    209368}
    210369
     
    215374template void DimLut::set_lut<unsigned char>( const std::vector<unsigned char> &new_lut );
    216375template void DimLut::set_lut<unsigned int>( const std::vector<unsigned int> &new_lut );
    217 
    218 unsigned int DimLut::get_value( unsigned int pos ) const {
     376template void DimLut::set_lut<double>( const std::vector<double> &new_lut );
     377
     378DimLut::StorageType DimLut::get_value( const unsigned int &pos ) const {
    219379  if ( pos < lut.size() )
    220380    return lut[pos];
     
    223383}
    224384
    225 void DimLut::set_value( unsigned int pos, unsigned int val ) {
     385void DimLut::set_value( const unsigned int &pos, const DimLut::StorageType &val ) {
    226386  if ( pos < lut.size() )
    227387    lut[pos] = val;
     
    229389
    230390template <typename Ti, typename To>
    231 void DimLut::apply_lut( const Ti *ibuf, To *obuf, unsigned int num_data_points ) const {
     391void DimLut::apply_lut( const Ti *ibuf, To *obuf, const unsigned int &num_data_points ) const {
    232392  if (!ibuf || !obuf) return;
    233393
     
    236396}
    237397
    238 void DimLut::apply( void *ibuf, const void *obuf, unsigned int num_data_points ) const {
     398template <typename Ti, typename To>
     399void DimLut::apply_lut_scale_from( const Ti *ibuf, To *obuf, const unsigned int &num_data_points ) const {
     400  if (!ibuf || !obuf) return;
     401  double scale = h_in.scale;
     402  double shift = h_in.shift;
     403  double range = lut.size();
     404
     405  for (unsigned int i=0; i<num_data_points; ++i)
     406    obuf[i] = (To) lut[ dim::trim<unsigned int, double>( ((double)ibuf[i]-shift)*scale, 0, range-1) ];
     407}
     408
     409//------------------------------------------------------------------------------------
     410// ok, follows crazy code bloat of instantiations, will change this eventually
     411//------------------------------------------------------------------------------------
     412
     413// this guy instantiates real method based on input template
     414template <typename Ti>
     415inline void DimLut::do_apply_lut( const Ti *ibuf, const void *obuf, const unsigned int &num_data_points ) const {
     416 
     417  if (h_out.dataBpp()==8 && h_out.dataFormat()!=D_FMT_FLOAT )
     418    apply_lut<Ti, DIM_UINT8>( ibuf, (DIM_UINT8*) obuf, num_data_points );
     419  else
     420  if (h_out.dataBpp()==16 && h_out.dataFormat()!=D_FMT_FLOAT )
     421    apply_lut<Ti, DIM_UINT16>( ibuf, (DIM_UINT16*) obuf, num_data_points );
     422  else
     423  if (h_out.dataBpp()==32 && h_out.dataFormat()!=D_FMT_FLOAT )
     424    apply_lut<Ti, DIM_UINT32>( ibuf, (DIM_UINT32*) obuf, num_data_points );
     425  else
     426  if (h_out.dataBpp()==32 && h_out.dataFormat()==D_FMT_FLOAT )
     427    apply_lut<Ti, DIM_FLOAT32>( ibuf, (DIM_FLOAT32*) obuf, num_data_points );
     428  else
     429  if (h_out.dataBpp()==64 && h_out.dataFormat()==D_FMT_FLOAT )
     430    apply_lut<Ti, DIM_FLOAT64>( ibuf, (DIM_FLOAT64*) obuf, num_data_points );
     431}
     432
     433// this guy instantiates real method based on input template
     434template <typename Ti>
     435inline void DimLut::do_apply_lut_scale_from( const Ti *ibuf, const void *obuf, const unsigned int &num_data_points ) const {
     436  if (h_out.dataBpp()==8 && h_out.dataFormat()!=D_FMT_FLOAT )
     437    apply_lut_scale_from<Ti, DIM_UINT8>( ibuf, (DIM_UINT8*) obuf, num_data_points );
     438  else
     439  if (h_out.dataBpp()==16 && h_out.dataFormat()!=D_FMT_FLOAT )
     440    apply_lut_scale_from<Ti, DIM_UINT16>( ibuf, (DIM_UINT16*) obuf, num_data_points );
     441  else
     442  if (h_out.dataBpp()==32 && h_out.dataFormat()!=D_FMT_FLOAT )
     443    apply_lut_scale_from<Ti, DIM_UINT32>( ibuf, (DIM_UINT32*) obuf, num_data_points );
     444  else
     445  if (h_out.dataBpp()==32 && h_out.dataFormat()==D_FMT_FLOAT )
     446    apply_lut_scale_from<Ti, DIM_FLOAT32>( ibuf, (DIM_FLOAT32*) obuf, num_data_points );
     447  else
     448  if (h_out.dataBpp()==64 && h_out.dataFormat()==D_FMT_FLOAT )
     449    apply_lut_scale_from<Ti, DIM_FLOAT64>( ibuf, (DIM_FLOAT64*) obuf, num_data_points );
     450}
     451
     452void DimLut::apply( void *ibuf, const void *obuf, const unsigned int &num_data_points ) const {
    239453  if (lut.size() <= 0) return;
    240454
    241   if (in_depth == 8 && out_depth == 8)
    242     apply_lut<unsigned char, unsigned char>( (unsigned char*) ibuf, (unsigned char*) obuf, num_data_points );
    243 
    244   if (in_depth == 16 && out_depth == 8)
    245     apply_lut<unsigned short, unsigned char>( (unsigned short*) ibuf, (unsigned char*) obuf, num_data_points );
    246 
    247   if (in_depth == 8 && out_depth == 16)
    248     apply_lut<unsigned char, unsigned short>( (unsigned char*) ibuf, (unsigned short*) obuf, num_data_points );
    249 
    250   if (in_depth == 16 && out_depth == 16)
    251     apply_lut<unsigned short, unsigned short>( (unsigned short*) ibuf, (unsigned short*) obuf, num_data_points );
    252 
     455  // uint
     456  if (h_in.dataBpp()==8 && h_in.dataFormat()==D_FMT_UNSIGNED)
     457    do_apply_lut<DIM_UINT8>( (DIM_UINT8*) ibuf, obuf, num_data_points );
     458  else
     459  if (h_in.dataBpp()==16 && h_in.dataFormat()==D_FMT_UNSIGNED)
     460    do_apply_lut<DIM_UINT16>( (DIM_UINT16*) ibuf, obuf, num_data_points );
     461  else
     462  if (h_in.dataBpp()==32 && h_in.dataFormat()==D_FMT_UNSIGNED)
     463    do_apply_lut_scale_from<DIM_UINT32>( (DIM_UINT32*) ibuf, obuf, num_data_points );
     464  else
     465  // int
     466  if (h_in.dataBpp()==8 && h_in.dataFormat()==D_FMT_SIGNED)
     467    do_apply_lut_scale_from<DIM_INT8>( (DIM_INT8*) ibuf, obuf, num_data_points );
     468  else
     469  if (h_in.dataBpp()==16 && h_in.dataFormat()==D_FMT_SIGNED)
     470    do_apply_lut_scale_from<DIM_INT16>( (DIM_INT16*) ibuf, obuf, num_data_points );
     471  else
     472  if (h_in.dataBpp()==32 && h_in.dataFormat()==D_FMT_SIGNED)
     473    do_apply_lut_scale_from<DIM_INT32>( (DIM_INT32*) ibuf, obuf, num_data_points );
     474  else
     475  // float: current implementation would provide poor quality for float2float because of the LUT binning size
     476  // should look into doing this by applying generator function for each element of the data ignoring LUT at all...
     477  if (h_in.dataBpp()==32 && h_in.dataFormat()==D_FMT_FLOAT)
     478    do_apply_lut_scale_from<DIM_FLOAT32>( (DIM_FLOAT32*) ibuf, obuf, num_data_points );
     479  else
     480  if (h_in.dataBpp()==64 && h_in.dataFormat()==D_FMT_FLOAT)
     481    do_apply_lut_scale_from<DIM_FLOAT64>( (DIM_FLOAT64*) ibuf, obuf, num_data_points );
    253482}
    254483
     
    279508template void linear_range_generator<unsigned char>( int b, int e, unsigned int out_phys_range, std::vector<unsigned char> &lut );
    280509template void linear_range_generator<unsigned int>( int b, int e, unsigned int out_phys_range, std::vector<unsigned int> &lut );
     510template void linear_range_generator<double>( int b, int e, unsigned int out_phys_range, std::vector<double> &lut );
    281511//------------------------
    282512
     
    290520template void linear_full_range_generator<unsigned char>( const DimHistogram &in, std::vector<unsigned char> &lut, unsigned int out_phys_range, void *args );
    291521template void linear_full_range_generator<unsigned int>( const DimHistogram &in, std::vector<unsigned int> &lut, unsigned int out_phys_range, void *args );
    292 
     522template void linear_full_range_generator<double>( const DimHistogram &in, std::vector<double> &lut, unsigned int out_phys_range, void *args );
    293523
    294524template <typename Tl>
     
    304534template void linear_data_range_generator<unsigned char>( const DimHistogram &in, std::vector<unsigned char> &lut, unsigned int out_phys_range, void *args );
    305535template void linear_data_range_generator<unsigned int>( const DimHistogram &in, std::vector<unsigned int> &lut, unsigned int out_phys_range, void *args );
     536template void linear_data_range_generator<double>( const DimHistogram &in, std::vector<double> &lut, unsigned int out_phys_range, void *args );
    306537
    307538template <typename Tl>
     
    310541  // simple linear mapping cutting elements with small appearence
    311542  // get 1% threshold
    312   unsigned int th = (unsigned int) ( in[ in.max_pos() ] * 1.0 / 100.0 );
     543  unsigned int th = (unsigned int) ( in[ in.bin_of_max_value() ] * 1.0 / 100.0 );
    313544  int b = 0;
    314545  int e = in.size()-1;
     
    331562template void linear_data_tolerance_generator<unsigned char>( const DimHistogram &in, std::vector<unsigned char> &lut, unsigned int out_phys_range, void *args );
    332563template void linear_data_tolerance_generator<unsigned int>( const DimHistogram &in, std::vector<unsigned int> &lut, unsigned int out_phys_range, void *args );
     564template void linear_data_tolerance_generator<double>( const DimHistogram &in, std::vector<double> &lut, unsigned int out_phys_range, void *args );
    333565
    334566template <typename Tl>
     
    348580template void equalized_generator<unsigned char>( const DimHistogram &in, std::vector<unsigned char> &lut, unsigned int out_phys_range, void *args );
    349581template void equalized_generator<unsigned int>( const DimHistogram &in, std::vector<unsigned int> &lut, unsigned int out_phys_range, void *args );
     582template void equalized_generator<double>( const DimHistogram &in, std::vector<double> &lut, unsigned int out_phys_range, void *args );
    350583
    351584template <typename Tl>
     
    362595template void linear_custom_range_generator<unsigned char>( const DimHistogram &in, std::vector<unsigned char> &lut, unsigned int out_phys_range, void *args );
    363596template void linear_custom_range_generator<unsigned int>( const DimHistogram &in, std::vector<unsigned int> &lut, unsigned int out_phys_range, void *args );
    364 
     597template void linear_custom_range_generator<double>( const DimHistogram &in, std::vector<double> &lut, unsigned int out_phys_range, void *args );
  • bioView3D/libsrc/libbioimg/formats_api/dim_histogram.h

    r103 r112  
    88    10/20/2006 20:21 - First creation
    99    2007-06-26 12:18 - added lut class
    10 
    11   ver: 2
     10    2010-01-22 17:06 - changed interface to support floating point data
     11
     12  ver: 3
    1213       
    1314*******************************************************************************/
     
    1819#include <vector>
    1920
     21#include "dim_img_format_interface.h"
     22
    2023//******************************************************************************
    2124// DimHistogram
    2225//******************************************************************************
     26
     27class DimLut;
    2328
    2429class DimHistogram {
    2530  public:
    26     DimHistogram( int bpp=0 );
    27     DimHistogram( int bpp, void *data, unsigned int num_data_points );
     31    static const unsigned int defaultSize=256;
     32
     33    DimHistogram( const unsigned int &bpp=0, const D_DataFormat &fmt=D_FMT_UNSIGNED );
     34    DimHistogram( const unsigned int &bpp, void *data, const unsigned int &num_data_points, const D_DataFormat &fmt=D_FMT_UNSIGNED );
    2835    ~DimHistogram();
    2936
    30     void init( int bpp );  // negative bpp is used for signed data
    31     void clear( );
    32     void addData( void *data, unsigned int num_data_points );
    33     void newData( int bpp, void *data, unsigned int num_data_points );
    34     int dataBpp() const { return data_bpp; }
    35 
    36     int first_pos() const;
    37     int last_pos() const;
    38     int max_pos() const;
    39     int min_pos() const;
    40     int num_unique() const;
     37    void newData( const unsigned int &bpp, void *data, const unsigned int &num_data_points, const D_DataFormat &fmt=D_FMT_UNSIGNED );
     38    void clear();
     39
     40    void init( const unsigned int &bpp, const D_DataFormat &fmt=D_FMT_UNSIGNED );
     41    void updateStats( void *data, const unsigned int &num_data_points );
     42    // careful with this function operating on data with 32 bits and above, stats should be properly updated for all data chunks if vary
     43    // use the updateStats method on each data chunk prior to calling addData on >=32bit data
     44    void addData( void *data, const unsigned int &num_data_points );
     45
     46    unsigned int getDefaultSize() const { return default_size; }
     47    void         setDefaultSize(const unsigned int &v) { default_size=v; }
     48
     49    unsigned int dataBpp()    const { return data_bpp; }
     50    D_DataFormat dataFormat() const { return data_fmt; }
     51
     52    int bin_of_max_value() const;
     53    int bin_of_min_value() const;
     54    double max_value() const;
     55    double min_value() const;
     56
     57    int bin_of_first_nonzero() const;
     58    int bin_of_last_nonzero()  const;
     59    int bin_number_nonzero()   const;
     60    int first_pos()  const { return bin_of_first_nonzero(); }
     61    int last_pos()   const { return bin_of_last_nonzero(); }
     62    int num_unique() const { return bin_number_nonzero(); }
     63
     64    inline unsigned int bin_number() const { return size(); }
     65    inline unsigned int size() const { return hist.size(); }
     66    const std::vector<unsigned int> &get_hist( ) const { return hist; }
     67
    4168    double average() const;
    42     unsigned int size() const { return hist.size(); }
    43     const std::vector<unsigned int> &get_hist( ) const { return hist; }
    44 
    45     unsigned int cumsum( unsigned int pos ) const;
    46     unsigned int get_value( unsigned int pos ) const;
    47     void set_value( unsigned int pos, unsigned int val );
    48     void append_value( unsigned int pos, unsigned int val );
     69    unsigned int cumsum( const unsigned int &bin ) const;
     70
     71    unsigned int get_value( const unsigned int &bin ) const;
     72    void set_value( const unsigned int &bin, const unsigned int &val );
     73    void append_value( const unsigned int &bin, const unsigned int &val );
     74
    4975    inline unsigned int operator[](unsigned int x) const { return hist[x]; }
     76
     77    template <typename T>
     78    inline unsigned int bin_from( const T &data_point ) const;
    5079   
    5180  protected:
    52     // 8 = uchar, 16 = ushort, -8 = char, -16 = short and so on
    53     int data_bpp;
     81    unsigned int data_bpp;
     82    D_DataFormat data_fmt; // signed, unsigned, float
     83    int default_size;
     84    double shift, scale;
     85    double value_min, value_max;
     86    bool reversed_min_max;
    5487    std::vector<unsigned int> hist;
    5588
    56     template <typename T>
    57     void add_from_data( T *data, unsigned int num_data_points );
     89    template <typename T>
     90    void init_stats();
     91
     92    void initStats();
     93    void getStats( void *data, const unsigned int &num_data_points );
     94
     95    inline void recompute_shift_scale();
     96
     97    template <typename T>
     98    void get_data_stats( T *data, const unsigned int &num_data_points );
     99
     100    template <typename T>
     101    void update_data_stats( T *data, const unsigned int &num_data_points );
     102
     103    template <typename T>
     104    void add_from_data( T *data, const unsigned int &num_data_points );
     105   
     106    template <typename T>
     107    void add_from_data_scale( T *data, const unsigned int &num_data_points );
     108
     109    friend class DimLut;
    58110
    59111};
     
    73125    };
    74126
    75     typedef void (*DimLutGenerator)( const DimHistogram &in, std::vector<unsigned int> &lut, unsigned int out_phys_range, void *args );
     127    typedef double StorageType;
     128    typedef void (*DimLutGenerator)( const DimHistogram &in, std::vector<StorageType> &lut, unsigned int out_phys_range, void *args );
    76129
    77130    DimLut( );
    78131    DimLut( const DimHistogram &in, const DimHistogram &out );
    79     DimLut( const DimHistogram &in, const DimHistogram &out, LutType type );
     132    DimLut( const DimHistogram &in, const DimHistogram &out, const LutType &type );
    80133    DimLut( const DimHistogram &in, const DimHistogram &out, DimLutGenerator custom_generator );
    81134    ~DimLut();
    82135
    83     // negative bpp is used for signed data, not implemented yet...
    84136    void init( const DimHistogram &in, const DimHistogram &out );
    85     void init( const DimHistogram &in, const DimHistogram &out, LutType type );
     137    void init( const DimHistogram &in, const DimHistogram &out, const LutType &type );
    86138    void init( const DimHistogram &in, const DimHistogram &out, DimLutGenerator custom_generator );
    87139    void clear( );
    88140
    89141    unsigned int size() const { return lut.size(); }
    90     const std::vector<unsigned int> &get_lut( ) const { return lut; }
    91 
    92     int depthInput()  const { return in_depth; }
    93     int depthOutput() const { return out_depth; }
     142    const std::vector<StorageType> &get_lut( ) const { return lut; }
     143
     144    int depthInput()  const { return h_in.dataBpp(); }
     145    int depthOutput() const { return h_out.dataBpp(); }
     146    D_DataFormat dataFormatInput()  const { return h_in.dataFormat(); }
     147    D_DataFormat dataFormatOutput() const { return h_out.dataFormat(); }
    94148
    95149    template <typename Tl>
    96150    void         set_lut( const std::vector<Tl> & );
    97151   
    98     unsigned int get_value( unsigned int pos ) const;
    99     void         set_value( unsigned int pos, unsigned int val );
    100     inline unsigned int operator[](unsigned int x) const { return lut[x]; }
    101 
    102     void apply( void *ibuf, const void *obuf, unsigned int num_data_points ) const;
     152    StorageType   get_value( const unsigned int &pos ) const;
     153    void         set_value( const unsigned int &pos, const StorageType &val );
     154    inline StorageType operator[](unsigned int x) const { return lut[x]; }
     155
     156    void apply( void *ibuf, const void *obuf, const unsigned int &num_data_points ) const;
    103157    // generates values of output histogram, given the current lut and in histogram
    104158    void apply( const DimHistogram &in, DimHistogram &out ) const;
    105159
    106160  protected:
    107     std::vector<unsigned int> lut;
     161    std::vector<StorageType> lut;
    108162    DimLutGenerator generator;
    109     int in_depth, out_depth;
     163    DimHistogram h_in, h_out;
    110164    void *internal_arguments;
    111165
    112166    template <typename Ti, typename To>
    113     void apply_lut( const Ti *ibuf, To *obuf, unsigned int num_data_points ) const;
     167    void apply_lut( const Ti *ibuf, To *obuf, const unsigned int &num_data_points ) const;
     168
     169    template <typename Ti, typename To>
     170    void apply_lut_scale_from( const Ti *ibuf, To *obuf, const unsigned int &num_data_points ) const;
     171
     172    template <typename Ti>
     173    inline void do_apply_lut( const Ti *ibuf, const void *obuf, const unsigned int &num_data_points ) const;
     174
     175    template <typename Ti>
     176    inline void do_apply_lut_scale_from( const Ti *ibuf, const void *obuf, const unsigned int &num_data_points ) const;
    114177};
    115178
  • bioView3D/libsrc/libbioimg/formats_api/dim_image.cpp

    r108 r112  
    241241
    242242  int depth = lut.depthOutput();
     243  D_DataFormat pxt = lut.dataFormatOutput();
    243244  DIM_UINT w = bmp->i.width;
    244245  DIM_UINT h = bmp->i.height;
    245246  unsigned int num_pix = w * h;
    246247
    247   if ( img.alloc( w, h, bmp->i.samples, depth ) == 0 )
    248   for (unsigned int sample=0; sample<bmp->i.samples; ++sample ) {
    249     lut[sample]->apply( bmp->bits[sample], img.bits(sample), num_pix );
    250   } // sample
    251 
    252   DIM_DataType pxt = img.bmp->i.pixelType;
    253   img.bmp->i = this->bmp->i;
    254   img.bmp->i.depth = depth;
    255   img.bmp->i.pixelType = pxt;
     248  if ( img.alloc( w, h, bmp->i.samples, depth ) == 0 ) {
     249    img.bmp->i = this->bmp->i;
     250    img.bmp->i.depth = depth;
     251    img.bmp->i.pixelType = pxt;
     252    for (unsigned int sample=0; sample<bmp->i.samples; ++sample ) {
     253      lut[sample]->apply( bmp->bits[sample], img.bits(sample), num_pix );
     254    } // sample
     255  }
     256
    256257  return img;
    257258}
    258259
    259 TDimImage TDimImage::convertToDepth( int depth, DimLut::LutType method ) const {
    260 
     260TDimImage TDimImage::convertToDepth( int depth, DimLut::LutType method, D_DataFormat pxt ) const {
    261261  TDimImage img;
    262262  if (bmp==NULL) return img;
    263   //if (bmp->i.depth == depth) return *this;
    264263
    265264  DIM_UINT w = bmp->i.width;
     
    267266  unsigned int num_pix = w * h;
    268267   
    269   DimHistogram ihist( bmp->i.depth );
    270   DimHistogram ohist( depth );
    271   DimLut       lut;
    272 
    273   if ( img.alloc( w, h, bmp->i.samples, depth ) == 0 )
    274   for (unsigned int sample=0; sample<bmp->i.samples; ++sample ) {
     268  if ( img.alloc( w, h, bmp->i.samples, depth ) == 0 ) {
     269    img.bmp->i = this->bmp->i;
     270    img.bmp->i.depth = depth;
     271    if (pxt!=D_FMT_UNDEFINED) img.bmp->i.pixelType = pxt;
    275272   
    276     ihist.newData( bmp->i.depth, bmp->bits[sample], num_pix );
    277     lut.init( ihist, ohist, method );
    278     lut.apply( bmp->bits[sample], img.bits(sample), num_pix );
    279   } // sample
    280 
    281   DIM_DataType pxt = img.bmp->i.pixelType;
    282   img.bmp->i = this->bmp->i;
    283   img.bmp->i.depth = depth;
    284   img.bmp->i.pixelType = pxt;
     273    DImageHistogram ih(*this);
     274    DImageHistogram oh( img.samples(), img.depth(), img.pixelType() );
     275    DImageLut       lut(ih, oh, method);
     276
     277    for (unsigned int sample=0; sample<bmp->i.samples; ++sample )
     278      lut[sample]->apply( bmp->bits[sample], img.bits(sample), num_pix );
     279  }
     280
    285281  return img;
    286282}
     
    291287  if (bmp->i.depth == to_bpp) return *this;
    292288
    293   return convertToDepth( to_bpp, DimLut::ltLinearDataRange );
     289  return convertToDepth( to_bpp, DimLut::ltLinearDataRange, D_FMT_UNSIGNED );
    294290}
    295291
     
    323319  } // allocated image
    324320
    325   //DIM_DataType pxt = img.bmp->i.pixelType;
    326321  img.bmp->i = this->bmp->i;
    327322  img.bmp->i.width = w;
     
    356351}
    357352
    358 bool TDimImage::toFile( const char *fileName, const char *formatName ) {
    359  
     353bool TDimImage::toFile( const char *fileName, const char *formatName, const char *options ) {
    360354  TMetaFormatManager fm;
    361   fm.writeImage ( fileName, bmp,  formatName);
     355  fm.writeImage ( fileName, bmp,  formatName, options);
    362356  return true;
    363357}
     
    375369
    376370  for (unsigned int sample=0; sample<bmp->i.samples; ++sample ) {
    377     if (bmp->i.depth == 8)
    378       fill_channel<DIM_UCHAR>( (DIM_UCHAR*) bmp->bits[sample], (DIM_UCHAR) v, bmp->i.width*bmp->i.height );
    379 
    380     if (bmp->i.depth == 16)
     371    if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_UNSIGNED)
     372      fill_channel<DIM_UINT8>( (DIM_UINT8*) bmp->bits[sample], (DIM_UINT8) v, bmp->i.width*bmp->i.height );
     373    else
     374    if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_UNSIGNED)
    381375      fill_channel<DIM_UINT16>( (DIM_UINT16*) bmp->bits[sample], (DIM_UINT16) v, bmp->i.width*bmp->i.height );
    382 
    383     if (bmp->i.depth == 32)
     376    else
     377    if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_UNSIGNED)
    384378      fill_channel<DIM_UINT32>( (DIM_UINT32*) bmp->bits[sample], (DIM_UINT32) v, bmp->i.width*bmp->i.height );
     379    else
     380    if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_SIGNED)
     381      fill_channel<DIM_INT8>( (DIM_INT8*) bmp->bits[sample], (DIM_INT8) v, bmp->i.width*bmp->i.height );
     382    else
     383    if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_SIGNED)
     384      fill_channel<DIM_INT16>( (DIM_INT16*) bmp->bits[sample], (DIM_INT16) v, bmp->i.width*bmp->i.height );
     385    else
     386    if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_SIGNED)
     387      fill_channel<DIM_INT32>( (DIM_INT32*) bmp->bits[sample], (DIM_INT32) v, bmp->i.width*bmp->i.height );
     388    else
     389    if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_FLOAT)
     390      fill_channel<DIM_FLOAT32>( (DIM_FLOAT32*) bmp->bits[sample], (DIM_FLOAT32) v, bmp->i.width*bmp->i.height );
     391    else
     392    if (bmp->i.depth==64 && bmp->i.pixelType==D_FMT_FLOAT)
     393      fill_channel<DIM_FLOAT64>( (DIM_FLOAT64*) bmp->bits[sample], (DIM_FLOAT64) v, bmp->i.width*bmp->i.height );
     394
    385395  } // sample
    386396}
    387397
    388398bool TDimImage::isUnTypedDepth() const {
    389   if ( bmp->i.depth == 8) return false;
    390   else
    391   if ( bmp->i.depth == 16) return false;
    392   else
    393   if ( bmp->i.depth == 32) return false;
     399  if ( bmp->i.depth==8) return false;
     400  else
     401  if ( bmp->i.depth==16) return false;
     402  else
     403  if ( bmp->i.depth==32) return false;
     404  else
     405  if ( bmp->i.depth==64) return false;
    394406  else
    395407  return true;
     
    567579      y2 += 2;
    568580
    569       if (bmp->i.depth == 8)
    570         downsample_line<DIM_UCHAR> ( dest, src1, src2, w );
    571 
    572       if (bmp->i.depth == 16)
     581      if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_UNSIGNED)
     582        downsample_line<DIM_UINT8> ( dest, src1, src2, w );
     583      else
     584      if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_UNSIGNED)
    573585        downsample_line<DIM_UINT16> ( dest, src1, src2, w );
    574      
    575       if (bmp->i.depth == 32)
     586      else
     587      if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_UNSIGNED)
    576588        downsample_line<DIM_UINT32> ( dest, src1, src2, w );
     589      else
     590      if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_SIGNED)
     591        downsample_line<DIM_INT8> ( dest, src1, src2, w );
     592      else
     593      if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_SIGNED)
     594        downsample_line<DIM_INT16> ( dest, src1, src2, w );
     595      else
     596      if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_SIGNED)
     597        downsample_line<DIM_INT32> ( dest, src1, src2, w );
     598      else
     599      if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_FLOAT)
     600        downsample_line<DIM_FLOAT32> ( dest, src1, src2, w );
     601      else
     602      if (bmp->i.depth==64 && bmp->i.pixelType==D_FMT_FLOAT)
     603        downsample_line<DIM_FLOAT64> ( dest, src1, src2, w );
    577604    }
    578605
     
    598625}
    599626
    600 template <typename T>
     627template <typename T, typename Tw>
    601628void image_resample ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
    602629                      const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in, TDimImage::ResizeMethod method ) {
    603630
    604631  if (method == TDimImage::szNearestNeighbor)
    605     image_resample_NN<T>( pdest, w_to, h_to, offset_to, psrc, w_in, h_in, offset_in );
     632    image_resample_NN<T, Tw>( pdest, w_to, h_to, offset_to, psrc, w_in, h_in, offset_in );
    606633
    607634  if (method == TDimImage::szBiLinear)
    608     image_resample_BL<T>( pdest, w_to, h_to, offset_to, psrc, w_in, h_in, offset_in );
     635    image_resample_BL<T, Tw>( pdest, w_to, h_to, offset_to, psrc, w_in, h_in, offset_in );
    609636
    610637  if (method == TDimImage::szBiCubic)
    611     image_resample_BC<T>( pdest, w_to, h_to, offset_to, psrc, w_in, h_in, offset_in );
     638    image_resample_BC<T, Tw>( pdest, w_to, h_to, offset_to, psrc, w_in, h_in, offset_in );
    612639
    613640}
     
    631658  for (unsigned int sample=0; sample<bmp->i.samples; ++sample ) {
    632659
    633     if (bmp->i.depth==8)
    634       image_resample<DIM_UCHAR>( (DIM_UCHAR*) img.bits(sample), img.width(), img.height(),img.width(),
     660    if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_UNSIGNED)
     661      image_resample<DIM_UCHAR, float>( (DIM_UCHAR*) img.bits(sample), img.width(), img.height(),img.width(),
    635662                                 (DIM_UCHAR*) bmp->bits[sample], bmp->i.width, bmp->i.height, bmp->i.width, method );
    636 
    637     if (bmp->i.depth==16)
    638       image_resample<DIM_UINT16>( (DIM_UINT16*) img.bits(sample), img.width(), img.height(),img.width(),
     663    else
     664    if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_UNSIGNED)
     665      image_resample<DIM_UINT16, float>( (DIM_UINT16*) img.bits(sample), img.width(), img.height(),img.width(),
    639666                                  (DIM_UINT16*) bmp->bits[sample], bmp->i.width, bmp->i.height, bmp->i.width, method );
    640 
    641     if (bmp->i.depth==32)
    642       image_resample<DIM_UINT32>( (DIM_UINT32*) img.bits(sample), img.width(), img.height(),img.width(),
     667    else
     668    if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_UNSIGNED)
     669      image_resample<DIM_UINT32, double>( (DIM_UINT32*) img.bits(sample), img.width(), img.height(),img.width(),
    643670                                  (DIM_UINT32*) bmp->bits[sample], bmp->i.width, bmp->i.height, bmp->i.width, method );
     671    else
     672    if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_SIGNED)
     673      image_resample<DIM_INT8, float>( (DIM_INT8*) img.bits(sample), img.width(), img.height(),img.width(),
     674                                 (DIM_INT8*) bmp->bits[sample], bmp->i.width, bmp->i.height, bmp->i.width, method );
     675    else
     676    if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_SIGNED)
     677      image_resample<DIM_INT16, float>( (DIM_INT16*) img.bits(sample), img.width(), img.height(),img.width(),
     678                                  (DIM_INT16*) bmp->bits[sample], bmp->i.width, bmp->i.height, bmp->i.width, method );
     679    else
     680    if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_SIGNED)
     681      image_resample<DIM_INT32, double>( (DIM_INT32*) img.bits(sample), img.width(), img.height(),img.width(),
     682                                  (DIM_INT32*) bmp->bits[sample], bmp->i.width, bmp->i.height, bmp->i.width, method );
     683    else
     684    if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_FLOAT)
     685      image_resample<DIM_FLOAT32, double>( (DIM_FLOAT32*) img.bits(sample), img.width(), img.height(),img.width(),
     686                                   (DIM_FLOAT32*) bmp->bits[sample], bmp->i.width, bmp->i.height, bmp->i.width, method );
     687    else
     688    if (bmp->i.depth==64 && bmp->i.pixelType==D_FMT_FLOAT)
     689      image_resample<DIM_FLOAT64, double>( (DIM_FLOAT64*) img.bits(sample), img.width(), img.height(),img.width(),
     690                                   (DIM_FLOAT64*) bmp->bits[sample], bmp->i.width, bmp->i.height, bmp->i.width, method );
     691
    644692  } // sample
    645693
     
    731779      image_rotate<DIM_UCHAR>( (DIM_UCHAR*) img.bits(sample), img.width(), img.height(),img.width(),
    732780                               (DIM_UCHAR*) bmp->bits[sample], bmp->i.width, bmp->i.height, bmp->i.width, deg );
    733 
     781    else
    734782    if (bmp->i.depth==16)
    735783      image_rotate<DIM_UINT16>( (DIM_UINT16*) img.bits(sample), img.width(), img.height(),img.width(),
    736784                                (DIM_UINT16*) bmp->bits[sample], bmp->i.width, bmp->i.height, bmp->i.width, deg );
    737 
     785    else
    738786    if (bmp->i.depth==32)
    739787      image_rotate<DIM_UINT32>( (DIM_UINT32*) img.bits(sample), img.width(), img.height(),img.width(),
    740788                                (DIM_UINT32*) bmp->bits[sample], bmp->i.width, bmp->i.height, bmp->i.width, deg );
     789    else
     790    if (bmp->i.depth==64)
     791      image_rotate<DIM_FLOAT64>( (DIM_FLOAT64*) img.bits(sample), img.width(), img.height(),img.width(),
     792                                (DIM_FLOAT64*) bmp->bits[sample], bmp->i.width, bmp->i.height, bmp->i.width, deg );
    741793  } // sample
    742794
     
    793845
    794846bool TDimImage::pixelArithmeticMin( const TDimImage &img ) {
    795 
    796   if (bmp->i.depth == 8)
    797     return pixel_arithmetic<DIM_UCHAR> ( img, min_lines<DIM_UCHAR> );
    798 
    799   if (bmp->i.depth == 16)
     847  if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_UNSIGNED)
     848    return pixel_arithmetic<DIM_UINT8> ( img, min_lines<DIM_UINT8> );
     849  else
     850  if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_UNSIGNED)
    800851    return pixel_arithmetic<DIM_UINT16> ( img, min_lines<DIM_UINT16> );
    801      
    802   if (bmp->i.depth == 32)
     852  else
     853  if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_UNSIGNED)
    803854    return pixel_arithmetic<DIM_UINT32> ( img, min_lines<DIM_UINT32> );
    804 
     855  else
     856  if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_SIGNED)
     857    return pixel_arithmetic<DIM_INT8> ( img, min_lines<DIM_INT8> );
     858  else
     859  if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_SIGNED)
     860    return pixel_arithmetic<DIM_INT16> ( img, min_lines<DIM_INT16> );
     861  else
     862  if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_SIGNED)
     863    return pixel_arithmetic<DIM_INT32> ( img, min_lines<DIM_INT32> );
     864  else
     865  if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_FLOAT)
     866    return pixel_arithmetic<DIM_FLOAT32> ( img, min_lines<DIM_FLOAT32> );
     867  else
     868  if (bmp->i.depth == 64 && bmp->i.pixelType==D_FMT_FLOAT)
     869    return pixel_arithmetic<DIM_FLOAT64> ( img, min_lines<DIM_FLOAT64> );
     870  else
    805871  return false;
    806872}
    807873
    808874bool TDimImage::pixelArithmeticMax( const TDimImage &img ) {
    809 
    810   if (bmp->i.depth == 8)
    811     return pixel_arithmetic<DIM_UCHAR> ( img, max_lines<DIM_UCHAR> );
    812 
    813   if (bmp->i.depth == 16)
     875  if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_UNSIGNED)
     876    return pixel_arithmetic<DIM_UINT8> ( img, max_lines<DIM_UINT8> );
     877  else
     878  if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_UNSIGNED)
    814879    return pixel_arithmetic<DIM_UINT16> ( img, max_lines<DIM_UINT16> );
    815      
    816   if (bmp->i.depth == 32)
     880  else
     881  if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_UNSIGNED)
    817882    return pixel_arithmetic<DIM_UINT32> ( img, max_lines<DIM_UINT32> );
    818 
     883  else
     884  if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_SIGNED)
     885    return pixel_arithmetic<DIM_INT8> ( img, max_lines<DIM_INT8> );
     886  else
     887  if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_SIGNED)
     888    return pixel_arithmetic<DIM_INT16> ( img, max_lines<DIM_INT16> );
     889  else
     890  if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_SIGNED)
     891    return pixel_arithmetic<DIM_INT32> ( img, max_lines<DIM_INT32> );
     892  else
     893  if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_FLOAT)
     894    return pixel_arithmetic<DIM_FLOAT32> ( img, max_lines<DIM_FLOAT32> );
     895  else
     896  if (bmp->i.depth == 64 && bmp->i.pixelType==D_FMT_FLOAT)
     897    return pixel_arithmetic<DIM_FLOAT64> ( img, max_lines<DIM_FLOAT64> );
     898  else
    819899  return false;
    820900}
     
    843923  for (unsigned int sample=0; sample<bmp->i.samples; ++sample ) {
    844924
    845     if (bmp->i.depth==8)
    846       image_negative<DIM_UCHAR>( img.bits(sample), bmp->bits[sample], plane_size_pixels );
    847 
    848     if (bmp->i.depth==16)
     925    if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_UNSIGNED)
     926      image_negative<DIM_UINT8>( img.bits(sample), bmp->bits[sample], plane_size_pixels );
     927    else
     928    if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_UNSIGNED)
    849929      image_negative<DIM_UINT16>( img.bits(sample), bmp->bits[sample], plane_size_pixels );
    850 
    851     if (bmp->i.depth==32)
     930    else
     931    if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_UNSIGNED)
    852932      image_negative<DIM_UINT32>( img.bits(sample), bmp->bits[sample], plane_size_pixels );
     933    else
     934    if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_SIGNED)
     935      image_negative<DIM_INT8>( img.bits(sample), bmp->bits[sample], plane_size_pixels );
     936    else
     937    if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_SIGNED)
     938      image_negative<DIM_INT16>( img.bits(sample), bmp->bits[sample], plane_size_pixels );
     939    else
     940    if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_SIGNED)
     941      image_negative<DIM_INT32>( img.bits(sample), bmp->bits[sample], plane_size_pixels );
     942    else
     943    if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_FLOAT)
     944      image_negative<DIM_FLOAT32>( img.bits(sample), bmp->bits[sample], plane_size_pixels );
     945    else
     946    if (bmp->i.depth==64 && bmp->i.pixelType==D_FMT_FLOAT)
     947      image_negative<DIM_FLOAT64>( img.bits(sample), bmp->bits[sample], plane_size_pixels );
    853948
    854949  } // sample
     
    873968  if (bmp->i.depth==8)
    874969    image_row_scan<DIM_UCHAR>( buf, *this, sample, x );
    875 
     970  else
    876971  if (bmp->i.depth==16)
    877972    image_row_scan<DIM_UINT16>( buf, *this, sample, x );
    878 
    879   if (bmp->i.depth==32)
     973  else
     974  if (bmp->i.depth==32 && bmp->i.pixelType!=D_FMT_FLOAT)
    880975    image_row_scan<DIM_UINT32>( buf, *this, sample, x );
    881 
     976  else
     977  if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_FLOAT)
     978    image_row_scan<DIM_FLOAT32>( buf, *this, sample, x );
     979  else
     980  if (bmp->i.depth==64 && bmp->i.pixelType==D_FMT_FLOAT)
     981    image_row_scan<DIM_FLOAT64>( buf, *this, sample, x );
    882982}
    883983
     
    9191019bool TDimImage::operationThershold( const double &th ) {
    9201020
    921   if (bmp->i.depth == 8)
    922     return pixel_operations<DIM_UCHAR>  ( operation_threshold<DIM_UCHAR>, th );
    923 
    924   if (bmp->i.depth == 16)
     1021  if (bmp->i.depth == 8 && bmp->i.pixelType==D_FMT_UNSIGNED)
     1022    return pixel_operations<DIM_UINT8>  ( operation_threshold<DIM_UINT8>, th );
     1023  else
     1024  if (bmp->i.depth == 16 && bmp->i.pixelType==D_FMT_UNSIGNED)
    9251025    return pixel_operations<DIM_UINT16> ( operation_threshold<DIM_UINT16>, th );
    926      
    927   if (bmp->i.depth == 32)
     1026  else     
     1027  if (bmp->i.depth == 32 && bmp->i.pixelType==D_FMT_UNSIGNED)
    9281028    return pixel_operations<DIM_UINT32> ( operation_threshold<DIM_UINT32>, th );
    929 
     1029  else
     1030  if (bmp->i.depth == 8 && bmp->i.pixelType==D_FMT_SIGNED)
     1031    return pixel_operations<DIM_INT8>  ( operation_threshold<DIM_INT8>, th );
     1032  else
     1033  if (bmp->i.depth == 16 && bmp->i.pixelType==D_FMT_SIGNED)
     1034    return pixel_operations<DIM_INT16> ( operation_threshold<DIM_INT16>, th );
     1035  else     
     1036  if (bmp->i.depth == 32 && bmp->i.pixelType==D_FMT_SIGNED)
     1037    return pixel_operations<DIM_INT32> ( operation_threshold<DIM_INT32>, th );
     1038  else   
     1039  if (bmp->i.depth == 32 && bmp->i.pixelType==D_FMT_FLOAT)
     1040    return pixel_operations<DIM_FLOAT32> ( operation_threshold<DIM_FLOAT32>, th );
     1041  else     
     1042  if (bmp->i.depth == 64 && bmp->i.pixelType==D_FMT_FLOAT)
     1043    return pixel_operations<DIM_FLOAT64> ( operation_threshold<DIM_FLOAT64>, th );
     1044  else
    9301045  return false;
    9311046}
     
    9351050//*****************************************************************************
    9361051
    937 DImageHistogram::DImageHistogram( int channels, int bpp ) {
     1052DImageHistogram::DImageHistogram( int channels, int bpp, const D_DataFormat &fmt ) {
    9381053  if (channels > 0)
    9391054    histograms.resize( channels );
     
    9411056  if (bpp > 0) 
    9421057  for (int c=0; c<channels; ++c) {
    943     histograms[c].init( bpp );
     1058    histograms[c].init( bpp, fmt );
    9441059  }
    9451060}
     
    9531068  histograms.resize( img.samples() );
    9541069  for (unsigned int c=0; c<img.samples(); ++c) {
    955     histograms[c].init( img.depth() );
    956     histograms[c].newData( img.depth(), img.bits(c), img.numPixels() );
     1070    histograms[c].newData( img.depth(), img.bits(c), img.numPixels(), img.pixelType() );
    9571071  }
    9581072}
    9591073
    9601074//*****************************************************************************
    961 //  DImageHistogram
     1075//  DImageLut
    9621076//*****************************************************************************
    9631077
  • bioView3D/libsrc/libbioimg/formats_api/dim_image.h

    r108 r112  
    148148    inline DIM_UINT     depth()     const { if (bmp==NULL) return 0; else return bmp->i.depth;  }
    149149    inline DIM_UINT     samples()   const { if (bmp==NULL) return 0; else return bmp->i.samples; }
    150     inline DIM_DataType pixelType() const { if (bmp==NULL) return DIM_TAG_NOTYPE; else return bmp->i.pixelType; }
     150    inline DIM_UINT     channels()  const { return samples(); }
     151    inline D_DataFormat pixelType() const { if (bmp==NULL) return D_FMT_UNSIGNED; else return bmp->i.pixelType; }
     152
     153    void updateGeometry( const unsigned int &z=0, const unsigned int &t=0 ) {
     154      if (bmp==NULL) return;
     155      if (z>0) bmp->i.number_z = z;
     156      if (t>0) bmp->i.number_t = t;
     157    }
    151158
    152159    TDimImageBitmap *imageBitmap() { return bmp; }
     
    185192    bool fromFile( const std::string &fileName, int page ) {
    186193      return fromFile( fileName.c_str(), page ); }
    187    
    188     bool toFile( const char *fileName, const char *formatName );
     194
     195    bool toFile( const char *fileName, const char *formatName, const char *options=NULL );
    189196    bool toFile( const std::string &fileName, const std::string &formatName ) {
    190197      return toFile( fileName.c_str(), formatName.c_str() ); }
     198    bool toFile( const std::string &fileName, const std::string &formatName, const std::string &options ) {
     199      return toFile( fileName.c_str(), formatName.c_str(), options.c_str() ); }
    191200    #endif //DIM_USE_IMAGEMANAGER
    192201
     
    206215    //--------------------------------------------------------------------------
    207216   
    208     TDimImage convertToDepth( int depth, DimLut::LutType method = DimLut::ltLinearFullRange ) const;
     217    TDimImage convertToDepth( int depth, DimLut::LutType method = DimLut::ltLinearFullRange, D_DataFormat pxtype = D_FMT_UNDEFINED ) const;
    209218    TDimImage convertToDepth( const DImageLut & ) const;
    210219    TDimImage normalize( int to_bpp = 8 ) const;
     
    313322class DImageHistogram {
    314323  public:
    315     DImageHistogram( int channels=0, int bpp=0 );
     324    DImageHistogram( int channels=0, int bpp=0, const D_DataFormat &fmt=D_FMT_UNSIGNED );
    316325    DImageHistogram( const TDimImage &img ) { fromImage(img); }
    317326    ~DImageHistogram();
     
    353362    int depthInput()  const { if (size()<=0) return 0; return luts[0].depthInput(); }
    354363    int depthOutput() const { if (size()<=0) return 0; return luts[0].depthOutput(); }
     364    D_DataFormat dataFormatInput()  const { if (size()<=0) return D_FMT_UNDEFINED; return luts[0].dataFormatInput(); }
     365    D_DataFormat dataFormatOutput() const { if (size()<=0) return D_FMT_UNDEFINED; return luts[0].dataFormatOutput(); }
    355366
    356367    const DimLut& lut_for_channel( int c ) const { return luts[c]; }
  • bioView3D/libsrc/libbioimg/formats_api/dim_image_pyramid.h

    r43 r112  
    3838    int  levelClosestTop( unsigned int w, unsigned int h ) const;
    3939    int  levelClosestBottom( unsigned int w, unsigned int h ) const;
     40    int  numberLevels() const { return size(); }
     41
     42    void setMinImageSize( int v ) { min_width = v; min_height = v; }
    4043
    4144    void createFrom( const TDimImage &img );
  • bioView3D/libsrc/libbioimg/formats_api/dim_image_stack.cpp

    r103 r112  
    187187//------------------------------------------------------------------------------
    188188
    189 void DImageStack::convertToDepth( int depth, DimLut::LutType method, bool planes_independent ) {
     189void DImageStack::convertToDepth( int depth, DimLut::LutType method, bool planes_independent, D_DataFormat pxtype ) {
     190 
    190191  if (!planes_independent) {
    191192    DStackHistogram stack_histogram ( *this );
    192     DImageHistogram out( this->samples(), depth );
     193    if (pxtype==D_FMT_UNDEFINED) pxtype = this->pixelType();
     194    DImageHistogram out( this->samples(), depth, pxtype );
    193195    DImageLut lut( stack_histogram, out, method );
    194196    convertToDepth( lut );
     
    196198    for (unsigned int i=0; i<images.size(); ++i) {
    197199      do_progress( i, images.size(), "Converting depth" );
    198       images[i] = images[i].convertToDepth( depth, method );
     200      images[i] = images[i].convertToDepth( depth, method, pxtype );
    199201    }
    200202  }
     
    209211
    210212void DImageStack::normalize( int to_bpp, bool planes_independent ) {
    211   this->convertToDepth( to_bpp, DimLut::ltLinearDataRange, planes_independent );
     213  this->convertToDepth( to_bpp, DimLut::ltLinearDataRange, planes_independent, D_FMT_UNSIGNED );
    212214}
    213215
     
    417419
    418420void DStackHistogram::fromImageStack( const DImageStack &stack ) { 
    419  
    420421  histograms.clear();
    421422  histograms.resize( stack.samples() );
    422423
     424  // iterate first to get stats - slower but will not fail on float data
    423425  for (unsigned int c=0; c<stack.samples(); ++c) {
    424     histograms[c].init( stack.depth() );
     426    histograms[c].init( stack.depth(), stack.pixelType() );
     427    for (unsigned int i=0; i<stack.length(); ++i)
     428      histograms[c].updateStats( stack[i]->bits(c), stack[i]->numPixels() );
     429  } // channels 
     430
     431  // iterate first to create histograms
     432  for (unsigned int c=0; c<stack.samples(); ++c) {
    425433    for (unsigned int i=0; i<stack.length(); ++i)
    426434      histograms[c].addData( stack[i]->bits(c), stack[i]->numPixels() );
  • bioView3D/libsrc/libbioimg/formats_api/dim_image_stack.h

    r103 r112  
    4949    void       setNumberPlanes( unsigned int );
    5050
    51     DIM_ULONG    width()     const { if (size()<=0) return 0; else return images[0].width();  }
    52     DIM_ULONG    height()    const { if (size()<=0) return 0; else return images[0].height(); }
    53     DIM_ULONG    length()    const { return size(); }
    54     DIM_UINT     depth()     const { if (size()<=0) return 0; else return images[0].depth();  }
    55     DIM_UINT     samples()   const { if (size()<=0) return 0; else return images[0].samples(); }
     51    inline DIM_ULONG    width()     const { if (size()<=0) return 0; else return images[0].width();  }
     52    inline DIM_ULONG    height()    const { if (size()<=0) return 0; else return images[0].height(); }
     53    inline DIM_ULONG    length()    const { return size(); }
     54    inline DIM_UINT     depth()     const { if (size()<=0) return 0; else return images[0].depth();  }
     55    inline DIM_UINT     samples()   const { if (size()<=0) return 0; else return images[0].samples(); }
     56    inline D_DataFormat pixelType() const { if (size()<=0) return D_FMT_UNSIGNED; else return images[0].pixelType(); }
    5657
    5758    TDimImage *imageAt( unsigned int position ) const;
     
    8687
    8788    // Operations
    88     void convertToDepth( int depth, DimLut::LutType method = DimLut::ltLinearFullRange, bool planes_independent = false );
     89    void convertToDepth( int depth, DimLut::LutType method = DimLut::ltLinearFullRange, bool planes_independent = false, D_DataFormat pxtype = D_FMT_UNDEFINED );
    8990    void convertToDepth( const DImageLut & );
    9091    void normalize( int to_bpp = 8, bool planes_independent = false );
  • bioView3D/libsrc/libbioimg/formats_api/dim_img_format_interface.h

    r95 r112  
    3535    2008-04-04 14:11 - updated API to v1.6
    3636    2009-06-29 16:21 - updated API to v1.7
     37    2010-01-25 16:45 - updated API to v1.8
    3738
    3839  ver: 17
     
    7879//#ifndef DIM_INT
    7980#define DIM_INT int
     81#define DIM_INT8 char
    8082#define DIM_INT16 short
    8183#define DIM_INT32 int
     
    9092//#ifndef DIM_UINT
    9193#define DIM_UINT unsigned int
     94#define DIM_UINT8  unsigned char
    9295#define DIM_UINT16 unsigned short
    9396#define DIM_UINT32 unsigned int
     
    143146} DIM_DataType;
    144147
     148// Data storage format used along with pixel depth (BPP)
     149typedef enum {
     150  D_FMT_UNDEFINED   = 0,  // placeholder type
     151  D_FMT_UNSIGNED    = 1,  // unsigned integer
     152  D_FMT_SIGNED      = 2,  // signed integer
     153  D_FMT_FLOAT       = 3   // floating point
     154} D_DataFormat;
     155
    145156
    146157// modes are declared similarry to Adobe Photoshop, but there are differences
     
    292303  DIM_UINT      samples;      // Samples per pixel
    293304  DIM_UINT      depth;        // Bits per sample, currently must be 8 or 16
    294   DIM_DataType  pixelType;    // type in which the pixels are stored v1.3
    295                               // related to depth but differentiate signed/unsigned etc.
     305  D_DataFormat  pixelType;    // type in which the pixels are stored, changed in v1.8
     306                              // related to depth but differentiate signed/unsigned/floats etc.
    296307  DIM_DataType  rowAlignment; // type to which each row is aligned v1.5
    297308
  • bioView3D/libsrc/libbioimg/formats_api/dim_img_format_utils.cpp

    r75 r112  
    368368  tp.samples = 0;
    369369  tp.depth = 0;
    370   tp.pixelType = DIM_TAG_BYTE;
     370  tp.pixelType = D_FMT_UNSIGNED;
    371371  tp.rowAlignment = DIM_TAG_BYTE;
    372372
  • bioView3D/libsrc/libbioimg/formats_api/resize.h

    r43 r112  
    5858template<typename T> class DBlackmanSincFilter;
    5959
    60 //------------------------------------------------------------------------------------
     60//************************************************************************************
    6161// Vector resize functions
    62 //------------------------------------------------------------------------------------
    63 
    64 // nearest neighbor
    65 
     62//************************************************************************************
     63
     64// nearest neighbor ------------------------------------------------------------------
    6665template <typename T>
    6766std::vector<T> vector_resample_NN ( const std::vector<T> &src, unsigned int new_size );
    6867
     68// templating Tw - work type, potentially giving higher quality or faster speed
     69template <typename T, typename Tw>
     70std::vector<T> vector_resample_NN ( const std::vector<T> &src, unsigned int new_size );
     71
     72// Bilinear ---------------------------------------------------------------------------
    6973template <typename T>
    7074std::vector<T> vector_resample_BL ( const std::vector<T> &src, unsigned int new_size );
    7175
     76// templating Tw - work type, potentially giving higher quality or faster speed
     77template <typename T, typename Tw>
     78std::vector<T> vector_resample_BL ( const std::vector<T> &src, unsigned int new_size );
     79
     80// Bicubic ----------------------------------------------------------------------------
    7281template <typename T>
    7382std::vector<T> vector_resample_BC ( const std::vector<T> &src, unsigned int new_size );
    7483
    75 template <typename Td, typename Tw>
    76 std::vector<Td> ResizeVector( const std::vector<Td> &src, unsigned int new_size,
    77                               DInterpolationFilter<Tw> &filter, const Tw blur );
    78 
    79 //------------------------------------------------------------------------------------
    80 // Simple Image Resize functions, templated type is the pixel data type
    81 //------------------------------------------------------------------------------------
    82 
    83 // nearest neighbor
    84 template <typename T>
    85 void image_resample_NN ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
    86                         const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in );
    87 
    88 // Bilinear
    89 template <typename T>
    90 void image_resample_BL ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
    91                         const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in );
    92 
    93 // Bicubic
    94 template <typename T>
    95 void image_resample_BC ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
    96                         const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in );
     84// templating Tw - work type, potentially giving higher quality or faster speed
     85template <typename T, typename Tw>
     86std::vector<T> vector_resample_BC ( const std::vector<T> &src, unsigned int new_size );
    9787
    9888//------------------------------------------------------------------------------------
     
    10595//   o blur: The blur factor where > 1 is blurry, < 1 is sharp
    10696//------------------------------------------------------------------------------------
     97
     98template <typename Td, typename Tw>
     99std::vector<Td> ResizeVector( const std::vector<Td> &src, unsigned int new_size,
     100                              DInterpolationFilter<Tw> &filter, const Tw blur );
     101
     102
     103
     104//************************************************************************************
     105// Simple Image Resize functions, templated type is the pixel data type
     106//************************************************************************************
     107
     108// nearest neighbor ------------------------------------------------------------------
     109template <typename T>
     110void image_resample_NN ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
     111                        const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in );
     112
     113// templating Tw - work type, potentially giving higher quality or faster speed
     114template <typename T, typename Tw>
     115void image_resample_BL ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
     116                         const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in );
     117
     118// Bilinear --------------------------------------------------------------------------
     119template <typename T>
     120void image_resample_BL ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
     121                        const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in );
     122
     123// templating Tw - work type, potentially giving higher quality or faster speed
     124template <typename T, typename Tw>
     125void image_resample_BL ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
     126                        const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in );
     127
     128// Bicubic ---------------------------------------------------------------------------
     129template <typename T>
     130void image_resample_BC ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
     131                        const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in );
     132
     133// templating Tw - work type, potentially giving higher quality or faster speed
     134template <typename T, typename Tw>
     135void image_resample_BC ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
     136                        const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in );
     137
     138
     139//------------------------------------------------------------------------------------
     140// Generic resize function,
     141// Types:
     142//   o Td is the pixel data type (uchar, short, ...)
     143//   o Tw is the working type, suggested values are float or double
     144// Params:
     145//   o filter: filter to use
     146//   o blur: The blur factor where > 1 is blurry, < 1 is sharp
     147//------------------------------------------------------------------------------------
    107148template <typename Td, typename Tw>
    108149void ResizeImage( Td *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
    109150                         const Td *psrc, unsigned int w_in, unsigned int h_in, unsigned int offset_in,
    110151                         DInterpolationFilter<Tw> &filter, const Tw blur );
     152
     153
     154
     155
    111156
    112157
     
    711756//------------------------------------------------------------------------------------
    712757
    713 template <typename T>
     758template <typename T, typename Tw>
    714759void image_resample_NN ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
    715760                         const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in ) {
    716761
    717   float ratio_h = w_in  / (float) w_to;
    718   float ratio_v = h_in / (float) h_to;
     762  Tw ratio_h = w_in  / (Tw) w_to;
     763  Tw ratio_v = h_in / (Tw) h_to;
    719764  register unsigned int x, y;
    720765  register unsigned int xn, yn;
     
    725770  for (y=0; y<h_to; y++) {
    726771    for (x=0; x<w_to; x++) {
    727       xn = dim::trim<unsigned int, float>(ceil(x*ratio_h), 0, w_in-1 );
    728       yn = dim::trim<unsigned int, float>(ceil(y*ratio_v), 0, h_in-1 );
     772      xn = dim::trim<unsigned int, Tw>(ceil(x*ratio_h), 0, w_in-1 );
     773      yn = dim::trim<unsigned int, Tw>(ceil(y*ratio_v), 0, h_in-1 );
    729774      p = psrc + (offset_in * yn);
    730775      q[x] = p[xn];     
     
    735780
    736781template <typename T>
     782void image_resample_NN ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
     783                        const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in ) {
     784  image_resample_NN<T, float> ( pdest, w_to, h_to, offset_to, psrc,  w_in, h_in, offset_in );
     785}
     786
     787
     788template <typename T, typename Tw>
    737789void image_resample_BL ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
    738790                         const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in ) {
    739   DTriangleFilter<float> filter;
    740   ResizeImage<T, float>( pdest, w_to, h_to, offset_to, psrc, w_in, h_in, offset_in, filter, 0.85f );
    741 }
    742 
    743 template <typename T>
     791  DTriangleFilter<Tw> filter;
     792  ResizeImage<T, Tw>( pdest, w_to, h_to, offset_to, psrc, w_in, h_in, offset_in, filter, 0.85f );
     793}
     794
     795template <typename T>
     796void image_resample_BL ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
     797                        const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in ) {
     798  image_resample_BL<T, float> ( pdest, w_to, h_to, offset_to, psrc,  w_in, h_in, offset_in );
     799}
     800
     801
     802template <typename T, typename Tw>
    744803void image_resample_BC ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
    745804                        const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in ) {
    746   DCubicFilter<float> filter;
    747   ResizeImage<T, float>( pdest, w_to, h_to, offset_to, psrc, w_in, h_in, offset_in, filter, 0.95f );
     805  DCubicFilter<Tw> filter;
     806  ResizeImage<T, Tw>( pdest, w_to, h_to, offset_to, psrc, w_in, h_in, offset_in, filter, 0.95f );
     807}
     808
     809template <typename T>
     810void image_resample_BC ( T *pdest, unsigned int w_to, unsigned int h_to, unsigned int offset_to,
     811                        const T *psrc,  unsigned int w_in, unsigned int h_in, unsigned int offset_in ) {
     812  image_resample_BC<T, float> ( pdest, w_to, h_to, offset_to, psrc,  w_in, h_in, offset_in );
    748813}
    749814
     
    827892//------------------------------------------------------------------------------------
    828893
    829 template <typename T>
     894template <typename T, typename Tw>
    830895std::vector<T> vector_resample_NN ( const std::vector<T> &src, unsigned int new_size ) {
    831896
    832897  std::vector<T> q(new_size);
    833   float ratio = src.size() / (float) new_size;
     898  Tw ratio = src.size() / (Tw) new_size;
    834899  register unsigned int x, xn;
    835900
    836901  for (x=0; x<new_size; x++) {
    837     xn = dim::trim<unsigned int, float>(ceil(x*ratio), 0, src.size()-1 );
     902    xn = dim::trim<unsigned int, Tw>(ceil(x*ratio), 0, src.size()-1 );
    838903    q[x] = src[xn];     
    839904  } // x
     
    842907
    843908template <typename T>
     909std::vector<T> vector_resample_NN ( const std::vector<T> &src, unsigned int new_size ) {
     910  return vector_resample_NN<T, double>( src, new_size );
     911}
     912
     913
     914template <typename T, typename Tw>
    844915std::vector<T> vector_resample_BL ( const std::vector<T> &src, unsigned int new_size ) {
    845   DTriangleFilter<float> filter;
    846   return ResizeVector<T, float>( src, new_size, filter, 0.85f );
    847 }
    848 
    849 template <typename T>
     916  DTriangleFilter<Tw> filter;
     917  return ResizeVector<T, Tw>( src, new_size, filter, 0.85f );
     918}
     919
     920template <typename T>
     921std::vector<T> vector_resample_BL ( const std::vector<T> &src, unsigned int new_size ) {
     922  return vector_resample_BL<T, double>( src, new_size );
     923}
     924
     925
     926template <typename T, typename Tw>
    850927std::vector<T> vector_resample_BC ( const std::vector<T> &src, unsigned int new_size ) {
    851   DCubicFilter<float> filter;
    852   return ResizeVector<T, float>( src, new_size, filter, 0.95f );
     928  DCubicFilter<Tw> filter;
     929  return ResizeVector<T, Tw>( src, new_size, filter, 0.95f );
     930}
     931
     932template <typename T>
     933std::vector<T> vector_resample_BC ( const std::vector<T> &src, unsigned int new_size ) {
     934  return vector_resample_BC<T, double>( src, new_size );
    853935}
    854936
  • bioView3D/msvc2008/bioView3D.rc

    r95 r112  
    5454
    5555VS_VERSION_INFO VERSIONINFO
    56  FILEVERSION 0,0,12,12
    57  PRODUCTVERSION 0,0,12,12
     56 FILEVERSION 0,0,14,14
     57 PRODUCTVERSION 0,0,14,14
    5858 FILEFLAGSMASK 0x17L
    5959#ifdef _DEBUG
     
    7272            VALUE "CompanyName", "Center for Bio-Image Informatics"
    7373            VALUE "FileDescription", "bioView3D"
    74             VALUE "FileVersion", "0, 0, 12, 12"
     74            VALUE "FileVersion", "0, 0, 14, 14"
    7575            VALUE "InternalName", "bioView3D"
    76             VALUE "LegalCopyright", "Copyright (C) 2009, Center for Bio-Image Informatics"
     76            VALUE "LegalCopyright", "Copyright (C) 2010, Center for Bio-Image Informatics"
    7777            VALUE "OriginalFilename", "bioView3D"
    7878            VALUE "ProductName", "bioView3D"
    79             VALUE "ProductVersion", "0, 0, 12, 12"
     79            VALUE "ProductVersion", "0, 0, 14, 14"
    8080        END
    8181    END
  • bioView3D/src/glwidget.cpp

    r110 r112  
    13231323
    13241324void GLWidget::saveImage( const QString &fileName, const QString &formatName ) {
     1325  progress->startNow(true);
    13251326  stack.toFile( fileName.toStdString(), formatName.toStdString() );
     1327  in_progress = false;
     1328  emit stopProgress();
    13261329}
    13271330
  • bioView3D/src/widgets/d_range_slider.h

    r43 r112  
    4141public slots:
    4242  void setRange( double _min, double _max ) { range_min =_min; range_max=_max; setSub(_min,_max); }
    43   void setSub( double _min, double _max ) { sub_min =_min; sub_max=_max; updateRangeCoordinates(); this->update(); }
     43  void setSub( double _min, double _max ) { sub_min =_min; sub_max=_max; updateRangeCoordinates(); this->update();  }
    4444
    4545signals:
  • bioView3D/src/window.cpp

    r110 r112  
    1818#define BV_APPLICATION     "BioView3D"
    1919#define BV_CONFIG_FILE     "bioview3d.ini"
    20 #define BV_VERSION         "0.0.13"
     20#define BV_VERSION         "0.0.14"
    2121
    2222#include <string>
     
    106106  ui.transparencySlider->setSub( ui.glWidget->getTransparencyLoBound()/2.55, ui.glWidget->getTransparencyUpBound()/2.55 );
    107107  connect(ui.transparencySlider, SIGNAL(rangeChanged(double, double)), this, SLOT(onTransparencyBoundsCombo(double, double)));
     108
     109  connect(ui.transpChannelsCombo, SIGNAL(activated(int)), this, SLOT(onTransparencyChannelCombo(int)));
     110
    108111
    109112  connect(ui.xSlider, SIGNAL(valueChanged(int)), ui.glWidget, SLOT(setXRotation(int)));
Note: See TracChangeset for help on using the changeset viewer.