IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 28, 2008, 11:09:34 AM (18 years ago)
Author:
Paul Price
Message:

Using pmReadoutRebin.

File:
1 edited

Legend:

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

    r18724 r20438  
    1010    pmReadout *inReadout, *outReadout;
    1111
    12     pmFPAfile *outFile = psMetadataLookupPtr (NULL, config->files, outName);
     12    pmFPAfile *outFile = psMetadataLookupPtr(NULL, config->files, outName);
    1313    if (outFile == NULL) return false;
    1414
     
    3333
    3434            // run the rebin code
    35             ppImageRebinReadout (outReadout, inReadout, outFile, options);
     35            if (!pmReadoutRebin(outReadout, inReadout, options->maskVal, outFile->xBin, outFile->yBin)) {
     36                psError(PS_ERR_UNKNOWN, false, "Unable to rebin readout.");
     37                return false;
     38            }
    3639        }
    37 
    38         // Get the original values for the binning
    39         bool mdok = true;               // Status of MD lookup
    40         int xBin = psMetadataLookupS32(&mdok, cell->concepts, "CELL.XBIN"); // The binning in x
    41         if (!mdok || xBin <= 0) {
    42             psLogMsg(__func__, PS_LOG_WARN, "CELL.XBIN is not set --- assuming 1.\n");
    43             xBin = 1;
    44         }
    45         int yBin = psMetadataLookupS32(&mdok, cell->concepts, "CELL.YBIN"); // The binning in y
    46         if (!mdok || yBin <= 0) {
    47             psLogMsg(__func__, PS_LOG_WARN, "CELL.YBIN is not set --- assuming 1.\n");
    48             yBin = 1;
    49         }
    50 
    51         // Update the concepts with the new values for the binning
    52         pmCell *outCell = pmFPAviewThisCell(view, outFile->fpa); // The output cell
    53         psMetadataItem *binItem = psMetadataLookup(outCell->concepts, "CELL.XBIN");
    54         binItem->data.S32 = xBin * outFile->xBin;
    55         binItem = psMetadataLookup(outCell->concepts, "CELL.YBIN");
    56         binItem->data.S32 = yBin * outFile->yBin;
    5740    }
    5841
     
    6043}
    6144
    62 // XXX this should be made consistent with psImageBinning
    63 bool ppImageRebinReadout (pmReadout *output, pmReadout *input, pmFPAfile *outFile, ppImageOptions *options)
    64 {
    65     PS_ASSERT_PTR_NON_NULL(output, false);
    66     PS_ASSERT_IMAGE_NON_NULL(output->image, false);
    67     PS_ASSERT_PTR_NON_NULL(input, false);
    68     PS_ASSERT_IMAGE_NON_NULL(input->image, false);
    69     PS_ASSERT_PTR_NON_NULL(outFile, false);
    70 
    71     // the binning process must not change the size of the output image...
    72     // psStats *stats = psStatsAlloc (PS_STATS_SAMPLE_MEAN);
    73     // psImageRebin (output->image, input->image, NULL, 0, scale, stats);
    74     // psFree (stats);
    75 
    76     int dX = outFile->xBin;
    77     int dY = outFile->yBin;
    78 
    79     int nX = input->image->numCols;
    80     int nY = input->image->numRows;
    81 
    82     // we should *either* skip masked pixels or replace masked pixels with the specified value
    83    
    84 
    85     // do the rebinning by hand, mean only for test
    86     for (int yOut = 0; yOut < output->image->numRows; yOut++) {
    87         for (int xOut = 0; xOut < output->image->numCols; xOut++) {
    88             float maskedValue = 0.0;
    89             float value = 0;
    90             int nPix = 0;
    91             for (int yIn = yOut * dY; (yIn < yOut * dY + dY) && (yIn < nY); yIn ++) {
    92                 for (int xIn = xOut * dX; (xIn < xOut * dX + dX) && (xIn < nX); xIn ++) {
    93                     if (input->mask && input->mask->data.U8[yIn][xIn]) {
    94                       maskedValue = input->image->data.F32[yIn][xIn];
    95                       continue;
    96                     }
    97                     value += input->image->data.F32[yIn][xIn];
    98                     nPix ++;
    99                 }
    100             }
    101             if (nPix > 0) {
    102               output->image->data.F32[yOut][xOut] = value / nPix;
    103             } else {
    104               if (options->replaceMasked) {
    105                 output->image->data.F32[yOut][xOut] = maskedValue;
    106               } else {
    107                 output->image->data.F32[yOut][xOut] = 0.0;
    108               }
    109             }
    110         }
    111     }
    112 
    113     return true;
    114 }
Note: See TracChangeset for help on using the changeset viewer.