IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7194


Ignore:
Timestamp:
May 23, 2006, 7:08:52 PM (20 years ago)
Author:
Paul Price
Message:

Fixing image ranges: output image range was going off the image.

File:
1 edited

Legend:

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

    r7059 r7194  
    55 *  @author GLG, MHPCC
    66 *
    7  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2006-05-04 02:38:20 $
     7 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2006-05-24 05:08:52 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    144144    psVector *colLower = psVectorAlloc(inputs->n, PS_TYPE_U32); // The lower x bound for each image
    145145    psVector *colUpper = psVectorAlloc(inputs->n, PS_TYPE_U32); // The upper x bound for each image
     146    rowLower->n = inputs->n;
     147    rowUpper->n = inputs->n;
     148    colLower->n = inputs->n;
     149    colUpper->n = inputs->n;
    146150    psVector *mask   = psVectorAlloc(inputs->n, PS_TYPE_U8); // Mask for stack
     151    mask->n = inputs->n;
    147152    psVectorInit(mask, 0);
    148153    bool haveWeights = false;           // Do we have weight images?
     
    180185        colUpper->data.U32[i] = readout->col0 + readout->image->numCols;
    181186    }
    182 
    183     // Reset output readout components
    184     *(psS32 *) &(output->col0) = minInputCols;
    185     *(psS32 *) &(output->row0) = minInputRows;
    186     output->image = psImageRecycle(output->image, maxInputCols - minInputCols, maxInputRows - minInputRows,
    187                                    PS_TYPE_F32);
    188     output->mask = psImageRecycle(output->mask, maxInputCols - minInputCols, maxInputRows - minInputRows,
    189                                   PS_TYPE_U8);
    190     psImageInit(output->mask, 0);
    191     psStatsOptions combineStdev = 0;    // Statistics option for weights
     187    if (!valid) {
     188        psError(PS_ERR_IO, true, "No valid inputs.\n");
     189        return NULL;
     190    }
     191
     192    // If there's existing images, we need to extend them
     193    long minOutputRows = (output->image || output->mask || output->weight) ?
     194                         PS_MIN(minInputRows, output->row0) : minInputRows; // Smallest row value, considering the output
     195    long minOutputCols = (output->image || output->mask || output->weight) ?
     196                         PS_MIN(minInputCols, output->col0) : minInputCols; // Smallest column value, considering the output
     197
     198    // Update the origin
     199    *(psS32 *) &(output->col0) = minOutputCols;
     200    *(psS32 *) &(output->row0) = minOutputRows;
     201
     202    // Generate the new output image by extending the current one, or making a whole new one
     203    psImage *newImage = psImageAlloc(maxInputCols - minOutputCols, maxInputRows - minOutputRows, PS_TYPE_F32);
     204    psImageInit(newImage, 0.0);
     205    if (output->image) {
     206        psImageOverlaySection(newImage, output->image, output->col0, output->row0, "=");
     207        psFree(output->image);
     208    }
     209    output->image = newImage;
     210
     211    psImage *newMask = psImageAlloc(maxInputCols - minOutputCols, maxInputRows - minOutputRows, PS_TYPE_U8);
     212    psImageInit(newMask, 0);
     213    if (output->mask) {
     214        psImageOverlaySection(newMask, output->mask, output->col0, output->row0, "=");
     215        psFree(output->mask);
     216    }
     217    output->mask = newMask;
     218
     219    psStatsOptions combineStdev = 0; // Statistics option for weights
    192220    if (haveWeights) {
    193         output->weight = psImageRecycle(output->weight, maxInputCols - minInputCols,
    194                                         maxInputRows - minInputRows, PS_TYPE_F32);
     221        psImage *newWeight = psImageAlloc(maxInputCols - minOutputCols, maxInputRows - minOutputRows,
     222                                          PS_TYPE_F32);
     223        psImageInit(newWeight, 0.0);
     224        if (output->weight) {
     225            psImageOverlaySection(newWeight, output->weight, output->col0, output->row0, "=");
     226            psFree(output->weight);
     227        }
     228        output->weight = newWeight;
     229
     230        // Get the correct statistics option for weights
    195231        switch (params->combine) {
    196232        case PS_STAT_SAMPLE_MEAN:
     
    231267    psMaskType maskVal = params->maskVal; // The mask value
    232268
    233     for (int i = output->row0; i < output->row0 + output->image->numRows; i++) {
    234         for (int j = output->col0; j < output->col0 + output->image->numCols; j++) {
     269    for (int i = minInputRows; i < maxInputRows; i++) {
     270        for (int j = minInputCols; j < maxInputCols; j++) {
    235271
    236272            int numValid = 0;           // Number of valid pixels in the stack
     
    246282
    247283                pmReadout *readout = inputs->data[r]; // Input readout
    248                 int y = i - readout->row0; // y position on input readout
    249                 int x = j - readout->col0; // x position on input readout
    250                 if (readout->mask && readout->mask->data.U8[y][x] & maskVal) {
     284                int yIn = i - readout->row0; // y position on input readout
     285                int xIn = j - readout->col0; // x position on input readout
     286                if (readout->mask && readout->mask->data.U8[yIn][xIn] & maskVal) {
    251287                    mask->data.U8[r] &= PM_READOUT_COMBINE_MASKED;
    252288                    continue;
    253289                }
    254290
    255                 pixels->data.F32[r] = readout->image->data.F32[y][x];
     291                pixels->data.F32[r] = readout->image->data.F32[yIn][xIn];
    256292
    257293                // Apply zero and scale
     
    264300
    265301                if (haveWeights) {
    266                     weights->data.F32[r] = readout->weight->data.F32[y][x];
     302                    weights->data.F32[r] = readout->weight->data.F32[yIn][xIn];
    267303                    if (scale) {
    268304                        weights->data.F32[r] /= scale->data.F32[r] * scale->data.F32[r];
     
    272308            }
    273309
     310            int yOut = i - output->row0; // y position on output readout
     311            int xOut = j - output->col0; // x position on output readout
     312            psTrace(__func__, 10, "Output pixel: %d %d\n", xOut, yOut);
     313
    274314            if (numValid == 0) {
    275                 output->mask->data.U8[i][j] = PM_MASK_FLAT;
     315                output->mask->data.U8[yOut][xOut] = PM_MASK_FLAT;
    276316                continue;
    277317            }
     
    298338                    }
    299339                }
    300                 psFree(index);
    301340            }
    302341
    303342            // Combination
    304343            psVectorStats(stats, pixels, weights, mask, PM_READOUT_COMBINE_BAD | PM_READOUT_COMBINE_CLIPPED);
    305             output->image->data.F32[i][j] = getStat(stats, params->combine);
     344            output->image->data.F32[yOut][xOut] = getStat(stats, params->combine);
    306345            if (haveWeights) {
    307                 output->weight->data.F32[i][j] = getStat(stats, combineStdev);
    308                 output->weight->data.F32[i][j] *= output->weight->data.F32[i][j]; // Squared for variance
     346                output->weight->data.F32[yOut][xOut] = PS_SQR(getStat(stats, combineStdev)); // Variance
    309347            }
    310348
     
    315353    }
    316354
     355    psFree(index);
    317356    psFree(rowLower);
    318357    psFree(rowUpper);
Note: See TracChangeset for help on using the changeset viewer.