LArOpenCV  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
larcaffe::Image2D Class Reference

Meant to be a storage class for an image into a ROOT file. More...

#include <Image2D.h>

Inheritance diagram for larcaffe::Image2D:

Public Member Functions

 Image2D (size_t width_npixel=0, size_t height_npixel=0)
 
 Image2D (const ImageMeta &)
 
 Image2D (const Image2D &)
 
virtual ~Image2D ()
 
unsigned int height () const
 
unsigned int width () const
 
float pixel (size_t w, size_t h) const
 
bool isInBounds (size_t w, size_t h) const
 
Image2D copy_compress (size_t width_npixel, size_t height_npixel) const
 
size_t index (size_t w, size_t h) const
 
void copy (size_t w, size_t h, const float *src, size_t num_pixel)
 
void copy (size_t w, size_t h, const std::vector< float > &src, size_t num_pixel=0)
 
void copy (size_t w, size_t h, const short *src, size_t num_pixel)
 
void copy (size_t w, size_t h, const std::vector< short > &src, size_t num_pixel=0)
 
const std::vector< float > & as_vector () const
 
const ImageMetameta_data () const
 
void resize (size_t width_npixel, size_t height_npixel)
 
void set_pixel (size_t w, size_t h, float value)
 
void paint (float value)
 
void clear_data ()
 
void compress (size_t width_npixel, size_t height_npixel)
 

Protected Attributes

elements
 STL member. More...
 

Private Member Functions

void clear ()
 

Private Attributes

ImageMeta _meta
 

Detailed Description

Meant to be a storage class for an image into a ROOT file.

