IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 16, 2021, 3:54:37 PM (5 years ago)
Author:
eugene
Message:

add utility command to report on pmFPAfiles; fix typo; add quick combine-by-percentile; remove some old and excessively-verbose test blocks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-dev-20210817/psModules/src/imcombine/pmStack.c

    r36710 r41843  
    961961
    962962    // KMM values;
    963     float Punimodal = 1.0,KMMmean = NAN,KMMsigma = NAN,KMMpi = NAN;
     963    float Punimodal = 1.0, KMMmean = NAN, KMMsigma = NAN, KMMpi = NAN;
    964964    int KMM_MINIMUM_INPUTS = 6;
    965965    bool useKMM = false;
     
    15101510}
    15111511
     1512# define MIN_GOOD_PERCENTILE 2
     1513bool pmStackCombineByPercentile(
     1514    pmReadout *combined,
     1515    psArray *stackData,
     1516    psF64 minRange,
     1517    psF64 maxRange,
     1518    psImageMaskType badMaskBits,        // treat these bits as 'bad'
     1519    psImageMaskType suspectMaskBits,    // treat these bits as 'suspect'
     1520    psImageMaskType blankMaskBits       // use this mask value for pixels missing input data (distinguish between Ninput = 0 and Ngood = 0?)
     1521) {
     1522    int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine
     1523    int xSize, ySize;                   // Size of the output image
     1524
     1525    // we need to copy the readouts to their own array for validation
     1526    psArray *stackReadouts = psArrayAlloc(stackData->n);
     1527    for (int i = 0; i < stackData->n; i++) {
     1528        pmStackData *data = stackData->data[i]; // Stack data for this input
     1529        pmReadout *ro = data->readout;  // Readout of interest
     1530        stackReadouts->data[i] = psMemIncrRefCounter(ro);
     1531    }
     1532
     1533    if (!pmReadoutStackValidate(&minInputCols, &maxInputCols, &minInputRows, &maxInputRows, &xSize, &ySize, stackReadouts)) {
     1534        psError(psErrorCodeLast(), false, "Input stack is not valid.");
     1535        psFree(stackReadouts);
     1536        return false;
     1537    }
     1538    psFree(stackReadouts);
     1539
     1540    psVector *pixelData = psVectorAlloc(stackData->n, PS_TYPE_F32);
     1541    psVector *pixelMask = psVectorAlloc(stackData->n, PS_TYPE_VECTOR_MASK);
     1542
     1543    for (int y = minInputRows; y < maxInputRows; y++) {
     1544        for (int x = minInputCols; x < maxInputCols; x++) {
     1545
     1546            int nGood = 0;
     1547            for (int i = 0; i < stackData->n; i++) {
     1548
     1549                pmStackData *data = stackData->data[i]; // Stack data for this input
     1550                pmReadout *ro = data->readout;  // Readout of interest
     1551                psImage *image = ro->image;
     1552
     1553                int xIn = x - data->readout->col0;
     1554                int yIn = y - data->readout->row0; // Coordinates on input readout
     1555
     1556                if (!isfinite(image->data.F32[yIn][xIn])) continue;
     1557                if (fabs(image->data.F32[yIn][xIn]) > 1e5) continue;
     1558                // XXX need to test the input mask as well here
     1559
     1560                pixelData->data.F32[nGood] = image->data.F32[yIn][xIn];
     1561                nGood ++;
     1562            }
     1563            pixelData->n = nGood;
     1564            psVectorSortInPlace (pixelData);
     1565
     1566            if (nGood < MIN_GOOD_PERCENTILE) {
     1567                combined->image->data.F32[y][x] = NAN;
     1568                combined->variance->data.F32[y][x] = NAN;
     1569                combined->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = 1;
     1570                continue;
     1571            }
     1572
     1573            int Ns = MIN(MAX(0, minRange * nGood),nGood); // e.g., 0.1 * 50 = 5
     1574            int Ne = MIN(MAX(0, maxRange * nGood),nGood); // e.g., 0.9 * 50 = 45
     1575            int Npt = Ne - Ns;
     1576
     1577            float sum = 0.0;
     1578            for (int n = Ns; n < Ne; n++) {
     1579                sum += pixelData->data.F32[n];
     1580            }
     1581            float mean = sum / (float) Npt;
     1582
     1583            float varSum = 0.0;
     1584            for (int n = Ns; n < Ne; n++) {
     1585                varSum += SQ(pixelData->data.F32[n] - mean);
     1586            }
     1587            // variance on the mean (stdev / sqrt(N))^2
     1588            float varValue = varSum / (Npt - 1) / Npt;
     1589
     1590            combined->image->data.F32[y][x] = mean;
     1591            combined->variance->data.F32[y][x] = varValue;
     1592            combined->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = 0;
     1593        }
     1594    }
     1595 
     1596    psFree(pixelData);
     1597    psFree(pixelMask);
     1598
     1599    return (true);
     1600}
     1601
    15121602/// Stack input images
    15131603bool pmStackCombine(
     
    16441734        expweight = expmaps->variance;
    16451735    }
    1646 
    1647 /*     // Pre-reject inputs using KMM bimodality test. */
    1648 /*     if (1)  { */
    1649 /* /\*       KMMRejectUnpopular(input,x,y); *\/ */
    1650 /*       rejection = true; */
    1651 /*     } */
    16521736   
    16531737    // Set up rejection list
     
    16601744    for (int y = minInputRows; y < maxInputRows; y++) {
    16611745        for (int x = minInputCols; x < maxInputCols; x++) {
     1746            // this is only for TESTING:
    16621747            CHECKPIX(x, y, "Combining pixel %d,%d: %x %x %f %f %f %f %d %d %d\n", x, y, badMaskBits, blankMaskBits, iter, rej, sys, olympic, useVariance, safe, rejection);
    1663 
    1664 /*          // Pre-reject inputs using KMM bimodality test. */
    1665 /*        if (1)  { */
    1666 /*          KMMRejectUnpopular(input,x,y); */
    1667 /* /\*      rejection = true; *\/ */
    1668 /*        } */
    1669 /*        else { */
    1670 /*          KMMRejectBright(input,x,y); */
    1671 /*        } */
    1672 
    1673 #ifdef TESTING
    1674             if (PS_SQR(x - TEST_X) + PS_SQR(y - TEST_Y) <= PS_SQR(TEST_RADIUS)) {
    1675                 fprintf (stderr, "combine\n");
    1676             }
    1677 # endif
    16781748
    16791749            psVector *reject = NULL; // Images to reject for this pixel
Note: See TracChangeset for help on using the changeset viewer.