- Timestamp:
- Sep 2, 2007, 10:29:50 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20070830/psLib/src/imageops/psImagePixelInterpolate.c
r14724 r14725 11 11 * @author Eugene Magnier, IfA 12 12 * 13 * @version $Revision: 1.1.2. 3$ $Name: not supported by cvs2svn $14 * @date $Date: 2007-09-02 02:42:55$13 * @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2007-09-02 20:29:50 $ 15 15 * 16 16 * Copyright 2007 Institute for Astronomy, University of Hawaii … … 62 62 63 63 // count and mark pixels based on their potential for being interpolated. the input image is 64 // just the mask, the output image is the mask image in which the good, bad, and poor pixels 65 // are marked. 66 // XXX return in the image the state (2nd, which of 4 corners, etc)? 64 // just the mask, the output image contains enum values which define the type of interpolation which 65 // can be performed 67 66 psImage *psImagePixelInterpolateState (int *nBad, int *nPoor, psImage *mask, psMaskType maskVal) { 68 67 … … 99 98 100 99 // interpolate the poor pixels using the available options 101 bool psImagePixelInterpolatePoor (psImage *image, psImage *mask, psMaskType maskVal, psImage *state) { 100 bool psImagePixelInterpolatePoor (psImage *image, psImage *state, psImage *mask, psMaskType maskVal) { 101 102 assert (image->numCols == state->numCols); 103 assert (image->numRows == state->numRows); 104 assert (image->numCols == mask->numCols); 105 assert (image->numRows == mask->numRows); 106 107 // allocate the vectors for the 2nd order fit below 108 psVector *f = psVectorAlloc (9, PS_TYPE_F32); 109 // XXX if we add the weight above, include df 110 // psVector *df = psVectorAlloc (9, PS_TYPE_F32); 111 psVector *x = psVectorAlloc (9, PS_TYPE_F32); 112 psVector *y = psVectorAlloc (9, PS_TYPE_F32); 113 114 // allocate a 2D polynomial to fit a quadratic to the valid neighbor pixels. 115 psPolynomial2D *poly = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 2, 2); 116 poly->mask[2][2] = 1; 117 poly->mask[2][1] = 1; 118 poly->mask[1][2] = 1; 102 119 103 120 for (int iy = 0; iy < state->numRows; iy++) { … … 114 131 115 132 case PS_IMAGE_INTERPOLATE_CENTER: { 116 // fit a quadratic to the valid neighbor pixels 117 // apply the quadratic to get the poor pixel value 118 psPolynomial2D *poly = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 2, 2); 119 poly->mask[2][2] = 1; 120 poly->mask[2][1] = 1; 121 poly->mask[1][2] = 1; 122 psVector *f = psVectorAlloc (9, PS_TYPE_F32); 123 psVector *df = psVectorAlloc (9, PS_TYPE_F32); 124 psVector *x = psVectorAlloc (9, PS_TYPE_F32); 125 psVector *y = psVectorAlloc (9, PS_TYPE_F32); 126 133 // XXX is there a fit-image-region function? 127 134 int n = 0; 128 135 for (int jy = -1; jy <= +1; jy++) { 129 // skip invalid pixels (jx < 0, >= Nx), etc136 // skip invalid pixels 130 137 if (jy + iy < 0) { continue; } 131 138 if (jy + iy >= image->numRows) { continue; } 132 139 for (int jx = -1; jx <= +1; jx++) { 133 // skip invalid pixels (jx < 0, >= Nx), etc140 // skip invalid pixels 134 141 if (jx + ix < 0) { continue; } 135 if (jx + ix >= mask->numCols) { continue; }136 / * skip self */142 if (jx + ix >= image->numCols) { continue; } 143 // skip self 137 144 if (!jx && !jy) { continue; } 138 145 // skip masked pixels 139 if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; } \ 140 f->data.F32[n] = image->data.F32[iy+jy][ix+jx]; 141 // df->data.F32[n] = weight->data.F32[jy][jx]; 146 if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; } 142 147 x->data.F32[n] = jx; 143 148 y->data.F32[n] = jy; 149 f->data.F32[n] = image->data.F32[iy+jy][ix+jx]; 150 // df->data.F32[n] = weight->data.F32[iy+jy][ix+jx]; 144 151 n++; 145 152 } 146 153 } 147 // XXXset vector lengths here154 // set vector lengths here 148 155 x->n = n; 149 156 y->n = n; 150 157 f->n = n; 151 158 // df->n = n; 152 psVectorFitPolynomial2D (poly, mask, maskValue, f, df, x, y); 159 // psVectorFitPolynomial2D (poly, NULL, 0xff, f, df, x, y); 160 psVectorFitPolynomial2D (poly, NULL, 0xff, f, NULL, x, y); 161 // apply the fitted quadratic to get the poor pixel value 153 162 image->data.F32[iy][ix] = poly->coeff[0][0]; 154 163 break; } … … 179 188 } 180 189 } 190 191 psFree (x); 192 psFree (y); 193 psFree (f); 194 195 psFree (poly); 181 196 return true; 182 197 }
Note:
See TracChangeset
for help on using the changeset viewer.
