/** @file  psImageMap.c
 *
 *  @brief Functions define a 2d coarse representation of a finer 2D field
 *
 *  @ingroup Image
 *
 *  @author Eugene Magnier, IfA
 *
 *  @version $Revision: 1.1.2.6 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2007-09-20 19:17:16 $
 *
 *  Copyright 2007 Institute for Astronomy, University of Hawaii
 */

#ifndef PS_IMAGE_MAP_H
#define PS_IMAGE_MAP_H

/// @addtogroup ImageOps Image Operations
/// @{

// a structure to describe the 2D variations of some quantity as a function of position the
// variation is represented as a psImage which covers the field also represented as a psImage.
// the map image pixels are superpixels of the field image.  values in the field are determined
// by interpolating the map image.
typedef struct {
    psStats *stats;
    psImage *map;
    psImage *error;
    psImage *field;
    psImageBinning *binning;
    int nBad;
    int nPoor;
    int nGood;
} psImageMap;

psImageMap *psImageMapAlloc(psImage *field, psImageBinning *binning, psStats *stats) PS_ATTR_MALLOC;

bool psImageMapModifyScale(psImageMap *map, int nXruff, int nYruff);

// generate a psImageMap (or NULL) with the given number of superpixels in X and Y
bool psImageMapGenerate (psImageMap *map, psVector *x, psVector *y, psVector *f, psVector *df, float badFrac);

bool psImageMapGenerateScale (psImageMap *map, psVector *x, psVector *y, psVector *f, psVector *df, float badFrac);

// apply the psImageMap to the given coordinate (fine image pixels)
double psImageMapEval (psImageMap *map, float x, float y);

// apply the psImageMap to the given coordinate vectors (fine image pixels)
psVector *psImageMapEvalVector (psImageMap *map, psVector *x, psVector *y);

// fit the image map to a set of points
bool psImageMapFit (psImageMap *map, psVector *mask, psMaskType maskValue, psVector *x, psVector *y, psVector *f, psVector *df);

// fit the image map to a set of points
bool psImageMapClipFit (psImageMap *map, psStats *stats, psVector *mask, psMaskType maskValue, psVector *x, psVector *y, psVector *f, psVector *df);

/// @}
#endif // #ifndef PS_IMAGE_MAP_H
