//------------------------------------------------------------------------------ #ifndef BWIMAGE_H #define BWIMAGE_H #include #include class floatImage; class rgbImage; class bwImage { public: bwImage( int w, int h ); bwImage( unsigned char *data, int w, int h ); // shallow copy bwImage( unsigned char *data, int w, int h, bool deep ); // deep copy bwImage( bwImage *src ); // deep copy bwImage( rgbImage *src ); // deep copy bwImage( floatImage *src, bool scaleFromZeroUp=true ); // deep copy ~bwImage(); // deallocates data irrespective of shallow/deep public: int getWidth() { return width_; } int getHeight() { return height_; } int getSize() { return size_; } void clampInImage( int &x, int &y ); unsigned char *rawData() { return data_; } unsigned char &pixel( int x, int y ) { return data_[y*width_+x]; } public: void addSquare( int x1, int y1, int x2, int y2, char intens, float trans=1.0f, bool checkInBounds=false ); public: // fast gradient (standard technique) // (allocates the memory for the floatImages - user should use delete // when finished) void imgGrad( floatImage *&gradImgX, floatImage *&gradImgY ); // quality gradient (Toulouse's technique) void imgGradToulouse( floatImage *&gradImgX, floatImage *&gradImgY ); // Harris Corner Detector (takes image gradient as input) // (allocates the memory for the floatImage - user should use delete // when finished) static floatImage *harrisCornerDetect( floatImage *gradImgX, floatImage *gradImgY, int responseWindow ); floatImage *harrisCornerDetect( int responseWindow ); floatImage *harrisCornerDetect_T( int responseWindow ); private: void gradToulouse( int x, int y, float &grdX, float &grdY ); private: int width_, height_, size_, memSize_; unsigned char *data_; }; inline bwImage::bwImage( int w, int h ) : width_(w), height_(h), size_(w*h), memSize_(size_*sizeof(unsigned char)) { data_ = (unsigned char*)malloc(memSize_); } inline bwImage::bwImage( unsigned char *data, int w, int h ) : data_(data), width_(w), height_(h), size_(w*h), memSize_(size_*sizeof(unsigned char)) { } inline bwImage::bwImage( unsigned char *data, int w, int h, bool deep ) : width_(w), height_(h), size_(w*h), memSize_(size_*sizeof(unsigned char)) { if ( (data_=(unsigned char*)malloc(memSize_))!=0 ) { memcpy( data_, data, memSize_ ); } } inline bwImage::bwImage( bwImage *src ) : width_(src->getWidth()), height_(src->getHeight()), size_(src->getSize()), memSize_(size_*sizeof(unsigned char)) { if ( (data_=(unsigned char*)malloc(memSize_))!=0 ) { memcpy( data_, src->rawData(), memSize_ ); } } inline bwImage::~bwImage() { if ( data_!=0 ) free( data_ ); } inline void bwImage::clampInImage( int &x, int &y ) { if ( x<0 ) x=0; else if (x>=width_) x=width_-1; if ( y<0 ) y=0; else if (y>=height_) y=height_-1; } #endif // BWIMAGE_H