Changeset 2735 for trunk/psLib/src/image/psImageStats.c
- Timestamp:
- Dec 16, 2004, 11:58:25 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/image/psImageStats.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImageStats.c
r2634 r2735 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.5 8$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-12- 04 19:22:25 $11 * @version $Revision: 1.59 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-12-16 21:58:25 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 174 174 return (chebPolys); 175 175 } 176 177 /*****************************************************************************178 psImageFitPolynomial(): This routine takes as input a 2-D image and produces179 as output the coefficients of the Chebyshev polynomials which match that180 input image.181 Input:182 Output:183 Internal Data Structures:184 chebPolys[i][j]185 sums[i][j]: This will contain the sum of186 input->data.F32[x][y] *187 psPolynomial1DEval(188 chebPolys[i],189 (float) x) *190 psPolynomial1DEval(191 chebPolys[j],192 (float) y,193 );194 over all pixels (x,y) in the image.195 *****************************************************************************/196 psPolynomial2D* psImageFitPolynomialORIG(psPolynomial2D* coeffs,197 const psImage* input)198 {199 PS_IMAGE_CHECK_NULL(input, NULL);200 PS_IMAGE_CHECK_EMPTY(input, NULL);201 if ((input->type.type != PS_TYPE_S8) &&202 (input->type.type != PS_TYPE_U16) &&203 (input->type.type != PS_TYPE_F32) &&204 (input->type.type != PS_TYPE_F64)) {205 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unallowable image type.\n");206 }207 PS_POLY_CHECK_NULL(coeffs, NULL);208 PS_POLY_CHECK_TYPE(coeffs, PS_POLYNOMIAL_CHEB, NULL);209 psS32 x = 0;210 psS32 y = 0;211 psS32 i = 0;212 psS32 j = 0;213 double **sums = NULL;214 psPolynomial1D* *chebPolys = NULL;215 psS32 maxChebyPoly = 0;216 double *cScalingFactors = NULL;217 double *rScalingFactors = NULL;218 219 // Create the sums[][] data structure. This220 // will hold the LHS of221 // equation222 // 29 in the ADD: sums[k][l] = SUM {223 // image(x,y) * Tk(x) * Tl(y) }224 sums = (double **)psAlloc(coeffs->nX * sizeof(double *));225 for (i = 0; i < coeffs->nX; i++) {226 sums[i] = (double *)psAlloc(coeffs->nY * sizeof(double));227 }228 // We scale the pixel positions to values229 // between -1.0 and 1.0230 rScalingFactors = calcScaleFactors(input->numRows);231 cScalingFactors = calcScaleFactors(input->numCols);232 233 // Determine how many Chebyshev polynomials234 // are needed, then create them.235 maxChebyPoly = coeffs->nX;236 if (coeffs->nY > coeffs->nX) {237 maxChebyPoly = coeffs->nY;238 }239 chebPolys = p_psCreateChebyshevPolys(maxChebyPoly);240 241 // Compute the sums[][] data structure.242 for (i = 0; i < coeffs->nX; i++) {243 for (j = 0; j < coeffs->nY; j++) {244 sums[i][j] = 0.0;245 for (x = 0; x < input->numRows; x++) {246 for (y = 0; y < input->numCols; y++) {247 double pixel;248 if (input->type.type == PS_TYPE_S8) {249 pixel = (double) input->data.S8[x][y];250 } else if (input->type.type == PS_TYPE_U16) {251 pixel = (double) input->data.U16[x][y];252 } else if (input->type.type == PS_TYPE_F32) {253 pixel = (double) input->data.F32[x][y];254 } else if (input->type.type == PS_TYPE_F64) {255 pixel = input->data.F64[x][y];256 }257 sums[i][j] += pixel * psPolynomial1DEval(chebPolys[i],rScalingFactors[x]) *258 psPolynomial1DEval(chebPolys[j], cScalingFactors[y]);259 }260 }261 }262 }263 264 for (i = 0; i < coeffs->nX; i++) {265 for (j = 0; j < coeffs->nY; j++) {266 coeffs->coeff[i][j] = sums[i][j];267 coeffs->coeff[i][j] /= (double)(input->numRows * input->numCols);268 269 if ((i != 0) && (j != 0)) {270 coeffs->coeff[i][j] *= 4.0;271 } else if ((i == 0) && (j == 0)) {272 coeffs->coeff[i][j] *= 1.0;273 } else {274 coeffs->coeff[i][j] *= 2.0;275 }276 }277 }278 279 // Free the Chebyshev polynomials that were280 // created in this routine.281 for (i = 0; i < maxChebyPoly; i++) {282 psFree(chebPolys[i]);283 }284 psFree(chebPolys);285 286 // Free some data287 for (i = 0; i < coeffs->nX; i++) {288 psFree(sums[i]);289 }290 psFree(sums);291 psFree(cScalingFactors);292 psFree(rScalingFactors);293 294 return (coeffs);295 }296 297 298 299 176 300 177 /***************************************************************************** … … 339 216 double *cScalingFactors = NULL; 340 217 double *rScalingFactors = NULL; 218 219 // Create the sums[][] data structure. This 220 // will hold the LHS of 221 // equation 222 // 29 in the ADD: sums[k][l] = SUM { 223 // image(x,y) * Tk(x) * Tl(y) } 224 sums = (double **)psAlloc(coeffs->nX * sizeof(double *)); 225 for (i = 0; i < coeffs->nX; i++) { 226 sums[i] = (double *)psAlloc(coeffs->nY * sizeof(double)); 227 } 228 // We scale the pixel positions to values 229 // between -1.0 and 1.0 230 rScalingFactors = calcScaleFactors(input->numRows); 231 cScalingFactors = calcScaleFactors(input->numCols); 232 233 // Determine how many Chebyshev polynomials 234 // are needed, then create them. 235 maxChebyPoly = coeffs->nX; 236 if (coeffs->nY > coeffs->nX) { 237 maxChebyPoly = coeffs->nY; 238 } 239 chebPolys = p_psCreateChebyshevPolys(maxChebyPoly); 240 241 // Compute the sums[][] data structure. 242 for (i = 0; i < coeffs->nX; i++) { 243 for (j = 0; j < coeffs->nY; j++) { 244 sums[i][j] = 0.0; 245 for (x = 0; x < input->numRows; x++) { 246 for (y = 0; y < input->numCols; y++) { 247 double pixel; 248 if (input->type.type == PS_TYPE_S8) { 249 pixel = (double) input->data.S8[x][y]; 250 } else if (input->type.type == PS_TYPE_U16) { 251 pixel = (double) input->data.U16[x][y]; 252 } else if (input->type.type == PS_TYPE_F32) { 253 pixel = (double) input->data.F32[x][y]; 254 } else if (input->type.type == PS_TYPE_F64) { 255 pixel = input->data.F64[x][y]; 256 } 257 sums[i][j] += pixel * psPolynomial1DEval(chebPolys[i],rScalingFactors[x]) * 258 psPolynomial1DEval(chebPolys[j], cScalingFactors[y]); 259 } 260 } 261 } 262 } 263 264 for (i = 0; i < coeffs->nX; i++) { 265 for (j = 0; j < coeffs->nY; j++) { 266 coeffs->coeff[i][j] = sums[i][j]; 267 coeffs->coeff[i][j] /= (double)(input->numRows * input->numCols); 268 269 if ((i != 0) && (j != 0)) { 270 coeffs->coeff[i][j] *= 4.0; 271 } else if ((i == 0) && (j == 0)) { 272 coeffs->coeff[i][j] *= 1.0; 273 } else { 274 coeffs->coeff[i][j] *= 2.0; 275 } 276 } 277 } 278 279 // Free the Chebyshev polynomials that were 280 // created in this routine. 281 for (i = 0; i < maxChebyPoly; i++) { 282 psFree(chebPolys[i]); 283 } 284 psFree(chebPolys); 285 286 // Free some data 287 for (i = 0; i < coeffs->nX; i++) { 288 psFree(sums[i]); 289 } 290 psFree(sums); 291 psFree(cScalingFactors); 292 psFree(rScalingFactors); 293 294 return (coeffs); 295 } 296 297 298 299 300 /***************************************************************************** 301 psImageFitPolynomial(): This routine takes as input a 2-D image and produces 302 as output the coefficients of the Chebyshev polynomials which match that 303 input image. 304 Input: 305 Output: 306 Internal Data Structures: 307 chebPolys[i][j] 308 sums[i][j]: This will contain the sum of 309 input->data.F32[x][y] * 310 psPolynomial1DEval( 311 chebPolys[i], 312 (float) x) * 313 psPolynomial1DEval( 314 chebPolys[j], 315 (float) y, 316 ); 317 over all pixels (x,y) in the image. 318 *****************************************************************************/ 319 psPolynomial2D* psImageFitPolynomialHMMM(psPolynomial2D* coeffs, 320 const psImage* input) 321 { 322 PS_IMAGE_CHECK_NULL(input, NULL); 323 PS_IMAGE_CHECK_EMPTY(input, NULL); 324 if ((input->type.type != PS_TYPE_S8) && 325 (input->type.type != PS_TYPE_U16) && 326 (input->type.type != PS_TYPE_F32) && 327 (input->type.type != PS_TYPE_F64)) { 328 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unallowable image type.\n"); 329 } 330 PS_POLY_CHECK_NULL(coeffs, NULL); 331 PS_POLY_CHECK_TYPE(coeffs, PS_POLYNOMIAL_CHEB, NULL); 332 psS32 x = 0; 333 psS32 y = 0; 334 psS32 i = 0; 335 psS32 j = 0; 336 double **sums = NULL; 337 psPolynomial1D* *chebPolys = NULL; 338 psS32 maxChebyPoly = 0; 339 double *cScalingFactors = NULL; 340 double *rScalingFactors = NULL; 341 341 psImage *nodes = psImageAlloc(input->numCols, input->numRows, PS_TYPE_F64); 342 342
Note:
See TracChangeset
for help on using the changeset viewer.
