- Timestamp:
- Sep 15, 2007, 9:43:43 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20070830/psLib/src/imageops/psImageUnbin.c
r12588 r14859 7 7 * @author Eugene Magnier, IfA 8 8 * 9 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $10 * @date $Date: 2007-0 3-27 02:43:22$9 * @version $Revision: 1.7.8.1 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-09-15 19:43:43 $ 11 11 * 12 12 * Copyright 2007 Institute for Astronomy, University of Hawaii … … 205 205 * N.b. This code only works for the central part of the image; the edge 206 206 * cases should be added 207 208 * XXXX this is bilinear interpolation, but written sub-optimally 209 * XXXX this function should be taking float input coordinates!!! 207 210 */ 208 211 double psImageUnbinPixel(const int ix, const int iy, // desired Unbinned point (parent coords) … … 249 252 return Vxs + (Vxe - Vxs)*(ix - xs)/DX; // value at [iy][ix] 250 253 } 254 255 double psImageUnbinPixel_V2(const double xFine, const double yFine, // desired Unbinned point (parent coords) 256 const psImage *in, // binned image 257 const psImageBinning *binning) //!< Overhang 258 { 259 PS_ASSERT_IMAGE_NON_NULL(in, NAN); 260 assert (in->type.type == PS_TYPE_F32); 261 262 const float xRuff = psImageBinningGetRuffX (binning, xFine); 263 const float yRuff = psImageBinningGetRuffY (binning, yFine); 264 265 const double value = psImageInterpolatePixelBilinear (xRuff, yRuff, in); 266 267 return value; 268 } 269 270 // fast & simple API to interpolate to a subpixel position using bilinear interpolation 271 // x,y in parent image coordinates (pixel centers at 0.5, 0.5) 272 double psImageInterpolatePixelBilinear (const double xIn, const double yIn, const psImage *in) { 273 274 PS_ASSERT_PTR_NON_NULL(in, PS_ERR_BAD_PARAMETER_VALUE); 275 assert (in->type.type == PS_TYPE_F32); 276 277 const double x = xIn - in->col0; 278 const double y = yIn - in->row0; 279 280 // allow extrapolation to edge of valid pixels, but not beyond 281 if ((x < 0) || (x >= in->numCols) || (y < 0) || (y >= in->numRows)) { 282 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Point (%f,%f) lies outside binned image", x, y); 283 return NAN; 284 } 285 286 // handle edge cases with extrapolation 287 288 const int ix = x - 0.5; // index of reference pixel 289 const int iy = y - 0.5; // index of reference pixel 290 291 const int Xs = PS_MAX (PS_MIN (ix, in->numCols - 2), 0); 292 const int Ys = PS_MAX (PS_MIN (iy, in->numRows - 2), 0); 293 294 const int Xe = Xs + 1; 295 const int Ye = Ys + 1; 296 297 // dx,dy range from 0.0 to 1.0 for interpolated pixels, and -0.5 to 1.5 for extrapolation 298 const double dx = x - 0.5 - Xs; 299 const double dy = y - 0.5 - Ys; 300 301 const double rx = 1.0 - dx; 302 const double ry = 1.0 - dy; 303 304 // Vxy 305 double V00 = in->data.F32[Ys][Xs]; 306 double V10 = in->data.F32[Ys][Xe]; 307 double V01 = in->data.F32[Ye][Xs]; 308 double V11 = in->data.F32[Ye][Xe]; 309 310 // bilinear interpolation 311 const double value = V00*rx*ry + V10*rx*dy + V01*dx*ry + V11*dx*dy; 312 313 return value; 314 } 315 316
Note:
See TracChangeset
for help on using the changeset viewer.
