//------------------------------------------------------------------------------ #ifndef RGBIMAGE_H #define RGBIMAGE_H #include "subWindow.h" #include #include class floatImage; class bwImage; #define R 0 #define G 1 #define B 2 class rgbImage { public: rgbImage( int w, int h ); rgbImage( floatImage *srcR, floatImage *srcG, floatImage *srcB, bool scaleFromZeroUp=true ); rgbImage( unsigned char *data, int w, int h ); // shallow copy rgbImage( unsigned char *data, int w, int h, bool deep ); // deep copy ~rgbImage(); // deallocates data irrespective of shallow/deep public: int getWidth() const { return width_; } int getHeight() const { return height_; } int getSize() const { return size_; } int getMemSize() const { return memSize_; } void clampInImage( int &x, int &y ); unsigned char *rawData() const { return data_; } unsigned char *pixel( int x, int y ) { return &data_[(y*width_+x)*3]; } void extractRGBComponents( bwImage *&rImg, bwImage *&gImg, bwImage *&bImg ); public: void addSquare( int x1, int y1, int x2, int y2, char r, char g, char b, float trans=1.0f, bool checkInBounds=false ); void addSquare( const subWindow &src, char r, char g, char b, float trans=1.0f, bool checkInBounds=false ); // line specified by ax+by+c=0 void addLine( float ax, float by, float c, char r, char g, char b, float trans=1.0f, int clipXmin=0, int clipYmin=0, int clipXmax=0, int clipYmax=0 ); void addLineSegment( int x1, int y1, int x2, int y2, char r, char g, char b, float trans=1.0f ); void paste( int x, int y, rgbImage *src ); public: // fast gradient (standard technique) // (allocates the memory for the floatImages - user should use delete // when finished) // Gradient based on pixel instensities ( (R+G+B)/3 ) void imgGrad( floatImage *&gradImgX, floatImage *&gradImgY ); // Gradient calculated for each colour component individually void imgGrad( floatImage *&compXR, floatImage *&compXG, floatImage *&compXB, floatImage *&compYR, floatImage *&compYG, floatImage *&compYB ); // quality gradient (Toulouse's technique) // (allocates the memory for the floatImages - user should use delete // when finished) // Gradient based on pixel instensities ( (R+G+B)/3 ) void imgGradToulouse( floatImage *&gradImgX, floatImage *&gradImgY ); // Gradient calculated for each colour component individually void imgGradToulouse( floatImage *&compXR, floatImage *&compXG, floatImage *&compXB, floatImage *&compYR, floatImage *&compYG, floatImage *&compYB ); // Harris Corner Detector (takes image gradient as input) // computes corner response for each colour individually and then finds // the magnitude of the RGB responses at each pixel static floatImage *harrisCornerDetect( floatImage *&compXR, floatImage *&compXG, floatImage *&compXB, floatImage *&compYR, floatImage *&compYG, floatImage *&compYB, int responseWindow ); floatImage *harrisCornerDetect( int responseWindow ); floatImage *harrisCornerDetect_T( int responseWindow ); private: void gradToulouse( int x, int y, float &grdX, float &grdY, int comp ); private: int width_, height_, size_, memSize_; unsigned char *data_; }; inline rgbImage::rgbImage( int w, int h ) : width_(w), height_(h), size_(w*h), memSize_(size_*3*sizeof(unsigned char)) { data_ = (unsigned char*)malloc(memSize_); } inline rgbImage::rgbImage( unsigned char *data, int w, int h ) : data_(data), width_(w), height_(h), size_(w*h), memSize_(size_*3*sizeof(unsigned char)) { } inline rgbImage::rgbImage( unsigned char *data, int w, int h, bool deep ) : width_(w), height_(h), size_(w*h), memSize_(size_*3*sizeof(unsigned char)) { if ( (data_=(unsigned char*)malloc(memSize_))!=0 ) { memcpy( data_, data, memSize_ ); } } inline rgbImage::~rgbImage() { if ( data_!=0 ) free( data_ ); } inline void rgbImage::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 // RGBIMAGE_H