Changeset 14925
- Timestamp:
- Sep 20, 2007, 1:55:52 PM (19 years ago)
- Location:
- trunk/psLib/src/imageops
- Files:
-
- 2 edited
-
psImageUnbin.c (modified) (3 diffs)
-
psImageUnbin.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageUnbin.c
r12588 r14925 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.8 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-09-20 23:55:50 $ 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 // limiting cases: Nx == 1 and/or Ny == 1 287 288 // if we have a single pixel, there is no spatial information 289 if ((in->numCols == 1) && (in->numRows == 1)) { 290 const double value = in->data.F32[0][0]; 291 return value; 292 } 293 294 // handle edge cases with extrapolation 295 296 const int ix = x - 0.5; // index of reference pixel 297 const int iy = y - 0.5; // index of reference pixel 298 299 // do numCols,Rows first so we are never < 0 300 const int Xs = PS_MAX (PS_MIN (ix, in->numCols - 2), 0); 301 const int Ys = PS_MAX (PS_MIN (iy, in->numRows - 2), 0); 302 303 const int Xe = Xs + 1; 304 const int Ye = Ys + 1; 305 306 // dx,dy range from 0.0 to 1.0 for interpolated pixels, and -0.5 to 1.5 for extrapolation 307 const double dx = x - 0.5 - Xs; 308 const double dy = y - 0.5 - Ys; 309 310 const double rx = 1.0 - dx; 311 const double ry = 1.0 - dy; 312 313 // if Nx == 1, we have no x-dir spatial information 314 if (in->numCols == 1) { 315 double V0 = in->data.F32[Ys][Xs]; 316 double V1 = in->data.F32[Ye][Xs]; 317 318 const double value = V0*ry + V1*dy; 319 return value; 320 } 321 322 // if Ny == 1, we have no y-dir spatial information 323 if (in->numRows == 1) { 324 double V0 = in->data.F32[Ys][Xs]; 325 double V1 = in->data.F32[Ys][Xe]; 326 327 const double value = V0*rx + V1*dx; 328 return value; 329 } 330 331 // Vxy 332 double V00 = in->data.F32[Ys][Xs]; 333 double V10 = in->data.F32[Ys][Xe]; 334 double V01 = in->data.F32[Ye][Xs]; 335 double V11 = in->data.F32[Ye][Xe]; 336 337 // bilinear interpolation 338 const double value = V00*rx*ry + V10*dx*ry + V01*rx*dy + V11*dx*dy; 339 340 return value; 341 } 342 343 -
trunk/psLib/src/imageops/psImageUnbin.h
r12588 r14925 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * $Revision: 1. 4$ $Name: not supported by cvs2svn $9 * $Date: 2007-0 3-27 02:43:22 $8 * $Revision: 1.5 $ $Name: not supported by cvs2svn $ 9 * $Date: 2007-09-20 23:55:52 $ 10 10 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 11 11 */ … … 28 28 ); 29 29 30 double psImageUnbinPixel_V2(const double xFine, const double yFine, // desired Unbinned point (parent coords) 31 const psImage *in, // binned image 32 const psImageBinning *binning //!< Overhang 33 ); 34 35 double psImageInterpolatePixelBilinear (const double xIn, const double yIn, const psImage *in); 36 30 37 /// @} 31 38 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
