IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 3, 2006, 2:19:11 PM (20 years ago)
Author:
Paul Price
Message:

Get the output image size from the concepts instead of the image ---
the image may only be half read, while the concepts (CELL.TRIMSEC)
gives the size of the full image.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmReadoutCombine.c

    r7741 r7802  
    55 *  @author GLG, MHPCC
    66 *
    7  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2006-06-29 00:30:36 $
     7 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2006-07-04 00:19:11 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    122122    // Step through each readout in the input image list to determine how big of an output image is needed to
    123123    // combine these input images.
    124     long maxInputCols = 0;              // The largest input column value
    125     long maxInputRows = 0;              // The largest input row value
    126     long minInputCols = LONG_MAX;       // The smallest input column value
    127     long minInputRows = LONG_MAX;       // The smallest input row value
     124    int maxInputCols = 0;               // The largest input column value
     125    int maxInputRows = 0;               // The largest input row value
     126    int minInputCols = INT_MAX;         // The smallest input column value
     127    int minInputRows = INT_MAX;         // The smallest input row value
     128    int xSize = 0, ySize = 0;           // The size of the output image
    128129
    129130    bool haveWeights = false;           // Do we have weight images?
    130131    bool valid = false;                 // Do we have a single valid input?
    131     for (int i = 0; i < inputs->n; i++) {
     132    for (long i = 0; i < inputs->n; i++) {
    132133        pmReadout *readout = inputs->data[i]; // Readout of interest
     134        pmCell *cell = readout->parent; // The parent cell
     135
    133136        if (!readout || !readout->image) {
    134137            psError(PS_ERR_UNEXPECTED_NULL, true, "Input readout %d is NULL or has NULL image.\n", i);
    135138            return false;
     139        }
     140
     141        bool mdok = true;       // Status of MD lookup
     142        psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section
     143        if (!mdok || !trimsec || psRegionIsNaN(*trimsec)) {
     144            psLogMsg(__func__, PS_LOG_WARN, "CELL.TRIMSEC is not set for readout %ld --- ignored.\n", i);
     145        } else {
     146            xSize = PS_MAX(xSize, trimsec->x1 - trimsec->x0);
     147            ySize = PS_MAX(ySize, trimsec->y1 - trimsec->y0);
    136148        }
    137149
     
    150162        valid = true;
    151163
    152         // Size of output image
     164        // Range of pixels on output image
    153165        minInputRows = PS_MIN(minInputRows, readout->row0);
    154166        maxInputRows = PS_MAX(maxInputRows, readout->row0 + readout->image->numRows);
     
    182194    }
    183195
    184     // If there's existing images, we need to extend them
    185     long minOutputRows = (output->image || output->mask || output->weight) ?
    186                          PS_MIN(minInputRows, output->row0) : minInputRows;  // Smallest output row value
    187     long minOutputCols = (output->image || output->mask || output->weight) ?
    188                          PS_MIN(minInputCols, output->col0) : minInputCols; // Smallest output column value
    189     psTrace(__func__, 7, "Output minimum: %d,%d\n", minOutputCols, minOutputRows);
    190 
    191196    // Update the origin
    192     *(psS32 *) &(output->col0) = minOutputCols;
    193     *(psS32 *) &(output->row0) = minOutputRows;
    194 
    195     // Generate the new output image by extending the current one, or making a whole new one
    196     psImage *newImage = psImageAlloc(maxInputCols - minOutputCols, maxInputRows - minOutputRows, PS_TYPE_F32);
    197     psImageInit(newImage, 0.0);
    198197    if (output->image) {
     198        *(psS32 *) &(output->col0) = PS_MIN(minInputCols, output->col0);
     199        *(psS32 *) &(output->row0) = PS_MIN(minInputRows, output->row0);
     200    } else {
     201        *(psS32 *) &(output->col0) = minInputCols;
     202        *(psS32 *) &(output->row0) = minInputRows;
     203    }
     204    psTrace(__func__, 7, "Output minimum: %d,%d\n", output->col0, output->row0);
     205
     206    // Allocate the output products
     207
     208    if (!output->image) {
     209        output->image = psImageAlloc(xSize, ySize, PS_TYPE_F32);
     210    }
     211    if (output->image->numCols < xSize || output->image->numRows < ySize) {
     212        // Generate the new output image by extending the current one, or making a whole new one
     213        psImage *newImage = psImageAlloc(xSize, ySize, PS_TYPE_F32);
     214        psImageInit(newImage, 0.0);
    199215        psImageOverlaySection(newImage, output->image, output->col0, output->row0, "=");
    200216        psFree(output->image);
    201     }
    202     output->image = newImage;
    203 
    204     psImage *newMask = psImageAlloc(maxInputCols - minOutputCols, maxInputRows - minOutputRows, PS_TYPE_U8);
    205     psImageInit(newMask, 0);
    206     if (output->mask) {
     217        output->image = newImage;
     218    }
     219
     220    if (!output->mask) {
     221        output->mask = psImageAlloc(xSize, ySize, PS_TYPE_U8);
     222    }
     223    if (output->mask->numCols < xSize || output->mask->numRows < ySize) {
     224        psImage *newMask = psImageAlloc(xSize, ySize, PS_TYPE_U8);
     225        psImageInit(newMask, 0);
    207226        psImageOverlaySection(newMask, output->mask, output->col0, output->row0, "=");
    208227        psFree(output->mask);
    209     }
    210     output->mask = newMask;
     228        output->mask = newMask;
     229    }
    211230
    212231    psStatsOptions combineStdev = 0; // Statistics option for weights
    213232    if (haveWeights) {
    214         psImage *newWeight = psImageAlloc(maxInputCols - minOutputCols, maxInputRows - minOutputRows,
    215                                           PS_TYPE_F32);
    216         psImageInit(newWeight, 0.0);
    217         if (output->weight) {
     233
     234        if (!output->weight) {
     235            output->weight = psImageAlloc(xSize, ySize, PS_TYPE_F32);
     236        }
     237        if (output->weight->numCols < xSize || output->weight->numRows < ySize) {
     238            psImage *newWeight = psImageAlloc(xSize, ySize, PS_TYPE_F32);
     239            psImageInit(newWeight, 0.0);
    218240            psImageOverlaySection(newWeight, output->weight, output->col0, output->row0, "=");
    219241            psFree(output->weight);
    220         }
    221         output->weight = newWeight;
     242            output->weight = newWeight;
     243        }
    222244
    223245        // Get the correct statistics option for weights
Note: See TracChangeset for help on using the changeset viewer.