Changeset 25753
- Timestamp:
- Oct 2, 2009, 3:04:33 PM (17 years ago)
- Location:
- trunk/psLib/src/imageops
- Files:
-
- 6 edited
-
psImageMap.c (modified) (1 diff)
-
psImageMap.h (modified) (1 diff)
-
psImageMapFit.c (modified) (2 diffs)
-
psImageMapFit.h (modified) (1 diff)
-
psImageMaskOps.c (modified) (1 diff)
-
psImageMaskOps.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageMap.c
r23989 r25753 386 386 return result; 387 387 } 388 389 bool psImageMapCleanup (psImageMap *map) { 390 391 if ((map->map->numRows == 1) && (map->map->numCols == 1)) return true; 392 393 // find the weighted average of all pixels 394 float Sum = 0.0; 395 float Wt = 0.0; 396 for (int j = 0; j < map->map->numRows; j++) { 397 for (int i = 0; i < map->map->numCols; i++) { 398 if (!isfinite(map->map->data.F32[j][i])) continue; 399 Sum += map->map->data.F32[j][i] * map->error->data.F32[j][i]; 400 Wt += map->error->data.F32[j][i]; 401 } 402 } 403 404 float Mean = Sum / Wt; 405 406 // do any of the pixels in the map need to be repaired? 407 // XXX for now, we are just replacing bad pixels with the Mean 408 for (int j = 0; j < map->map->numRows; j++) { 409 for (int i = 0; i < map->map->numCols; i++) { 410 if (isfinite(map->map->data.F32[j][i]) && 411 (map->error->data.F32[j][i] > 0.0)) continue; 412 map->map->data.F32[j][i] = Mean; 413 } 414 } 415 return true; 416 } 417 -
trunk/psLib/src/imageops/psImageMap.h
r21172 r25753 79 79 psVector *psImageMapEvalVector (const psImageMap *map, const psVector *mask, psMaskType maskValue, const psVector *x, const psVector *y); 80 80 81 bool psImageMapCleanup (psImageMap *map); 82 81 83 /// @} 82 84 #endif // #ifndef PS_IMAGE_MAP_H -
trunk/psLib/src/imageops/psImageMapFit.c
r24091 r25753 33 33 #include "psStats.h" 34 34 #include "psImageBinning.h" 35 #include "psImageStructManip.h" 35 36 #include "psImageMap.h" 36 37 // #include "psImagePixelInterpolate.h" … … 752 753 } 753 754 755 // this function repairs an image with NAN pixels (only valid for a small-scale map -- no robust mean) 756 bool psImageMapRepair (psImage *image) { 757 758 // we are going to repair the image by: 759 // 1) finding NAN pixels 760 // 2) if any of the neighbors are valid, 761 // replace with the mean of the neighbors 762 // 3) otherwise, replace with the image mean 763 764 // copy the image so the repaired pixels do not affect the input 765 psImage *fixed = psImageCopy (NULL, image, PS_TYPE_F32); 766 767 // find the global mean 768 float mean = 0.0; 769 float npix = 0.0; 770 for (int iy = 0; iy < image->numRows; iy++) { 771 for (int ix = 0; ix < image->numCols; ix++) { 772 if (!isfinite(image->data.F32[iy][ix])) continue; 773 mean += image->data.F32[iy][ix]; 774 npix += 1.0; 775 } 776 } 777 mean /= npix; 778 779 // find the NAN pixels: 780 for (int iy = 0; iy < image->numRows; iy++) { 781 for (int ix = 0; ix < image->numCols; ix++) { 782 if (isfinite(image->data.F32[iy][ix])) { 783 fixed->data.F32[iy][ix] = image->data.F32[iy][ix]; 784 continue; 785 } 786 787 // find mean of all possible neighbors 788 float meanLocal = 0.0; 789 float npixLocal = 0.0; 790 for (int jy = -1; jy <= +1; jy++) { 791 int ny = iy + jy; 792 if (ny < 0) continue; 793 if (ny >= image->numRows) continue; 794 for (int jx = -1; jx <= +1; jx++) { 795 int nx = ix + jx; 796 if (nx < 0) continue; 797 if (nx >= image->numCols) continue; 798 if (!isfinite(image->data.F32[ny][nx])) continue; 799 meanLocal += image->data.F32[ny][nx]; 800 npixLocal += 1.0; 801 } 802 } 803 meanLocal = (npixLocal > 0.0) ? meanLocal / npixLocal : mean; 804 fixed->data.F32[iy][ix] = meanLocal; 805 } 806 } 807 808 // find the NAN pixels: 809 for (int iy = 0; iy < image->numRows; iy++) { 810 for (int ix = 0; ix < image->numCols; ix++) { 811 image->data.F32[iy][ix] = fixed->data.F32[iy][ix]; 812 } 813 } 814 psFree (fixed); 815 816 return true; 817 } -
trunk/psLib/src/imageops/psImageMapFit.h
r21183 r25753 46 46 ); 47 47 48 bool psImageMapRepair (psImage *image); 49 48 50 #endif -
trunk/psLib/src/imageops/psImageMaskOps.c
r21183 r25753 223 223 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 224 224 "The logical operation specified is incorrect\n"); 225 return; 226 } 227 228 // perform the mask operation on the image pixels 229 void psImageMaskPixels(psImage *image, 230 const char *op, 231 psImageMaskType maskValue) 232 { 233 if (image == NULL) { 234 psError(PS_ERR_BAD_PARAMETER_NULL, true, "Invalid image input. Image is NULL.\n"); 235 return; 236 } 237 238 # define MASK_IT_IMAGE(OP) \ 239 for (int iy = 0; iy < image->numRows; iy++) { \ 240 for (int ix = 0; ix < image->numCols; ix++) { \ 241 image->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] OP maskValue; \ 242 } } 243 244 if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) { 245 MASK_IT_IMAGE (&=); 246 return; 247 } 248 if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) { 249 MASK_IT_IMAGE (|=); 250 return; 251 } 252 if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) { 253 MASK_IT_IMAGE (=); 254 return; 255 } 256 if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) { 257 MASK_IT_IMAGE (^=); 258 return; 259 } 260 261 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "The logical operation specified is incorrect\n"); 225 262 return; 226 263 } -
trunk/psLib/src/imageops/psImageMaskOps.h
r21183 r25753 22 22 #include "psStats.h" 23 23 #include "psPixels.h" 24 25 /** Perform the mask opertion on all image pixels 26 * 27 * The pixels are set by combining the existing pixel value and the given maskValue 28 * with a logical operation. The allowed operations are =, AND, OR, and XOR. 29 */ 30 void psImageMaskPixels(psImage *image, 31 const char *op, 32 psImageMaskType maskValue); 24 33 25 34 /** Sets the bits inside the region, ignoring pixels outside.
Note:
See TracChangeset
for help on using the changeset viewer.