Not yet implemented (don't bother reading!)

Definition at line 27 of file Image2D.h.

Constructor & Destructor Documentation

larcaffe::Image2D::Image2D ( size_t  width_npixel = 0,
size_t  height_npixel = 0 
)

Definition at line 8 of file Image2D.cxx.

9  : std::vector<float>(height_npixel*width_npixel,0.)
10  , _meta(0.,0.,width_npixel,height_npixel,0.,0.)
11  {}
larcaffe::Image2D::Image2D ( const ImageMeta meta)

Definition at line 13 of file Image2D.cxx.

14  : std::vector<float>(meta.num_pixel_row()*meta.num_pixel_column(),0.)
15  , _meta(meta)
16  {}
larcaffe::Image2D::Image2D ( const Image2D rhs)

Definition at line 18 of file Image2D.cxx.

19  : std::vector<float>(rhs)
20  , _meta(rhs._meta)
21  {}
virtual larcaffe::Image2D::~Image2D ( )
inlinevirtual

Definition at line 34 of file Image2D.h.

34 {}

Member Function Documentation

const std::vector<float>& larcaffe::Image2D::as_vector ( ) const
inline

Definition at line 48 of file Image2D.h.

49  { return (*this); }
void larcaffe::Image2D::clear ( )
private

Definition at line 29 of file Image2D.cxx.

References _meta, and larcaffe::ImageMeta::update().

29  {
30  std::vector<float>::clear();
31  _meta.update(1,1);
32  //std::cout << "[Image2D (" << this << ")] Cleared image memory " << std::endl;
33  }
void larcaffe::Image2D::clear_data ( )

Definition at line 35 of file Image2D.cxx.

35 { for(auto& v : (*this)) v = 0.; }
void larcaffe::Image2D::compress ( size_t  width_npixel,
size_t  height_npixel 
)

Definition at line 121 of file Image2D.cxx.

References copy_compress().

122  { (*this) = copy_compress(height,width); }
void larcaffe::Image2D::copy ( size_t  w,
size_t  h,
const float *  src,
size_t  num_pixel 
)

Definition at line 56 of file Image2D.cxx.

References index().

Referenced by copy().

57  {
58  const size_t idx = index(h,w);
59  if(idx+num_pixel >= size()) throw larbys("memcpy size exceeds allocated memory!");
60 
61  memcpy(&((*this)[idx]),src, num_pixel * sizeof(float));
62 
63  }
void larcaffe::Image2D::copy ( size_t  w,
size_t  h,
const std::vector< float > &  src,
size_t  num_pixel = 0 
)

Definition at line 65 of file Image2D.cxx.

References copy().

66  {
67  if(!num_pixel)
68  this->copy(h,w,(float*)(&(src[0])),src.size());
69  else if(num_pixel < src.size())
70  this->copy(h,w,(float*)&src[0],num_pixel);
71  else
72  throw larbys("Not enough pixel in source!");
73  }
void larcaffe::Image2D::copy ( size_t  w,
size_t  h,
const short *  src,
size_t  num_pixel 
)

Definition at line 75 of file Image2D.cxx.

References index().

76  {
77  const size_t idx = index(h,w);
78  if(idx+num_pixel >= size()) throw larbys("memcpy size exceeds allocated memory!");
79 
80  for(size_t i=0; i<num_pixel; ++i) (*this)[idx+i] = src[num_pixel];
81 
82  }
void larcaffe::Image2D::copy ( size_t  w,
size_t  h,
const std::vector< short > &  src,
size_t  num_pixel = 0 
)

Definition at line 84 of file Image2D.cxx.

References copy().

85  {
86  if(!num_pixel)
87  this->copy(h,w,(short*)(&(src[0])),src.size());
88  else if(num_pixel < src.size())
89  this->copy(h,w,(short*)&src[0],num_pixel);
90  else
91  throw larbys("Not enough pixel in source!");
92  }
Image2D larcaffe::Image2D::copy_compress ( size_t  width_npixel,
size_t  height_npixel 
) const

Definition at line 94 of file Image2D.cxx.

References larcaffe::ImageMeta::_height_npixel, _meta, larcaffe::ImageMeta::_width_npixel, height(), larcaffe::ImageMeta::update(), and width().

Referenced by compress().

95  {
97  throw larbys("Compression only possible if height/width are modular 0 of compression factor!");
98 
99  size_t width_factor = _meta._width_npixel / width;
100  size_t height_factor = _meta._height_npixel / height;
101  ImageMeta meta(_meta);
102  meta.update(height,width);
103  Image2D result(meta);
104 
105  for(size_t w=0; w<width; ++ w) {
106  for(size_t h=0; h<height; ++h) {
107  float value = 0;
108  //std::cout << w*height << " : " << h << std::endl;
109  for(size_t orig_w=w*width_factor; orig_w<(w+1)*width_factor; ++orig_w)
110  for(size_t orig_h=h*height_factor; orig_h<(h+1)*height_factor; ++orig_h) {
111  //std::cout << " " << (*this)[orig_w * _meta._height_npixel + orig_h] << " @ " << orig_w * _meta._height_npixel + orig_h << std::endl;
112  value += (*this)[orig_w * _meta._height_npixel + orig_h];
113  }
114  //std::cout<<std::endl;
115  result[w*height + h] = value;
116  }
117  }
118  return result;
119  }
unsigned int larcaffe::Image2D::height ( ) const
inline

Definition at line 36 of file Image2D.h.

References larcaffe::ImageMeta::_height_npixel, and _meta.

Referenced by copy_compress().

36 { return _meta._height_npixel; }
size_t larcaffe::Image2D::index ( size_t  w,
size_t  h 
) const

Definition at line 49 of file Image2D.cxx.

References larcaffe::ImageMeta::_height_npixel, _meta, and isInBounds().

Referenced by copy(), and pixel().

49  {
50 
51  if ( !isInBounds( h, w ) ) throw larbys("Invalid pixel index queried");
52 
53  return ( w * _meta._height_npixel + h );
54  }
bool larcaffe::Image2D::isInBounds ( size_t  w,
size_t  h 
) const
inline

Definition at line 39 of file Image2D.h.

References larcaffe::ImageMeta::_height_npixel, _meta, and larcaffe::ImageMeta::_width_npixel.

Referenced by index().

40  { return ( h < _meta._height_npixel && w < _meta._width_npixel ); }
const ImageMeta& larcaffe::Image2D::meta_data ( ) const
inline

Definition at line 50 of file Image2D.h.

References _meta.

50 { return _meta; }
void larcaffe::Image2D::paint ( float  value)

Definition at line 43 of file Image2D.cxx.

44  { for(auto& v : (*this)) v=value; }
float larcaffe::Image2D::pixel ( size_t  w,
size_t  h 
) const

Definition at line 46 of file Image2D.cxx.

References index().

47  { return (*this)[index(h,w)]; }
void larcaffe::Image2D::resize ( size_t  width_npixel,
size_t  height_npixel 
)

Definition at line 23 of file Image2D.cxx.

References _meta, and larcaffe::ImageMeta::update().

24  {
25  std::vector<float>::resize(height_npixel*width_npixel);
26  _meta.update(width_npixel,height_npixel);
27  }
void larcaffe::Image2D::set_pixel ( size_t  w,
size_t  h,
float  value 
)

Definition at line 37 of file Image2D.cxx.

References larcaffe::ImageMeta::_height_npixel, _meta, and larcaffe::ImageMeta::_width_npixel.

37  {
38  if ( h >= _meta._height_npixel || w >= _meta._width_npixel ) throw larbys("Out-of-bound pixel set request!");
39  return;
40  (*this)[w*_meta._height_npixel + h] = value;
41  }
unsigned int larcaffe::Image2D::width ( ) const
inline

Definition at line 37 of file Image2D.h.

References _meta, and larcaffe::ImageMeta::_width_npixel.

Referenced by copy_compress().

37 { return _meta._width_npixel; }

Member Data Documentation

ImageMeta larcaffe::Image2D::_meta
private

Definition at line 59 of file Image2D.h.

Referenced by clear(), copy_compress(), height(), index(), isInBounds(), meta_data(), resize(), set_pixel(), and width().

T std::vector< T >::elements
inherited

STL member.


The documentation for this class was generated from the following files: