IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 18, 2009, 10:42:16 AM (17 years ago)
Author:
eugene
Message:

updates from vysos branch: ppImage option to optionally flip images

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/ppImageParityFlip.c

    r24228 r25875  
    1010item->data.TYPE = VALUE; }
    1111
    12 bool ppImageParityFlip (pmConfig *config, const ppImageOptions *options, const pmFPAview *view) {
     12// flip the image to have 'native' (detector) or 'raw' (readout) orientation
     13bool ppImageParityFlip (pmConfig *config, const ppImageOptions *options, const pmFPAview *view, bool native) {
    1314
    1415    bool status;
     16    int xParity, yParity;
     17    int xParityRaw, yParityRaw;
     18    int xParityTarget, yParityTarget;
    1519
    1620    if (!options->applyParity) return true;
     
    2125    pmCell *cell = readout->parent;
    2226
    23     int xParity = psMetadataLookupS32(&status, cell->concepts, "CELL.XPARITY");
    24     if (!status || (xParity != -1 && xParity != 1)) {
    25         psWarning("CELL.XPARITY is not set for the input cell; assuming 1.\n");
    26         FIX_CONCEPT(cell->concepts, "CELL.XPARITY", S32, 1);
    27         xParity = 1;
    28     }
    29     int yParity = psMetadataLookupS32(&status, cell->concepts, "CELL.YPARITY");
    30     if (!status || (yParity != -1 && yParity != 1)) {
    31         psWarning("CELL.YPARITY is not set for the input cell; assuming 1.\n");
    32         FIX_CONCEPT(cell->concepts, "CELL.YPARITY", S32, 1);
    33         yParity = 1;
     27    if (native) {
     28        // find the current (raw) parity
     29        xParity = psMetadataLookupS32(&status, cell->concepts, "CELL.XPARITY");
     30        if (!status || (xParity != -1 && xParity != 1)) {
     31            psWarning("CELL.XPARITY is not set for the input cell; assuming 1.\n");
     32            FIX_CONCEPT(cell->concepts, "CELL.XPARITY", S32, 1);
     33            xParity = 1;
     34        }
     35        yParity = psMetadataLookupS32(&status, cell->concepts, "CELL.YPARITY");
     36        if (!status || (yParity != -1 && yParity != 1)) {
     37            psWarning("CELL.YPARITY is not set for the input cell; assuming 1.\n");
     38            FIX_CONCEPT(cell->concepts, "CELL.YPARITY", S32, 1);
     39            yParity = 1;
     40        }
     41
     42        // save the raw parity
     43        psMetadataAddS32 (cell->concepts, PS_LIST_TAIL, "CELL.XPARITY.RAW", PS_META_REPLACE, "original parity", xParity);
     44        psMetadataAddS32 (cell->concepts, PS_LIST_TAIL, "CELL.YPARITY.RAW", PS_META_REPLACE, "original parity", yParity);
     45
     46        xParityTarget = 1;
     47        yParityTarget = 1;
     48    } else {
     49        // find the current (native) parity
     50        xParity = psMetadataLookupS32(&status, cell->concepts, "CELL.XPARITY");
     51        psAssert (status, "CELL.XPARITY not set : cannot call ppImageParityFlip (native = false) without first calling it with native = true");
     52
     53        yParity = psMetadataLookupS32(&status, cell->concepts, "CELL.YPARITY");
     54        psAssert (status, "CELL.YPARITY not set : cannot call ppImageParityFlip (native = false) without first calling it with native = true");
     55
     56        // find the raw parity
     57        xParityRaw = psMetadataLookupS32(&status, cell->concepts, "CELL.XPARITY.RAW");
     58        psAssert (status, "CELL.XPARITY not set : cannot call ppImageParityFlip (native = false) without first calling it with native = true");
     59
     60        yParityRaw = psMetadataLookupS32(&status, cell->concepts, "CELL.YPARITY.RAW");
     61        psAssert (status, "CELL.YPARITY not set : cannot call ppImageParityFlip (native = false) without first calling it with native = true");
     62
     63        xParityTarget = xParityRaw;
     64        yParityTarget = yParityRaw;
    3465    }
    3566
    3667    // for this case, nothing to be done:
    37     if ((xParity == 1) && (yParity == 1)) return true;
    38    
     68    if ((xParity == xParityTarget) && (yParity == yParityTarget)) return true;
     69
    3970    psImage *image = readout->image;
    4071    psImage *var   = readout->variance;
     
    5586
    5687    // the three cases (+1,-1), (-1,+1), (-1,-1) should be handled independently
    57     if ((xParity == -1) && (yParity == +1)) {
     88
     89    // flip only in x-direction
     90    if ((xParity != xParityTarget) && (yParity == yParityTarget)) {
    5891        for (int iy = 0; iy < Ny; iy++) {
    5992            for (int ix = 0; ix < Nx; ix++) {
     
    71104        }
    72105    }
    73     if ((xParity == +1) && (yParity == -1)) {
     106    // flip only in y-direction
     107    if ((xParity == xParityTarget) && (yParity != yParityTarget)) {
    74108        for (int iy = 0; iy < Ny/2; iy++) {
    75109            memcpy (imrow, image->data.F32[iy], Nx*sizeof(psF32));
     
    90124        }
    91125    }
    92     if ((xParity == -1) && (yParity == -1)) {
     126    // flip in both directions
     127    if ((xParity != xParityTarget) && (yParity != yParityTarget)) {
    93128        for (int iy = 0; iy < Ny/2; iy++) {
    94129            for (int ix = 0; ix < Nx; ix++) {
     
    118153    }
    119154
    120     // FIX_CONCEPT(cell->concepts, "CELL.XPARITY", S32, 1);
    121     // FIX_CONCEPT(cell->concepts, "CELL.YPARITY", S32, 1);
     155    FIX_CONCEPT(cell->concepts, "CELL.XPARITY", S32, xParityTarget);
     156    FIX_CONCEPT(cell->concepts, "CELL.YPARITY", S32, yParityTarget);
    122157
    123158    psFree (imrow);
Note: See TracChangeset for help on using the changeset viewer.