IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25753


Ignore:
Timestamp:
Oct 2, 2009, 3:04:33 PM (17 years ago)
Author:
eugene
Message:

add psImageMaskPixels, psImageMapCleanup, psImageMapRepair

Location:
trunk/psLib/src/imageops
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageMap.c

    r23989 r25753  
    386386    return result;
    387387}
     388
     389bool 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  
    7979psVector *psImageMapEvalVector (const psImageMap *map, const psVector *mask, psMaskType maskValue, const psVector *x, const psVector *y);
    8080
     81bool psImageMapCleanup (psImageMap *map);
     82
    8183/// @}
    8284#endif // #ifndef PS_IMAGE_MAP_H
  • trunk/psLib/src/imageops/psImageMapFit.c

    r24091 r25753  
    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}
  • trunk/psLib/src/imageops/psImageMapFit.h

    r21183 r25753  
    4646    );
    4747
     48bool psImageMapRepair (psImage *image);
     49
    4850#endif
  • trunk/psLib/src/imageops/psImageMaskOps.c

    r21183 r25753  
    223223    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
    224224            "The logical operation specified is incorrect\n");
     225    return;
     226}
     227
     228// perform the mask operation on the image pixels
     229void 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");
    225262    return;
    226263}
  • trunk/psLib/src/imageops/psImageMaskOps.h

    r21183 r25753  
    2222#include "psStats.h"
    2323#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 */
     30void psImageMaskPixels(psImage *image,
     31                       const char *op,
     32                       psImageMaskType maskValue);
    2433
    2534/** Sets the bits inside the region, ignoring pixels outside.
Note: See TracChangeset for help on using the changeset viewer.