Changeset 773 for trunk/psLib/src/image/psImageStats.c
- Timestamp:
- May 24, 2004, 4:10:41 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/image/psImageStats.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImageStats.c
r767 r773 1 #include <stdlib.h> 2 #include <stdio.h> 3 #include <string.h> 4 #include <stdarg.h> 5 #include <float.h> 6 #include <math.h> 7 8 #include "psMemory.h" 9 #include "psVector.h" 10 #include "psTrace.h" 11 #include "psError.h" 12 #include "psAbort.h" 13 #include "psStats.h" 14 #include "psSort.h" 15 #include "psImage.h" 16 #include "psFunctions.h" 17 18 #include "float.h" 19 #include <math.h> 1 20 /// This routine must determine the various statistics for the image. 2 21 psStats * … … 4 23 psStats *stats) 5 24 { 6 if (input->type.typr == PS_TYPE_UINT8) { 7 return(psArrayStats(input->data.u8, NULL, 0xffffffff, stats)); 8 } else if (input->type.typr == PS_TYPE_UINT16) { 9 return(psArrayStats(input->data.u16, NULL, 0xffffffff, stats)); 10 } else if (input->type.typr == PS_TYPE_FLOAT) { 11 return(psArrayStats(input->data.F32, NULL, 0xffffffff, stats)); 12 } else if (input->type.typr == PS_TYPE_DOUBLE) { 13 return(psArrayStats(input->data.F64, NULL, 0xffffffff, stats)); 14 } 25 psVector *junk=NULL; 26 27 junk = psVectorAlloc(input->numRows * input->numCols, input->type.type); 28 return(psArrayStats(junk, NULL, 0xffffffff, stats)); 15 29 } 16 17 30 18 31 psHistogram * 19 32 psImageHistogram(psHistogram *hist, 20 33 const psImage *input) 21 {} 34 { 35 return(hist); 36 } 22 37 38 39 /***************************************************************************** 40 psImageFitPolynomial(): 41 This routine takes as input a 2-D image and produces as output 42 the coefficients of the Chebyshev polynomials which match that 43 input image. 44 Input: 45 Output: 46 Internal Data Structures: 47 chebPolys[i][j] 48 49 *****************************************************************************/ 23 50 psPolynomial2D * 24 51 psImageFitPolynomial(const psImage *input, 25 psPolynomial2D *coeffs); 26 {} 52 psPolynomial2D *coeffs) 53 { 54 int x = 0; 55 int y = 0; 56 int i = 0; 57 int j = 0; 58 float **sums = NULL; 59 psPolynomial1D **chebPolys = NULL; 60 int maxChebyPoly = 0; 61 62 // Create the sums[][] data structure. This will hold the LHS of equation 63 // 29 in the ADD: sums[k][l] = SUM { image(x,y) * Tk(x) * Tl(y) } 64 sums = (float **) psAlloc(coeffs->nX * sizeof(float *)); 65 for (i=0;i<coeffs->nX;i++) { 66 sums[i] = (float *) psAlloc(coeffs->nY * sizeof(float)); 67 } 68 for (i=0;i<coeffs->nX;i++) { 69 for (j=0;j<coeffs->nY;j++) { 70 sums[i][j] = 0.0; 71 } 72 } 73 74 // Determine how many Chebyshev polynomials are needed, then create them. 75 maxChebyPoly = coeffs->nX; 76 if (coeffs->nX > coeffs->nY) { 77 maxChebyPoly = coeffs->nY; 78 } 79 80 chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * 81 sizeof(psPolynomial1D *)); 82 for (i=0;i<maxChebyPoly;i++) { 83 chebPolys[i] = psPolynomial1DAlloc(i); 84 } 85 86 // Create the Chebyshev polynomials 87 chebPolys[1]->coeff[0] = 1; 88 for (i=2;i<maxChebyPoly;i++) { 89 for (j=0;j<chebPolys[i-1]->n;j++) { 90 chebPolys[i]->coeff[j+1] = 2 * chebPolys[i-1]->coeff[j]; 91 } 92 for (j=0;j<chebPolys[i-2]->n;j++) { 93 chebPolys[i]->coeff[j]-= chebPolys[i-2]->coeff[j]; 94 } 95 } 96 97 for (x=0;x<input->numRows;x++) { 98 for (y=0;y<input->numCols;y++) { 99 for (i=0;i<coeffs->nX;i++) { 100 for (j=0;j<coeffs->nY;j++) { 101 sums[i][j]+= input->data.F32[x][y] * 102 psEvalPolynomial1D((float) x, chebPolys[i]) * 103 psEvalPolynomial1D((float) y, chebPolys[j]); 104 } 105 } 106 } 107 } 108 109 110 coeffs->coeff[0][0] = sums[0][0] / (coeffs->nX * coeffs->nY); 111 for (i=0;i<coeffs->nX;i++) { 112 coeffs->coeff[i][0] = 0.5 * 113 ((sums[i][0] * 4.0) / (coeffs->nX * coeffs->nY)) - 114 (2.0 * coeffs->coeff[0][0]); 115 } 116 for (j=0;j<coeffs->nY;j++) { 117 coeffs->coeff[0][j] = 0.5 * 118 ((sums[0][j] * 4.0) / (coeffs->nX * coeffs->nY)) - 119 (2.0 * coeffs->coeff[0][0]); 120 } 121 for (i=1;i<coeffs->nX;i++) { 122 for (j=1;j<coeffs->nY;j++) { 123 coeffs->coeff[i][j] = 124 (sums[i][0] * 4.0) / (coeffs->nX * coeffs->nY) - 125 coeffs->coeff[0][0] - 126 coeffs->coeff[i][0] - 127 coeffs->coeff[0][j]; 128 } 129 } 130 return(coeffs); 131 } 27 132 28 133 int 29 134 psImageEvalPolynomial(const psImage *input, 30 const psPolynomial2D *coeffs); 31 {} 135 const psPolynomial2D *coeffs) 136 { 137 return(0); 138 }
Note:
See TracChangeset
for help on using the changeset viewer.
