Index: /trunk/psLib/test/image/Makefile
===================================================================
--- /trunk/psLib/test/image/Makefile	(revision 2253)
+++ /trunk/psLib/test/image/Makefile	(revision 2254)
@@ -3,6 +3,6 @@
 ##  Makefile:   test/collections
 ##
-##  $Revision: 1.5 $  $Name: not supported by cvs2svn $
-##  $Date: 2004-10-15 19:10:51 $
+##  $Revision: 1.6 $  $Name: not supported by cvs2svn $
+##  $Date: 2004-11-02 01:24:08 $
 ##
 ##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -26,4 +26,5 @@
 tst_psImageStats02 \
 tst_psImageStats03 \
+tst_psImageStats04 \
 tst_psImageExtraction \
 tst_psImageConvolve \
Index: /trunk/psLib/test/image/tst_psImageStats04.c
===================================================================
--- /trunk/psLib/test/image/tst_psImageStats04.c	(revision 2254)
+++ /trunk/psLib/test/image/tst_psImageStats04.c	(revision 2254)
@@ -0,0 +1,109 @@
+/*****************************************************************************
+This routine must ensure that the 
+    psImageFitPolynomial()
+    psImageEvalPolynomial()
+functions work correctly.
+ 
+XXX: We do not check image pixels.
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psImage.h"
+#include "psImageStats.h"
+#include <float.h>
+#include <math.h>
+#define IMAGE_SIZE 8
+#define NUM_COLS IMAGE_SIZE
+#define NUM_ROWS IMAGE_SIZE
+#define ERROR_TOL 0.1
+#define A 1.0
+#define B 2.0
+#define C 3.0
+#define D 4.0
+#define E 5.0
+#define F 6.0
+
+#define I_POLY(X, Y) \
+((A) + (B * X) + (C * Y) + (D * X * Y) + (E * X * X) + (F * Y * Y)) \
+
+psS32 FitCheby(int numCols, int numRows)
+{
+    psImage *tmpImage     = NULL;
+    psImage *outImage     = NULL;
+    psS32 testStatus      = true;
+    psS32 memLeaks        = 0;
+    psS32 i               = 0;
+    psS32 j               = 0;
+    psS32 currentId       = psMemGetId();
+    float chi2 = 0.0;
+
+
+    printf("psImageFitPolynomial(), psImageEvalPolynom(): (%d by %d)\n", numRows, numCols);
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+
+    printPositiveTestHeader(stdout,
+                            "psImageStats functions",
+                            "psImageFitPolynomial(), psImageEvalPolynom()");
+
+    tmpImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
+    outImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
+    for (i=0;i<numRows;i++) {
+        for (j=0;j<numCols;j++) {
+            tmpImage->data.F32[i][j] = I_POLY(((float) i), ((float) j));
+        }
+    }
+
+    psPolynomial2D *chebys = psPolynomial2DAlloc(5, 5, PS_POLYNOMIAL_CHEB);
+
+    chebys = psImageFitPolynomial(chebys, tmpImage);
+
+    outImage = psImageEvalPolynomial(outImage, chebys);
+
+    chi2 = 0.0;
+    for (i=0;i<numRows;i++) {
+        for (j=0;j<numCols;j++) {
+            float expect = tmpImage->data.F32[i][j];
+            float actual = outImage->data.F32[i][j];
+            chi2+= (actual-expect) * (actual-expect);
+            if (fabs((actual - expect) / expect) > ERROR_TOL) {
+                printf("pixel [%d][%d] is %.2f should be %.2f\n", i, j, actual, expect);
+            }
+        }
+    }
+    chi2/= ((float) (numCols * numRows));
+    printf("The chi-squared per pixel is %f\n", chi2);
+
+    psFree(tmpImage);
+    psFree(outImage);
+    psFree(chebys);
+    psMemCheckCorruption(1);
+    printFooter(stdout,
+                "psImageStats functions",
+                "psImagePixelInterpolation()",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    return(!testStatus);
+}
+
+int main()
+{
+    FitCheby(1, 1);
+    FitCheby(1, NUM_ROWS);
+    FitCheby(1, 1);
+    FitCheby(NUM_COLS, 1);
+    FitCheby(NUM_COLS, NUM_ROWS);
+}
