Changeset 42375
- Timestamp:
- Feb 8, 2023, 11:21:05 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20220316/psModules/src/camera/pmFPABin.c
r42215 r42375 31 31 psImage *outImage; // Output image 32 32 if (out->image && out->image->numCols >= numColsOut && out->image->numRows >= numRowsOut) { 33 outImage = out->image;33 outImage = out->image; 34 34 } else { 35 outImage = out->image = psImageRecycle(out->image, numColsOut, numRowsOut, PS_TYPE_F32);35 outImage = out->image = psImageRecycle(out->image, numColsOut, numRowsOut, PS_TYPE_F32); 36 36 } 37 37 38 38 psImage *outMask; // Output mask 39 39 if (out->mask && out->mask->numCols >= numColsOut && out->mask->numRows >= numRowsOut) { 40 outMask = out->mask;40 outMask = out->mask; 41 41 } else { 42 outMask = out->mask = psImageRecycle(out->mask, numColsOut, numRowsOut, PS_TYPE_IMAGE_MASK);42 outMask = out->mask = psImageRecycle(out->mask, numColsOut, numRowsOut, PS_TYPE_IMAGE_MASK); 43 43 } 44 44 … … 50 50 int yStart = psImageBinningGetFineY(binning, 0); // Starting input y for binning 51 51 for (int yOut = 0; yOut < numRowsOut; yOut++) { 52 int yStop = psImageBinningGetFineY(binning, yOut + 1); // Stopping input y for binning53 yStop = PS_MIN(yStop, yLast);54 int xStart = psImageBinningGetFineX(binning, 0); // Starting input x for binning55 for (int xOut = 0; xOut < numColsOut; xOut++) {56 int xStop = psImageBinningGetFineX(binning, xOut + 1); // Stopping input x for binning57 xStop = PS_MIN(xStop, xLast);52 int yStop = psImageBinningGetFineY(binning, yOut + 1); // Stopping input y for binning 53 yStop = PS_MIN(yStop, yLast); 54 int xStart = psImageBinningGetFineX(binning, 0); // Starting input x for binning 55 for (int xOut = 0; xOut < numColsOut; xOut++) { 56 int xStop = psImageBinningGetFineX(binning, xOut + 1); // Stopping input x for binning 57 xStop = PS_MIN(xStop, xLast); 58 58 59 float sum = 0.0; // Sum of pixels60 int numPix = 0; // Number of pixels59 float sum = 0.0; // Sum of pixels 60 int numPix = 0; // Number of pixels 61 61 62 62 for (int j = 0; j < Nbits; j++) { // Reset bit counter 63 bitcounter[j] = 0;63 bitcounter[j] = 0; 64 64 } 65 65 pxlcount = 0; 66 66 67 for (int y = yStart; y < yStop; y++) { 68 for (int x = xStart; x < xStop; x++) { 69 if (false && inMask && (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] != 0)) { 70 for (int j = 0; j < Nbits; j++) { 71 psImageMaskType M = (psImageMaskType) pow(2,j); 72 if (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & M) { 73 bitcounter[j]++; 67 for (int y = yStart; y < yStop; y++) { 68 for (int x = xStart; x < xStop; x++) { 69 if (false && inMask && (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] != 0)) { 70 for (int j = 0; j < Nbits; j++) { 71 psImageMaskType M = (psImageMaskType) pow(2,j); 72 if (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & M) { 73 bitcounter[j]++; 74 } 74 75 } 75 }76 76 } 77 77 78 if (inMask && (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal)) {79 continue;80 }81 if (!isfinite(inImage->data.F32[y][x])) {82 continue;83 }84 sum += inImage->data.F32[y][x];85 numPix++;78 if (inMask && (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal)) { 79 continue; 80 } 81 if (!isfinite(inImage->data.F32[y][x])) { 82 continue; 83 } 84 sum += inImage->data.F32[y][x]; 85 numPix++; 86 86 87 87 88 }89 }88 } 89 } 90 90 91 91 // Values to set 92 float imageValue;92 float imageValue; 93 93 psImageMaskType maskValue; 94 if (numPix > 0) {95 imageValue = sum / numPix;96 maskValue = 0;97 } else {98 imageValue = NAN;99 maskValue = maskVal;100 }101 outImage->data.F32[yOut][xOut] = imageValue;94 if (numPix > 0) { 95 imageValue = sum / numPix; 96 maskValue = 0; 97 } else { 98 imageValue = NAN; 99 maskValue = maskVal; 100 } 101 outImage->data.F32[yOut][xOut] = imageValue; 102 102 if (true) { 103 outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] = maskValue;103 outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] = maskValue; 104 104 } else { 105 outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] = 0;105 outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] = 0; 106 106 } 107 107 // this loop is pointless if pxlcount == 0 (all masked) 108 108 if (false) { 109 if (pxlcount) { 110 for (int j = 0; j < Nbits; j++) { 111 if (bitcounter[j] > 0.5 * pxlcount) { 112 outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] |= (1 << j); 113 } 109 if (pxlcount) { 110 for (int j = 0; j < Nbits; j++) { 111 if (bitcounter[j] > 0.5 * pxlcount) { 112 outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] |= (1 << j); 113 } 114 } 115 } else { 116 outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] = maskValue; 114 117 } 115 } else {116 outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] = maskValue;117 }118 118 } 119 119 xStart = xStop; 120 }121 yStart = yStop;120 } 121 yStart = yStop; 122 122 } 123 123 … … 126 126 out->data_exists = true; 127 127 if (out->parent) { 128 pmCell *outCell = out->parent; // Output cell129 outCell->data_exists = outCell->parent->data_exists = true;128 pmCell *outCell = out->parent; // Output cell 129 outCell->data_exists = outCell->parent->data_exists = true; 130 130 131 // We would copy the concepts from the input cell, except that is done by pmFPACopy,132 // pmChipCopyStructure, etc. This function just does the mechanics of binning.133 // We don't even update the CELL.XBIN, CELL.YBIN because that would apply the correction twice.131 // We would copy the concepts from the input cell, except that is done by pmFPACopy, 132 // pmChipCopyStructure, etc. This function just does the mechanics of binning. 133 // We don't even update the CELL.XBIN, CELL.YBIN because that would apply the correction twice. 134 134 } 135 135
Note:
See TracChangeset
for help on using the changeset viewer.
