- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psLib/src/imageops/psImageMapFit.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/psLib/src/imageops/psImageMapFit.c
r24091 r27840 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 }
Note:
See TracChangeset
for help on using the changeset viewer.
