Changeset 20438 for trunk/ppImage/src/ppImageRebinReadout.c
- Timestamp:
- Oct 28, 2008, 11:09:34 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ppImage/src/ppImageRebinReadout.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppImage/src/ppImageRebinReadout.c
r18724 r20438 10 10 pmReadout *inReadout, *outReadout; 11 11 12 pmFPAfile *outFile = psMetadataLookupPtr (NULL, config->files, outName);12 pmFPAfile *outFile = psMetadataLookupPtr(NULL, config->files, outName); 13 13 if (outFile == NULL) return false; 14 14 … … 33 33 34 34 // 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 } 36 39 } 37 38 // Get the original values for the binning39 bool mdok = true; // Status of MD lookup40 int xBin = psMetadataLookupS32(&mdok, cell->concepts, "CELL.XBIN"); // The binning in x41 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 y46 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 binning52 pmCell *outCell = pmFPAviewThisCell(view, outFile->fpa); // The output cell53 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;57 40 } 58 41 … … 60 43 } 61 44 62 // XXX this should be made consistent with psImageBinning63 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 value83 84 85 // do the rebinning by hand, mean only for test86 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.
