www.pudn.com > firev0.01.rar > gabor.hpp


/*
This file is part of the FIRE -- Flexible Image Retrieval System

FIRE is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

FIRE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with FIRE; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
/**
 * @file   gabor.hpp
 * @author Thomas Deselaers
 * @date   Mon Jun 23 19:29:12 2003
 * 
 * @brief Various functions dealing with gabor transformation.
 * 
 */


#ifndef __gabor_hpp
#define __gabor_hpp

#include 
#include 
#include 
#include "hdimage.hpp"
#include "rgbimage.hpp"
#include "image.hpp"
#include "basetools.hpp"



/**
 * save the gabor features from an image into a text file.
 * @param image the ::img::HDImage containing the gaborfeatures.
 * @param filename the filename of the file, where the features shall be saved.
 *
 */ 
int saveGaborFeatures(::img::HDImage image, ::std::string filename) ;

/**
 * load gabor features from a file 
 *
 */
::std::vector< ::std::vector* > loadGaborFeatures(string filename, const bool withcoords=true);

/** 
 * Extract gabor features from a color image
 * 
 * @param filename the file to save the gaborfeatures to
 * @param inImage the image to be processed
 * @param decomp the decomposed version of the image
 * @param threshold the threshold for local variance to determine which features to save
 * @param winsize the window size for local variance calculation
 * 
 * @return the number of features extracted
 */
int extractGaborFeatures(::std::string filename, const ::img::RGBImage & inImage, const ::img::HDImage &decomp,double threshold, unsigned int winsize) ;

/** 
 * Extract gabor features from a color image
 * 
 * @param filename the file to save the gaborfeatures to
 * @param inImage the image to be processed
 * @param decomp the decomposed version of the image
 * @param nOfFeatures the number of features to be extracted. The ones with highest local variance are extracted.
 * @param winsize the window size for local variance calculation
 * 
 * @return the number of features extracted
 */
int extractGaborFeatures(::std::string filename, const ::img::RGBImage & inImage, const ::img::HDImage &decomp,int nOfFeatures, unsigned int winsize);

/** 
 * Extract gabor features from a single layer image
 * 
 * @param filename the file to save the gaborfeatures to
 * @param inImage the image to be processed
 * @param decomp the decomposed version of the image
 * @param threshold the threshold for local variance to determine which features to save
 * @param winsize the window size for local variance calculation
 * 
 * @return the number of features extracted
 */
int extractGaborFeatures(::std::string filename, const ::img::BaseImage & inImage, const ::img::HDImage &decomp,double threshold, unsigned int winsize);

/** 
 * Extract gabor features from a single layer image
 * 
 * @param filename the file to save the gaborfeatures to
 * @param inImage the image to be processed
 * @param decomp the decomposed version of the image
 * @param nOfFeatures the number of features to be extracted. The ones with highest local variance are extracted.
 * @param winsize the window size for local variance calculation
 * 
 * @return the number of features extracted
 */
int extractGaborFeatures(::std::string filename, const ::img::BaseImage & inImage, const ::img::HDImage &decomp,int nOfFeatures, unsigned int winsize);

/** 
 * return the integer power of two
 * 
 * @param input the number for which the next larger 2^x is search with x integer
 * 
 * @return the first exponential of two larger than the input
 */
unsigned int next2Power(const unsigned int input) ;

/** 
 * return the position in a one dimensional array which is interpreted
 * as two dimensional. No checking is done if this is possible.
 * 
 * @param y the y position
 * @param x the x position
 * @param width the assumend width
 * 
 * @return the position in a one dimensional array
 */
///return the index for a field at position (y,x) if width is assumed.
inline const unsigned int idx(const unsigned int& y,const unsigned int& x,const unsigned int& width) ;


/** 
 * Copy the Results from the Gabor filter into two layers of the output image
 * 
 * @param result the ::img::HDImage where all the gabor answers will be collected
 * @param HStoTransform the gaboranswers for the ::std::complex layer. In the format the NR-Routine fourn needs it
 * @param VtoTransform the gaboransers for the value layer. In the format the NR-Routine fourn needs it
 * @param height The Height of the important part of the image. (to skip padded values)
 * @param width  the width of the important part of the image. (to skip padded values)
 * @param maxnn the dimensionality of the complete image (width=height=maxnn=2^x, x integer)
 * @param filterno The number of the filter beeing applied, to know which layers have to be writen in result
 */
void copyToResultRGB(::img::HDImage &result,const ::std::vector &HStoTransform, const ::std::vector &VtoTransform,const unsigned int height,const unsigned int width, const unsigned int maxnn, const unsigned  int filterno) ;

/** 
 * Save the ::std::complex and the value image to be able to see the results. Normalization is done within here
 * 
 * @param HStoTransform the gaboranswers for the ::std::complex layer. In the format the NR-Routine fourn needs it
 * @param VtoTransform  the gaboransers for the value layer. In the format the NR-Routine fourn needs it
 * @param freq The frequency of the used filter (used for filename generation)
 * @param deviation The deviation of the used filter (used for filename generation)
 * @param pha The phase of the used filter (used for filename generation)
 * @param ratio The ratio of the used filter (used for filename generation)
 * @param height The Height of the important part of the image. (to skip padded values)
 * @param width  the width of the important part of the image. (to skip padded values)
 * @param maxnn the dimensionality of the complete image (width=height=maxnn=2^x, x integer)
 */
void saveHSVTransformed(const ::std::vector &HStoTransform, 
                        const ::std::vector &VtoTransform,
                        double freq, double deviation, double pha, double ratio,
                        unsigned int height, unsigned int width,unsigned int maxnn) ;


/** 
 * Save the filter as png. For visual control of results.
 * 
 * @param filter the filter to be saved
 * @param freq The frequency of the used filter (used for filename generation)
 * @param deviation The deviation of the used filter (used for filename generation)
 * @param phase The phase of the used filter (used for filename generation)
 * @param ratio The ratio of the used filter (used for filename generation)
 */
void saveFilter(const ::std::vector > &filter, double freq, double deviation, double phase, double ratio);

/** 
 * Make Gabor-Jet decomposition for an image.
 * 
 * @param in the image to be analyzed
 * @param numpha the number of phases used for this
 * 
 * @return the ::img::HDImage contains in each "layer" a response from either
 * a Gaborfilter on a ::std::complex image or the v image.
 */
///direct reimplementation of ldecompose.c from keysers

::img::HDImage decompose(::img::RGBImage in, unsigned int numpha=8, int numfreq=-1);

/** 
 * Make Gabor-Jet decomposition for an image.
 * 
 * @param in the image to be analyzed
 * @param numpha the number of phases used for this
 * 
 * @return the ::img::HDImage contains in each "layer" a response from either
 * a Gaborfilter.
 */
///direct reimplementation of ldecompose.c from keysers
::img::HDImage decompose(::img::BaseImage in, unsigned int numpha=8, int numfreq=-1);

#endif