Changeset 11299 for trunk/psLib/src/imageops/psImageUnbin.c
- Timestamp:
- Jan 25, 2007, 6:38:53 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageUnbin.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageUnbin.c
r10999 r11299 12 12 // interpolate from model to background (~bresenham linear interpolation) 13 13 // XXX this code skips the initial pixels? 14 // XXX this code may be off by 0.5,0.5 pixels 14 15 psImage *psImageUnbin(psImage *out, const psImage *in, int DX, int DY, int dx, int dy) 15 16 { … … 18 19 PS_ASSERT_INT_POSITIVE(DX, NULL); 19 20 PS_ASSERT_INT_POSITIVE(DY, NULL); 20 PS_ASSERT_INT_NONNEGATIVE(dx, NULL);21 PS_ASSERT_INT_NONNEGATIVE(dy, NULL);22 21 PS_ASSERT_INT_LESS_THAN_OR_EQUAL(dx, DX, NULL); 23 22 PS_ASSERT_INT_LESS_THAN_OR_EQUAL(dy, DY, NULL); … … 31 30 psF32 **vOut = out->data.F32; 32 31 32 // loop over all pixels with 33 33 for (int Iy = 0; Iy < ny-1; Iy ++) { 34 34 for (int Ix = 0; Ix < nx-1; Ix ++) { … … 42 42 // (Xs,Ys) : (Xe,Ye) : binned pixel centers in unbinned coords 43 43 // corresponding to (Ix,Iy), (Ix+1,Iy+1) 44 int Xs = (Ix + 1)*DX - dx;45 int Ys = (Iy + 1)*DY - dy;46 int Xe = Xs + DX;47 int Ye = Ys + DY;44 int Xs = PS_MAX (0, PS_MIN (Nx, (Ix + 0.5)*DX - dx)); 45 int Ys = PS_MAX (0, PS_MIN (Ny, (Iy + 0.5)*DY - dy)); 46 int Xe = PS_MAX (0, PS_MIN (Nx, Xs + DX)); 47 int Ye = PS_MAX (0, PS_MIN (Ny, Ys + DY)); 48 48 49 49 for (int iy = Ys; (iy < Ye) && (iy < Ny); iy++) { … … 62 62 63 63 // side pixels 64 int Xs = DX - dx;65 int Xe = nx*DX - dx;64 int Xs = PS_MAX (0, PS_MIN (Nx, ( 0 + 0.5)*DX - dx)); 65 int Xe = PS_MAX (0, PS_MIN (Nx, (nx - 0.5)*DX - dx)); 66 66 for (int Iy = 0; Iy < ny - 1; Iy++) { 67 67 68 int Ys = (Iy + 1)*DY - dy;69 int Ye = Ys + DY;68 int Ys = PS_MAX (0, PS_MIN (Ny, (Iy + 0.5)*DY - dy)); 69 int Ye = PS_MAX (0, PS_MIN (Ny, Ys + DY)); 70 70 71 71 // leading edge … … 95 95 96 96 // top and bottom pixels 97 int Ys = DY - dy;98 int Ye = ny*DY - dy;97 int Ys = PS_MAX (0, PS_MIN (Ny, ( 0 + 0.5)*DY - dy)); 98 int Ye = PS_MAX (0, PS_MIN (Ny, (ny - 0.5)*DY - dy)); 99 99 for (int Ix = 0; Ix < nx - 1; Ix++) { 100 100 101 int Xs = (Ix + 1)*DX - dx;102 int Xe = Xs + DX;101 int Xs = PS_MAX (0, PS_MIN (Nx, (Ix + 0.5)*DX - dx)); 102 int Xe = PS_MAX (0, PS_MIN (Nx, Xs + DX)); 103 103 104 104 // top edge … … 183 183 PS_ASSERT_INT_POSITIVE(DX, NAN); 184 184 PS_ASSERT_INT_POSITIVE(DY, NAN); 185 PS_ASSERT_INT_NONNEGATIVE(dx, NAN);186 PS_ASSERT_INT_NONNEGATIVE(dy, NAN);187 185 PS_ASSERT_INT_LESS_THAN_OR_EQUAL(dx, DX, NAN); 188 186 PS_ASSERT_INT_LESS_THAN_OR_EQUAL(dy, DY, NAN); … … 190 188 * Find which binned pixel we're in 191 189 */ 192 const int Ix = (ix + dx)/DX - 1; // index of binned pixel 193 const int Iy = (iy + dy)/DY - 1; 194 195 if (Ix < 0 || Ix >= in->numCols - 1 || Iy < 0 || Iy >= in->numRows - 1) { 190 const int Xs = (ix + dx)/DX; // index of binned pixel 191 const int Ys = (iy + dy)/DY; 192 if (Xs < 0 || Xs >= in->numCols || Ys < 0 || Ys >= in->numRows) { 196 193 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Point (%d,%d) lies outside binned image", ix, iy); 197 194 return NAN; 198 195 } 199 200 double V00 = in->data.F32[Iy+0][Ix+0]; 201 double V01 = in->data.F32[Iy+0][Ix+1]; 202 double V10 = in->data.F32[Iy+1][Ix+0]; 203 double V11 = in->data.F32[Iy+1][Ix+1]; 204 205 const int Xs = (Ix + 1)*DX - dx; // centre of bottom left corner of binned pixel 206 const int Ys = (Iy + 1)*DY - dy; // (i.e. [Iy][Ix]) in unbinned coordinates 207 208 const double Vxs = (V10 - V00)*(iy - Ys)/DY + V00; 209 const double Vxe = (V11 - V01)*(iy - Ys)/DY + V01; 210 211 return Vxs + (Vxe - Vxs)*(ix - Xs)/DX; // value at [iy][ix] 196 const int Xe = PS_MIN (Xs + 1, in->numCols - 1); 197 const int Ye = PS_MIN (Ys + 1, in->numRows - 1); 198 199 double V00 = in->data.F32[Ys][Xs]; 200 double V01 = in->data.F32[Ys][Xe]; 201 double V10 = in->data.F32[Ye][Xs]; 202 double V11 = in->data.F32[Ye][Xe]; 203 204 const int xs = Xs*DX - dx; // centre of bottom left corner of binned pixel 205 const int ys = Ys*DY - dy; // (i.e. [Xs][Ys]) in unbinned coordinates 206 207 const double Vxs = (V10 - V00)*(iy - ys)/DY + V00; 208 const double Vxe = (V11 - V01)*(iy - ys)/DY + V01; 209 210 return Vxs + (Vxe - Vxs)*(ix - xs)/DX; // value at [iy][ix] 212 211 }
Note:
See TracChangeset
for help on using the changeset viewer.
