- Timestamp:
- Dec 20, 2010, 4:25:10 PM (16 years ago)
- Location:
- branches/czw_branch/20101203
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psLib/src/fits/psFitsScale.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20101203
- Property svn:mergeinfo changed (with no actual effect on merging)
-
branches/czw_branch/20101203/psLib/src/fits/psFitsScale.c
r27417 r30119 100 100 } 101 101 102 102 103 // Determine appropriate BSCALE and BZERO for an image, mapping the standard deviation to the nominated number 103 104 // of bits … … 237 238 } 238 239 240 241 static bool logscaleStdev(double *bscale, // Scaling, to return 242 double *bzero, // Zero point, to return 243 const psImage *image, // Image to scale 244 const psImage *mask, // Mask image 245 psImageMaskType maskVal, // Value to mask 246 const psFitsOptions *options // FITS options 247 ) 248 { 249 psAssert(bscale, "impossible"); 250 psAssert(bzero, "impossible"); 251 psAssert(image, "impossible"); 252 psAssert(options, "impossible"); 253 254 psTrace("psLib.fits", 3, "Scaling image by logarithm statistics"); 255 int numCols = image->numCols, numRows = image->numRows; // Size of image 256 257 double offset = 99e99; 258 259 // Determine the minimum value on this image. 260 switch (image->type.type) { 261 case PS_TYPE_F32: 262 for (int y = 0; y < numRows; y++) { 263 for (int x = 0; x < numCols; x++) { 264 psF32 value = image->data.F32[y][x]; 265 if (!isfinite(value)) { 266 if (value < offset) { 267 offset = value; 268 } 269 } 270 } 271 } 272 break; 273 case PS_TYPE_F64: 274 for (int y = 0; y < numRows; y++) { 275 for (int x = 0; x < numCols; x++) { 276 psF64 value = image->data.F64[y][x]; 277 if (!isfinite(value)) { 278 if (value < offset) { 279 offset = value; 280 } 281 } 282 } 283 } 284 break; 285 default: 286 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Target type is not a float: %d",image->type.type); 287 return NULL; 288 break; 289 } 290 // We only need to offset images that go negative. 291 if (offset > 0.0) { 292 offset = 0.0; 293 } 294 // Write offset to header 295 // How? 296 // psMetadataAddF32(header,PS_LIST_TAIL,"LOGZERO",0,"Flux offset subtracted before taking logarithm.",offset); 297 // Take the logarithm of the image, applying the offset 298 switch (image->type.type) { 299 case PS_TYPE_F32: 300 for (int y = 0; y < numRows; y++) { 301 for (int x = 0; x < numCols; x++) { 302 image->data.F32[y][x] = (log10( image->data.F32[y][x] - offset)); 303 } 304 } 305 break; 306 case PS_TYPE_F64: 307 for (int y = 0; y < numRows; y++) { 308 for (int x = 0; x < numCols; x++) { 309 image->data.F64[y][x] = (log10( image->data.F64[y][x] - offset)); 310 } 311 } 312 break; 313 default: 314 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Target type is not a float: %d",image->type.type); 315 return NULL; 316 break; 317 } 318 319 // Do regular scaling on the logarithm image 320 if (!scaleStdev(bscale, bzero, image, mask, maskVal, options)) { 321 psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from stdev"); 322 return false; 323 } 324 return true; 325 } 326 327 static bool logscaleRange(double *bscale, // Scaling, to return 328 double *bzero, // Zero point, to return 329 const psImage *image, // Image to scale 330 const psFitsOptions *options // FITS options 331 ) 332 { 333 psAssert(bscale, "impossible"); 334 psAssert(bzero, "impossible"); 335 psAssert(image, "impossible"); 336 psAssert(options, "impossible"); 337 338 psTrace("psLib.fits", 3, "Scaling image by logarithm statistics"); 339 int numCols = image->numCols, numRows = image->numRows; // Size of image 340 341 double offset = 99e99; 342 343 // Determine the minimum value on this image. 344 switch (image->type.type) { 345 case PS_TYPE_F32: 346 for (int y = 0; y < numRows; y++) { 347 for (int x = 0; x < numCols; x++) { 348 psF32 value = image->data.F32[y][x]; 349 if (!isfinite(value)) { 350 if (value < offset) { 351 offset = value; 352 } 353 } 354 } 355 } 356 break; 357 case PS_TYPE_F64: 358 for (int y = 0; y < numRows; y++) { 359 for (int x = 0; x < numCols; x++) { 360 psF64 value = image->data.F64[y][x]; 361 if (!isfinite(value)) { 362 if (value < offset) { 363 offset = value; 364 } 365 } 366 } 367 } 368 break; 369 default: 370 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Target type is not a float: %d",image->type.type); 371 return NULL; 372 break; 373 } 374 // We only need to offset images that go negative. 375 if (offset > 0.0) { 376 offset = 0.0; 377 } 378 // Write offset to header 379 // How? 380 // psMetadataAddF32(header,PS_LIST_TAIL,"LOGZERO",0,"Flux offset subtracted before taking logarithm.",offset); 381 // Take the logarithm of the image, applying the offset 382 switch (image->type.type) { 383 case PS_TYPE_F32: 384 for (int y = 0; y < numRows; y++) { 385 for (int x = 0; x < numCols; x++) { 386 image->data.F32[y][x] = (log10( image->data.F32[y][x] - offset)); 387 } 388 } 389 break; 390 case PS_TYPE_F64: 391 for (int y = 0; y < numRows; y++) { 392 for (int x = 0; x < numCols; x++) { 393 image->data.F64[y][x] = (log10( image->data.F64[y][x] - offset)); 394 } 395 } 396 break; 397 default: 398 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Target type is not a float: %d",image->type.type); 399 return NULL; 400 break; 401 } 402 403 // Do regular scaling on the logarithm image 404 if (!scaleRange(bscale, bzero, image, options)) { 405 psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from stdev"); 406 return false; 407 } 408 return true; 409 } 410 411 239 412 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 240 413 // Public functions … … 295 468 case PS_FITS_SCALE_STDEV_BOTH: 296 469 if (!scaleStdev(bscale, bzero, image, mask, maskVal, options)) { 470 psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from stdev"); 471 return false; 472 } 473 break; 474 case PS_FITS_SCALE_LOG_RANGE: 475 if (!logscaleRange(bscale,bzero,image,options)) { 476 psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from range"); 477 return false; 478 } 479 break; 480 case PS_FITS_SCALE_LOG_STDEV_POSITIVE: 481 case PS_FITS_SCALE_LOG_STDEV_NEGATIVE: 482 case PS_FITS_SCALE_LOG_STDEV_BOTH: 483 if (!logscaleStdev(bscale, bzero, image, mask, maskVal, options)) { 297 484 psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from stdev"); 298 485 return false;
Note:
See TracChangeset
for help on using the changeset viewer.
