IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 3, 2007, 10:29:07 AM (19 years ago)
Author:
magnier
Message:

updates to image map code, tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070830/psLib/src/imageops/psImagePixelInterpolate.c

    r14725 r14726  
    1111 *  @author Eugene Magnier, IfA
    1212 *
    13  *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2007-09-02 20:29:50 $
     13 *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2007-09-03 20:29:07 $
    1515 *
    1616 *  Copyright 2007 Institute for Astronomy, University of Hawaii
     
    163163                  break; }
    164164
     165                // XXX should I use 1 1D polynomial fitting all unmasked pixels in the 3x3 grid?
     166                // XXX that would automatically extend to regions where only 2 pixels are valid...
    165167              case PS_IMAGE_INTERPOLATE_LL: {
    166168                  // fit a plane to the 3 pixels at (0,1),(1,0),(1,1), extend to pixel at (0,0)
     
    196198    return true;
    197199}
    198 
    199200   
     201// interpolate the good pixels to their true centers
     202bool psImagePixelInterpolateCenter (psImage *value, psImage *xCoord, psImage *yCoord, psImage *state, psImage *mask, psMaskType maskVal) {
     203
     204    assert (value->numCols == state->numCols);
     205    assert (value->numRows == state->numRows);
     206    assert (value->numCols == mask->numCols);
     207    assert (value->numRows == mask->numRows);
     208
     209    psImage *output = psImageAlloc (value->numCols, value->numRows, PS_TYPE_F32);
     210
     211    // allocate the vectors for the 2nd order fit below
     212    psVector *f  = psVectorAlloc (9, PS_TYPE_F32);
     213    // XXX if we add the weight above, include df
     214    // psVector *df = psVectorAlloc (9, PS_TYPE_F32);
     215    psVector *x  = psVectorAlloc (9, PS_TYPE_F32);
     216    psVector *y  = psVectorAlloc (9, PS_TYPE_F32);
     217
     218    // allocate a 2D polynomial to fit a quadratic to the valid neighbor pixels.
     219    psPolynomial2D *poly2D = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 2, 2);
     220    poly2D->mask[2][2] = 1;
     221    poly2D->mask[2][1] = 1;
     222    poly2D->mask[1][2] = 1;
     223
     224    // allocate a 2D polynomial to fit a plane to the valid neighbor pixels.
     225    psPolynomial2D *poly1D = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 1, 1);
     226    poly2D->mask[1][1] = 1;
     227
     228    for (int iy = 0; iy < state->numRows; iy++) {
     229        for (int ix = 0; ix < state->numCols; ix++) {
     230
     231            switch (state->data.S32[iy][ix]) {
     232              case PS_IMAGE_INTERPOLATE_GOOD2: {
     233                  // XXX is there a fit-image-region function?
     234                  int n = 0;
     235                  for (int jy = -1; jy <= +1; jy++) {
     236                      // skip invalid pixels
     237                      if (jy + iy < 0) { continue; }
     238                      if (jy + iy >= value->numRows) { continue; }
     239                      for (int jx = -1; jx <= +1; jx++) {
     240                          // skip invalid pixels
     241                          if (jx + ix < 0) { continue; }
     242                          if (jx + ix >= value->numCols) { continue; }
     243                          // skip masked pixels
     244                          if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
     245                          x->data.F32[n] = xCoord->data.F32[iy+jy][ix+jx];
     246                          y->data.F32[n] = yCoord->data.F32[iy+jy][ix+jx];
     247                          f->data.F32[n] = value->data.F32[iy+jy][ix+jx];
     248                          // df->data.F32[n] = weight->data.F32[iy+jy][ix+jx];
     249                          n++;
     250                      }
     251                  }
     252                  // set vector lengths here
     253                  x->n = n;
     254                  y->n = n;
     255                  f->n = n;
     256                  // df->n = n;
     257                  // psVectorFitPolynomial2D (poly, NULL, 0xff, f, df, x, y);
     258                  psVectorFitPolynomial2D (poly2D, NULL, 0xff, f, NULL, x, y);
     259                  // apply the fitted quadratic to get the poor pixel value
     260                  output->data.F32[iy][ix] = psPolynomial2DEval (poly2D, ix, iy);
     261                  break; }
     262
     263              case PS_IMAGE_INTERPOLATE_GOOD1: {
     264                  // XXX is there a fit-image-region function?
     265                  int n = 0;
     266                  for (int jy = -1; jy <= +1; jy++) {
     267                      // skip invalid pixels
     268                      if (jy + iy < 0) { continue; }
     269                      if (jy + iy >= value->numRows) { continue; }
     270                      for (int jx = -1; jx <= +1; jx++) {
     271                          // skip invalid pixels
     272                          if (jx + ix < 0) { continue; }
     273                          if (jx + ix >= value->numCols) { continue; }
     274                          // skip masked pixels
     275                          if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
     276                          x->data.F32[n] = xCoord->data.F32[iy+jy][ix+jx];
     277                          y->data.F32[n] = yCoord->data.F32[iy+jy][ix+jx];
     278                          f->data.F32[n] = value->data.F32[iy+jy][ix+jx];
     279                          // df->data.F32[n] = weight->data.F32[iy+jy][ix+jx];
     280                          n++;
     281                      }
     282                  }
     283                  // set vector lengths here
     284                  x->n = n;
     285                  y->n = n;
     286                  f->n = n;
     287                  // df->n = n;
     288                  // psVectorFitPolynomial2D (poly1D, NULL, 0xff, f, df, x, y);
     289                  psVectorFitPolynomial2D (poly1D, NULL, 0xff, f, NULL, x, y);
     290                  // apply the fitted quadratic to get the poor pixel value
     291                  output->data.F32[iy][ix] = psPolynomial2DEval (poly1D, ix, iy);
     292                  break; }
     293
     294              case PS_IMAGE_INTERPOLATE_GOOD0: {
     295                  output->data.F32[iy][ix] = value->data.F32[iy+jy][ix+jx];
     296                  break; }
     297
     298              default:
     299                psAbort("impossible case in __func__");
     300            }
     301        }           
     302    }
     303
     304    for (int iy = 0; iy < value->numRows; iy++) {
     305        for (int ix = 0; ix < value->numCols; ix++) {
     306          if (mask->data.PS_TYPE_MASK_DATA[iy][ix] & maskVal) { continue; }
     307          value->data.F32[iy][ix] = output->data.F32[iy][ix];
     308        }
     309    }
     310
     311    psFree (x);
     312    psFree (y);
     313    psFree (f);
     314
     315    psFree (poly2D);
     316    psFree (poly1D);
     317
     318    psFree (output);
     319    return true;
     320}
Note: See TracChangeset for help on using the changeset viewer.