IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11299


Ignore:
Timestamp:
Jan 25, 2007, 6:38:53 PM (19 years ago)
Author:
magnier
Message:

adjusted meaning of dx, dy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageUnbin.c

    r10999 r11299  
    1212// interpolate from model to background (~bresenham linear interpolation)
    1313// XXX this code skips the initial pixels?
     14// XXX this code may be off by 0.5,0.5 pixels
    1415psImage *psImageUnbin(psImage *out, const psImage *in, int DX, int DY, int dx, int dy)
    1516{
     
    1819    PS_ASSERT_INT_POSITIVE(DX, NULL);
    1920    PS_ASSERT_INT_POSITIVE(DY, NULL);
    20     PS_ASSERT_INT_NONNEGATIVE(dx, NULL);
    21     PS_ASSERT_INT_NONNEGATIVE(dy, NULL);
    2221    PS_ASSERT_INT_LESS_THAN_OR_EQUAL(dx, DX, NULL);
    2322    PS_ASSERT_INT_LESS_THAN_OR_EQUAL(dy, DY, NULL);
     
    3130    psF32 **vOut = out->data.F32;
    3231
     32    // loop over all pixels with
    3333    for (int Iy = 0; Iy < ny-1; Iy ++) {
    3434        for (int Ix = 0; Ix < nx-1; Ix ++) {
     
    4242            // (Xs,Ys) : (Xe,Ye) : binned pixel centers in unbinned coords
    4343            // 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));
    4848
    4949            for (int iy = Ys; (iy < Ye) && (iy < Ny); iy++) {
     
    6262
    6363    // 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));
    6666    for (int Iy = 0; Iy < ny - 1; Iy++) {
    6767
    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));
    7070
    7171        // leading edge
     
    9595
    9696    // 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));
    9999    for (int Ix = 0; Ix < nx - 1; Ix++) {
    100100
    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));
    103103
    104104        // top edge
     
    183183    PS_ASSERT_INT_POSITIVE(DX, NAN);
    184184    PS_ASSERT_INT_POSITIVE(DY, NAN);
    185     PS_ASSERT_INT_NONNEGATIVE(dx, NAN);
    186     PS_ASSERT_INT_NONNEGATIVE(dy, NAN);
    187185    PS_ASSERT_INT_LESS_THAN_OR_EQUAL(dx, DX, NAN);
    188186    PS_ASSERT_INT_LESS_THAN_OR_EQUAL(dy, DY, NAN);
     
    190188     * Find which binned pixel we're in
    191189     */
    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) {
    196193        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Point (%d,%d) lies outside binned image", ix, iy);
    197194        return NAN;
    198195    }
    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]
    212211}
Note: See TracChangeset for help on using the changeset viewer.