IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25694


Ignore:
Timestamp:
Sep 30, 2009, 2:33:50 PM (17 years ago)
Author:
eugene
Message:

add a function to repair NAN pixels in a psImageMap

Location:
branches/eam_branches/20090715/psLib/src/imageops
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090715/psLib/src/imageops/psImageMapFit.c

    r24091 r25694  
    3333#include "psStats.h"
    3434#include "psImageBinning.h"
     35#include "psImageStructManip.h"
    3536#include "psImageMap.h"
    3637// #include "psImagePixelInterpolate.h"
     
    752753}
    753754
     755// this function repairs an image with NAN pixels (only valid for a small-scale map -- no robust mean)
     756bool 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}
  • branches/eam_branches/20090715/psLib/src/imageops/psImageMapFit.h

    r21183 r25694  
    4646    );
    4747
     48bool psImageMapRepair (psImage *image);
     49
    4850#endif
Note: See TracChangeset for help on using the changeset viewer.