8 #ifndef META_OCEAN_CV_HISTOGRAM_H
9 #define META_OCEAN_CV_HISTOGRAM_H
39 template <
unsigned int tChannels>
51 template <
unsigned int tChannel, u
int8_t tIndex>
52 inline unsigned int bin()
const;
61 template <
unsigned int tChannel>
62 inline unsigned int bin(
const uint8_t index)
const;
70 inline unsigned int bin(
const unsigned int channel,
const uint8_t index)
const;
77 inline unsigned int sumBin(
const uint8_t index)
const;
84 template <
unsigned int tChannel>
85 inline const unsigned int* bins()
const;
92 inline const unsigned int* bins(
const unsigned int channel)
const;
99 template <
unsigned int tChannel>
100 unsigned int determineHighestValue()
const;
107 unsigned int determineHighestValue(
const unsigned int channel)
const;
120 unsigned int determineStartBin(
const unsigned int channel)
const;
127 unsigned int determineEndBin(
const unsigned int channel)
const;
133 inline void normalize(
const unsigned int newMaximalValue);
140 inline void normalize(
const unsigned int channel,
const unsigned int newMaximalValue);
151 inline bool isNull()
const;
179 inline const unsigned int* operator()()
const;
194 void setBin(
const unsigned int channel,
const uint8_t index,
const unsigned int value);
199 unsigned int histogramBins[256u * tChannels];
206 template <
unsigned int tChannels>
221 template <
unsigned int tChannel>
222 inline void incrementBin(
const uint8_t index);
229 inline void incrementBin(
const unsigned int channel,
const uint8_t index);
236 inline void increment(
const uint8_t* pixel);
251 template <
unsigned int tChannels>
283 template <
unsigned int tChannels>
307 template <
unsigned int tChannel>
308 uint8_t lookup(
const uint8_t index)
const;
316 uint8_t lookup(
const unsigned int channel,
const uint8_t index)
const;
321 uint8_t lookupData[256u * tChannels];
336 template <
unsigned int tChannels>
337 static Histogram8BitPerChannel<tChannels> determineHistogram8BitPerChannel(
const uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
Worker* worker =
nullptr);
353 template <
unsigned int tChannels>
354 static Histogram8BitPerChannel<tChannels> determineHistogram8BitPerChannel(
const uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int subframeLeft,
const unsigned int subframeTop,
const unsigned int subframeWidth,
const unsigned int subframeHeight,
const unsigned int framePaddingElements,
Worker* worker =
nullptr);
419 template <
unsigned int tChannels>
420 static bool adjustColorToReference(uint8_t* frame,
const unsigned int frameWidth,
const unsigned int frameHeight,
const uint8_t* reference,
const unsigned int referenceWidth,
const unsigned int referenceHeight,
const unsigned int horizontalBins,
const unsigned int verticalBins,
const unsigned int framePaddingElements,
const unsigned int referencePaddingElements,
Worker* worker =
nullptr);
446 template <
unsigned int tChannels>
447 static inline bool equalization(uint8_t* frame,
const unsigned int width,
const unsigned int height,
const Scalar factor,
const unsigned int framePaddingElements,
Worker* worker =
nullptr);
463 template <
unsigned int tChannels>
464 static inline bool equalization(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const Scalar factor,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
479 template <
unsigned int tChannels>
499 template <
unsigned int tChannels>
500 static bool equalization(uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int subframeLeft,
const unsigned int subframeTop,
const unsigned int subframeWidth,
const unsigned int subframeHeight,
const IntegralHistogram8BitPerChannel<tChannels>& normalizedIntegral,
const Scalar factor,
const unsigned int framePaddingElements,
Worker* worker =
nullptr);
517 template <
unsigned int tChannels>
518 static inline bool equalization(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const IntegralHistogram8BitPerChannel<tChannels>& normalizedIntegral,
const Scalar factor,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
539 template <
unsigned int tChannels>
540 static bool equalization(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int subframeLeft,
const unsigned int subframeTop,
const unsigned int subframeWidth,
const unsigned int subframeHeight,
const IntegralHistogram8BitPerChannel<tChannels>& normalizedIntegral,
const Scalar factor,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
557 template <
unsigned int tChannels>
558 static bool adjustColorToReference(uint8_t* frame,
const unsigned int frameWidth,
const unsigned int frameHeight,
const uint8_t* reference,
const unsigned int referenceWidth,
const unsigned int referenceHeight,
const unsigned int framePaddingElements,
const unsigned int referencePaddingElements,
Worker* worker =
nullptr);
578 template <
unsigned int tChannels>
579 static bool adjustColorToReference(
const uint8_t* source, uint8_t* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const uint8_t* reference,
const unsigned int referenceWidth,
const unsigned int referenceHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const unsigned int referencePaddingElements,
Worker* worker =
nullptr);
593 template <
unsigned int tChannels>
594 static inline bool adjustColorToReference(uint8_t* frame,
const unsigned int width,
const unsigned int height,
const IntegralHistogram8BitPerChannel<tChannels>& invertedNormalizedReferenceIntegral,
const unsigned int framePaddingElements,
Worker* worker =
nullptr);
612 template <
unsigned int tChannels>
613 static bool adjustColorToReference(uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int subframeLeft,
const unsigned int subframeTop,
const unsigned int subframeWidth,
const unsigned int subframeHeight,
const IntegralHistogram8BitPerChannel<tChannels>& invertedNormalizedReferenceIntegral,
const unsigned int framePaddingElements,
Worker* worker =
nullptr);
630 template <
unsigned int tChannels>
631 static inline bool adjustColorToReference(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const IntegralHistogram8BitPerChannel<tChannels>& invertedNormalizedReferenceIntegral,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
652 template <
unsigned int tChannels>
653 static bool adjustColorToReference(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int subframeLeft,
const unsigned int subframeTop,
const unsigned int subframeWidth,
const unsigned int subframeHeight,
const IntegralHistogram8BitPerChannel<tChannels>& invertedNormalizedReferenceIntegral,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
671 template <
unsigned int tChannels>
672 static void determineHistogram8BitPerChannelSubset(
const uint8_t* frame,
const unsigned int width,
const unsigned int height,
Histogram8BitPerChannel<tChannels>* histogram,
Lock* lock,
const unsigned int firstColumn,
const unsigned int numberColumns,
const unsigned int framePaddingElements,
const unsigned int firstRow,
const unsigned int numberRows);
689 template <
unsigned int tChannels>
690 static void equalizationSubset(uint8_t* frame,
const unsigned int width,
const unsigned int height,
const IntegralHistogram8BitPerChannel<tChannels>* normalizedIntegral,
const unsigned int factor,
const unsigned int firstColumn,
const unsigned int numberColumns,
const unsigned int framePaddingElements,
const unsigned int firstRow,
const unsigned int numberRows);
709 template <
unsigned int tChannels>
710 static void equalizationOfTargetSubset(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const IntegralHistogram8BitPerChannel<tChannels>* normalizedIntegral,
const unsigned int factor,
const unsigned int firstColumn,
const unsigned int numberColumns,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const unsigned int firstRow,
const unsigned int numberRows);
726 template <
unsigned int tChannels>
727 static void adjustColorToReferenceSubset(uint8_t* frame,
const unsigned int width,
const unsigned int height,
const LookupTable8BitPerChannel<tChannels>* lookupTable,
const unsigned int firstColumn,
const unsigned int numberColumns,
const unsigned int framePaddingElements,
const unsigned int firstRow,
const unsigned int numberRows);
746 template <
unsigned int tChannels>
747 static void adjustColorToReferenceOfTargetSubset(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const LookupTable8BitPerChannel<tChannels>* lookupTable,
const unsigned int firstColumn,
const unsigned int numberColumns,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const unsigned int firstRow,
const unsigned int numberRows);
759 static constexpr
unsigned int histogramSize = 256u;
782 static void equalization8BitPerChannel(
const uint8_t*
const source,
const unsigned int width,
const unsigned height, uint8_t*
const target,
const Scalar clipLimit =
Scalar(40),
const unsigned int horizontalTiles = 8u,
const unsigned int verticalTiles = 8u,
const unsigned int sourcePaddingElements = 0u,
const unsigned int targetPaddingElements = 0u,
Worker* worker =
nullptr);
795 static inline void computeLookupTable(
const uint8_t* source,
const unsigned int width,
const unsigned int height, uint8_t*
const lookupTable,
const Scalar clipLimit,
const unsigned int sourcePaddingElements = 0u);
836 static void bilinearInterpolation(
const uint8_t*
const source,
const TileLookupCenter2& lookupCenter2, uint8_t*
const target,
const std::vector<uint8_t>& tileLookupTables,
const unsigned int sourcePaddingElements = 0u,
const unsigned int targetPaddingElements = 0u,
Worker* worker =
nullptr);
848 static void computeTileLookupTablesSubset(
const uint8_t*
const source,
const TileLookupCenter2* lookupCenter2, uint8_t*
const tileLookupTables,
const Scalar clipLimit,
const unsigned int sourcePaddingElements = 0u,
const unsigned int firstTile = 0u,
const unsigned int tileCount = 0u);
863 static void bilinearInterpolation7BitPrecisionSubset(
const uint8_t*
const source,
const TileLookupCenter2* lookupCenter2, uint8_t*
const target,
const uint8_t*
const tileLookupTables,
const Index32*
const leftBins,
const uint8_t*
const leftFactors_fixed7,
const unsigned int sourcePaddingElements = 0u,
const unsigned int targetPaddingElements = 0u,
const unsigned int rowStart = 0u,
const unsigned int rowCount = 0u);
865 #if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
882 static void bilinearInterpolationNEON7BitPrecisionSubset(
const uint8_t*
const source,
const TileLookupCenter2* lookupCenter2, uint8_t*
const target,
const uint8_t*
const tileLookupTables,
const Index32*
const leftBins,
const uint8_t*
const leftFactors_fixed7,
const Index32*
const topBins,
const uint8_t*
const topFactors_fixed7,
const unsigned int sourcePaddingElements = 0u,
const unsigned int targetPaddingElements = 0u,
const unsigned int tileStart = 0u,
const unsigned int tileCount = 0u);
889 ocean_assert(source !=
nullptr);
890 ocean_assert(width != 0u && height != 0u);
891 ocean_assert(lookupTable !=
nullptr);
892 ocean_assert(clipLimit >=
Scalar(0));
894 const unsigned int sourceArea = width * height;
895 const unsigned int sourceStrideElements = width + sourcePaddingElements;
896 const uint8_t*
const sourceEnd = source + height * sourceStrideElements;
900 memset(histogram.data(), 0u, histogram.size() *
sizeof(TileHistogram::value_type));
901 const unsigned int widthEnd = width >= 4u ? width - 4u : 0u;
903 for (
unsigned int y = 0u; y < height; ++y)
909 ocean_assert_and_suppress_unused(source + x + 3u < sourceEnd, sourceEnd);
910 histogram[source[x + 0u]]++;
911 histogram[source[x + 1u]]++;
912 histogram[source[x + 2u]]++;
913 histogram[source[x + 3u]]++;
920 ocean_assert(source + x < sourceEnd);
921 histogram[source[x]]++;
926 source += sourceStrideElements;
931 const unsigned int scaledClipLimit = std::max(1u, (
unsigned int)(clipLimit *
float(sourceArea) /
float(
histogramSize)));
932 unsigned int clippedArea = 0u;
936 if (histogram[i] > scaledClipLimit)
938 clippedArea += histogram[i] - scaledClipLimit;
939 histogram[i] = scaledClipLimit;
943 if (clippedArea != 0u)
945 const unsigned int redistribution = clippedArea /
histogramSize;
946 const unsigned int residual = clippedArea - (redistribution *
histogramSize);
948 for (
unsigned int i = 0u; i < residual; ++i)
950 histogram[i] += (redistribution + 1u);
955 histogram[i] += redistribution;
960 ocean_assert(sourceArea != 0u);
961 const float normalizationFactor = float(
histogramSize - 1u) / float(sourceArea);
962 unsigned int sum = 0u;
968 ocean_assert((
int)(
float(sum) * normalizationFactor + 0.5f) >= 0);
970 lookupTable[i] = (uint8_t)(
float(sum) * normalizationFactor + 0.5f);
974 template <
unsigned int tChannels>
977 memset(histogramBins, 0x00,
sizeof(
unsigned int) * 256u * tChannels);
980 template <
unsigned int tChannels>
981 template <
unsigned int tChannel>
984 static_assert(tChannel < tChannels,
"Invalid channel index!");
986 return histogramBins[tChannel * 256u + index];
989 template <
unsigned int tChannels>
992 ocean_assert(channel < tChannels);
994 return histogramBins[channel * 256u + index];
997 template <
unsigned int tChannels>
1000 unsigned int result = 0u;
1002 for (
unsigned int n = 0u; n < tChannels; ++n)
1004 result += histogramBins[n * 256u + index];
1010 template <
unsigned int tChannels>
1011 template <
unsigned int tChannel>
1014 static_assert(tChannel < tChannels,
"Invalid channel index!");
1016 return histogramBins + 256u * tChannel;
1019 template <
unsigned int tChannels>
1022 ocean_assert(channel < tChannels);
1024 return histogramBins + 256u * channel;
1027 template <
unsigned int tChannels>
1028 template <
unsigned int tChannel>
1031 static_assert(tChannel < tChannels,
"Invalid channel index!");
1033 unsigned int value = 0u;
1034 const unsigned int* bins = histogramBins + 256u * tChannel;
1036 for (
unsigned int n = 0u; n < 256u; ++n)
1038 if (bins[n] > value)
1047 template <
unsigned int tChannels>
1050 ocean_assert(channel < tChannels);
1052 unsigned int value = 0u;
1053 const unsigned int* bins = histogramBins + 256u * channel;
1055 for (
unsigned int n = 0u; n < 256u; ++n)
1057 if (bins[n] > value)
1066 template <
unsigned int tChannels>
1069 unsigned int value = 0u;
1071 for (
unsigned int n = 0u; n < 256u * tChannels; ++n)
1073 if (histogramBins[n] > value)
1075 value = histogramBins[n];
1082 template <
unsigned int tChannels>
1085 ocean_assert(channel < tChannels);
1087 const unsigned int* bins = histogramBins + 256u * channel;
1089 for (
unsigned int n = 0u; n < 256u; ++n)
1097 return (
unsigned int)(-1);
1100 template <
unsigned int tChannels>
1103 ocean_assert(channel < tChannels);
1105 const unsigned int* bins = histogramBins + 256u * channel;
1107 for (
unsigned int n = 255u; n < 256u; --n)
1115 return (
unsigned int)(-1);
1118 template <
unsigned int tChannels>
1121 const unsigned int maximalValue = determineHighestValue();
1123 if (maximalValue == 0u)
1128 const unsigned int maximalValue_2 = maximalValue / 2u;
1130 for (
unsigned int n = 0u; n < 256u * tChannels; ++n)
1132 histogramBins[n] = (histogramBins[n] * newMaximalValue + maximalValue_2) / maximalValue;
1136 template <
unsigned int tChannels>
1139 ocean_assert(channel < tChannels);
1141 const unsigned int maximalValue = determineHighestValue(channel);
1143 if (maximalValue == 0u)
1148 const unsigned int maximalValue_2 = maximalValue / 2u;
1150 unsigned int* bins = histogramBins + 256u * channel;
1152 for (
unsigned int n = 0u; n < 256u; ++n)
1154 bins[n] = (bins[n] * newMaximalValue + maximalValue_2) / maximalValue;
1158 template <
unsigned int tChannels>
1161 memset(histogramBins, 0x00,
sizeof(
unsigned int) * 256u * tChannels);
1164 template <
unsigned int tChannels>
1167 for (
unsigned int n = 0u; n < 256u * tChannels; ++n)
1178 template <
unsigned int tChannels>
1181 return !(*
this == histogram);
1184 template <
unsigned int tChannels>
1187 for (
unsigned int n = 0u; n < 256u * tChannels; ++n)
1195 template <
unsigned int tChannels>
1198 return histogramBins;
1201 template <
unsigned int tChannels>
1204 ocean_assert(channel < tChannels);
1206 histogramBins[channel * 256u + index] = value;
1209 template <
unsigned int tChannels>
1212 for (
unsigned int n = 0u; n < 256u * tChannels; ++n)
1214 if (histogramBins[n] != 0u)
1223 template <
unsigned int tChannels>
1230 template <
unsigned int tChannels>
1231 template <
unsigned int tChannel>
1234 static_assert(tChannel < tChannels,
"Invalid channel index!");
1239 template <
unsigned int tChannels>
1242 ocean_assert(channel < tChannels);
1247 template <
unsigned int tChannels>
1250 ocean_assert(pixel !=
nullptr);
1252 for (
unsigned int n = 0u; n < tChannels; ++n)
1258 template <
unsigned int tChannels>
1263 for (
unsigned int n = 0u; n < 256u * tChannels; ++n)
1271 template <
unsigned int tChannels>
1278 template <
unsigned int tChannels>
1282 for (
unsigned int c = 0u; c < tChannels; ++c)
1284 const unsigned int*
const bins = histogram.
bins(c);
1288 thisBins[0] =
bins[0];
1291 for (
unsigned int b = 1u; b < 256u; ++b)
1293 thisBins[b] = thisBins[b - 1u] +
bins[b];
1300 for (
unsigned int c = 1u; c < tChannels; ++c)
1308 template <
unsigned int tChannels>
1315 for (
unsigned int c = 0u; c < tChannels; ++c)
1317 for (
unsigned int n = 0u; n < 256u; ++n)
1321 for (
int r =
int(value); r >= 0; --r)
1323 if (result.
bin(c, (uint8_t)(r)) == 0)
1325 result.
setBin(c, (uint8_t)(r), n);
1338 template <
unsigned int tChannels>
1341 for (
unsigned int c = 0u; c < tChannels; ++c)
1343 for (
unsigned int n = 0u; n < 256u; ++n)
1345 lookupData[c * 256u + n] = n;
1350 template <
unsigned int tChannels>
1356 for (
unsigned int c = 0u; c < tChannels; ++c)
1358 for (
unsigned int n = 0u; n < 256u; ++n)
1360 lookupData[c * 256u + n] = (uint8_t)(invertedNormalizedHistogram.
bin(c, (uint8_t)(normalizedHistogram.
bin(c, (uint8_t)(n)))));
1365 template <
unsigned int tChannels>
1366 template <
unsigned int tChannel>
1369 static_assert(tChannel < tChannels,
"Invalid channel!");
1371 return lookupData[tChannel * 256u + index];
1374 template <
unsigned int tChannels>
1377 ocean_assert(channel < tChannels);
1379 return lookupData[channel * 256u + index];
1382 template <
unsigned int tChannels>
1385 ocean_assert(frame && width >= 1u && height >= 1u);
1392 worker->
executeFunction(
Worker::Function::createStatic(determineHistogram8BitPerChannelSubset<tChannels>, frame, width, height, &result, &lock, 0u, width, framePaddingElements, 0u, 0u), 0u, height, 8u, 9u, 20u);
1396 if (framePaddingElements == 0u)
1398 const uint8_t*
const frameEnd = frame + height * width * tChannels;
1400 while (frame != frameEnd)
1408 for (
unsigned int y = 0u; y < height; ++y)
1410 for (
unsigned int x = 0u; x < width; ++x)
1416 frame += framePaddingElements;
1424 template <
unsigned int tChannels>
1427 ocean_assert(frame && width >= 1u && height >= 1u);
1429 ocean_assert(subframeLeft + subframeWidth <= width);
1430 ocean_assert(subframeTop + subframeHeight <= height);
1437 worker->
executeFunction(
Worker::Function::createStatic(determineHistogram8BitPerChannelSubset<tChannels>, frame, width, height, &result, &lock, subframeLeft, subframeWidth, framePaddingElements, 0u, 0u), subframeTop, subframeHeight, 8u, 9u, 20u);
1441 determineHistogram8BitPerChannelSubset<tChannels>(frame, width, height, &result,
nullptr, subframeLeft, subframeWidth, framePaddingElements, subframeTop, subframeHeight);
1447 template <
unsigned int tChannels>
1448 bool Histogram::adjustColorToReference(uint8_t* frame,
const unsigned int frameWidth,
const unsigned int frameHeight,
const uint8_t* reference,
const unsigned int referenceWidth,
const unsigned int referenceHeight,
const unsigned int horizontalBins,
const unsigned int verticalBins,
const unsigned int framePaddingElements,
const unsigned int referencePaddingElements,
Worker* worker)
1450 ocean_assert(frame !=
nullptr && reference !=
nullptr);
1452 ocean_assert(horizontalBins > 0u && verticalBins > 0u);
1453 ocean_assert(horizontalBins <= min(frameWidth, referenceWidth));
1454 ocean_assert(verticalBins <= min(frameHeight, referenceHeight));
1456 if (frame ==
nullptr || reference ==
nullptr || verticalBins == 0u || horizontalBins == 0u || horizontalBins > frameWidth || horizontalBins > referenceWidth || verticalBins > frameHeight || verticalBins > referenceHeight)
1461 std::vector<LookupTable8BitPerChannel<tChannels>> lookups;
1462 lookups.reserve(horizontalBins * verticalBins);
1465 for (
unsigned int y = 0; y < verticalBins; ++y)
1467 for (
unsigned int x = 0; x < horizontalBins; ++x)
1469 const unsigned int referenceBinLeft = x * referenceWidth / horizontalBins;
1470 const unsigned int referenceBinTop = y * referenceHeight / verticalBins;
1472 const unsigned int referenceBinRight = min((x + 1) * referenceWidth / horizontalBins, referenceWidth);
1473 const unsigned int referenceBinBottom = min((y + 1) * referenceHeight / verticalBins, referenceHeight);
1475 const unsigned int referenceBinWidth = referenceBinRight - referenceBinLeft;
1476 const unsigned int referenceBinHeight = referenceBinBottom - referenceBinTop;
1478 IntegralHistogram8BitPerChannel<tChannels> integralReferenceHistogram(determineHistogram8BitPerChannel<tChannels>(reference, referenceWidth, referenceHeight, referenceBinLeft, referenceBinTop, referenceBinWidth, referenceBinHeight, referencePaddingElements, worker));
1479 integralReferenceHistogram.
normalize(0xFF);
1481 const unsigned int frameBinLeft = x * frameWidth / horizontalBins;
1482 const unsigned int frameBinTop = y * frameHeight / verticalBins;
1484 const unsigned int frameBinRight = min((x + 1) * frameWidth / horizontalBins, frameWidth);
1485 const unsigned int frameBinBottom = min((y + 1) * frameHeight / verticalBins, frameHeight);
1487 const unsigned int frameBinWidth = frameBinRight - frameBinLeft;
1488 const unsigned int frameBinHeight = frameBinBottom - frameBinTop;
1490 IntegralHistogram8BitPerChannel<tChannels> frameHistogram(determineHistogram8BitPerChannel<tChannels>(frame, frameWidth, frameHeight, frameBinLeft, frameBinTop, frameBinWidth, frameBinHeight, framePaddingElements, worker));
1497 const unsigned int frameStrideElements = frameWidth * tChannels + framePaddingElements;
1499 for (
unsigned int y = 0u; y < frameHeight; ++y)
1501 for (
unsigned int x = 0u; x < frameWidth; ++x)
1503 const unsigned int xBin = (x * horizontalBins) / frameWidth;
1504 const unsigned int yBin = (y * verticalBins) / frameHeight;
1506 const unsigned int xBinCenter = (xBin * frameWidth / horizontalBins + min((xBin + 1u) * frameWidth / horizontalBins, frameWidth)) / 2u;
1507 const unsigned int yBinCenter = (yBin * frameHeight / verticalBins + min((yBin + 1u) * frameHeight / verticalBins, frameHeight)) / 2u;
1509 ocean_assert(xBinCenter < frameWidth);
1510 ocean_assert(yBinCenter < frameHeight);
1512 const unsigned int xLowBin = (x >= xBinCenter) ? xBin : max(0,
int(xBin) - 1);
1513 const unsigned int xHighBin = (x < xBinCenter) ? xBin : min(xLowBin + 1u, horizontalBins - 1u);
1515 const unsigned int yLowBin = (y >= yBinCenter) ? yBin : max(0,
int(yBin) - 1);
1516 const unsigned int yHighBin = (y < yBinCenter) ? yBin : min(yLowBin + 1u, verticalBins - 1u);
1518 ocean_assert(((xLowBin == 0u || xLowBin == horizontalBins - 1u) && xHighBin == xLowBin) || xLowBin + 1u == xHighBin);
1519 ocean_assert(((yLowBin == 0u || yLowBin == verticalBins - 1u) && yHighBin == yLowBin) || yLowBin + 1u == yHighBin);
1521 const unsigned int leftCenter = (xLowBin * frameWidth / horizontalBins + min((xLowBin + 1u) * frameWidth / horizontalBins, frameWidth)) / 2u;
1522 const unsigned int rightCenter = (xHighBin * frameWidth / horizontalBins + min((xHighBin + 1u) * frameWidth / horizontalBins, frameWidth)) / 2u;
1524 const unsigned int topCenter = (yLowBin * frameHeight / verticalBins + min((yLowBin + 1u) * frameHeight / verticalBins, frameHeight)) / 2u;
1525 const unsigned int bottomCenter = (yHighBin * frameHeight / verticalBins + min((yHighBin + 1u) * frameHeight / verticalBins, frameHeight)) / 2u;
1528 ocean_assert(leftCenter <= rightCenter);
1529 ocean_assert(topCenter <= bottomCenter);
1531 const unsigned int centerWidth = rightCenter - leftCenter;
1532 const unsigned int centerHeight = bottomCenter - topCenter;
1534 const unsigned int xFactor = centerWidth != 0u ? (abs(
int(x) -
int(leftCenter)) * 256u + centerWidth / 2u) / centerWidth : 256u;
1535 const unsigned int yFactor = centerHeight != 0u ? (abs(
int(y) -
int(topCenter)) * 256u + centerHeight / 2u) / centerHeight : 256u;
1537 ocean_assert(xFactor <= 256u);
1538 ocean_assert(yFactor <= 256u);
1540 uint8_t*
const framePixel = frame + y * frameStrideElements + x * tChannels;
1547 const unsigned int factorTopLeft = (256u - xFactor) * (256u - yFactor);
1548 const unsigned int factorTopRight = xFactor * (256u - yFactor);
1549 const unsigned int factorBottomLeft = (256u - xFactor) * yFactor;
1550 const unsigned int factorBottomRight = xFactor * yFactor;
1552 for (
unsigned int n = 0u; n < tChannels; ++n)
1554 const uint8_t value = framePixel[n];
1556 framePixel[n] = (uint8_t)((topLeft.
lookup(n, value) * factorTopLeft + topRight.
lookup(n, value) * factorTopRight
1557 + bottomLeft.
lookup(n, value) * factorBottomLeft + bottomRight.
lookup(n, value) * factorBottomRight + 32768u) >> 16u);
1565 template <
unsigned int tChannels>
1568 ocean_assert(frame && width > 0u && height > 0u);
1569 ocean_assert(factor >= 0 && factor <= 1);
1571 if (factor < 0 || factor > 1)
1579 return equalization<tChannels>(frame, width, height, integralHistogram, factor, framePaddingElements, worker);
1582 template <
unsigned int tChannels>
1583 inline bool Histogram::equalization(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const Scalar factor,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker)
1585 ocean_assert(source && target && width > 0u && height > 0u);
1586 ocean_assert(factor >= 0 && factor <= 1);
1588 if (factor < 0 || factor > 1)
1596 return equalization<tChannels>(source, target, width, height, integralHistogram, factor, sourcePaddingElements, targetPaddingElements, worker);
1599 template <
unsigned int tChannels>
1602 return equalization<tChannels>(frame, width, height, 0u, 0u, width, height, normalizedIntegral, factor, framePaddingElements, worker);
1605 template <
unsigned int tChannels>
1606 bool Histogram::equalization(uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int subframeLeft,
const unsigned int subframeTop,
const unsigned int subframeWidth,
const unsigned int subframeHeight,
const IntegralHistogram8BitPerChannel<tChannels>& normalizedIntegral,
const Scalar factor,
const unsigned int framePaddingElements,
Worker* worker)
1608 ocean_assert(frame && width > 0u && height > 0u);
1609 ocean_assert(factor >= 0 && factor <= 1);
1611 ocean_assert(subframeLeft + subframeWidth <= width);
1612 ocean_assert(subframeTop + subframeHeight <= height);
1614 if (factor < 0 || factor > 1 || subframeLeft + subframeWidth > width || subframeTop + subframeHeight > height)
1619 const unsigned int iFactor = (
unsigned int)(factor *
Scalar(256));
1623 worker->
executeFunction(
Worker::Function::createStatic(equalizationSubset<tChannels>, frame, width, height, (
const IntegralHistogram8BitPerChannel<tChannels>*)&normalizedIntegral, iFactor, subframeLeft, subframeWidth, framePaddingElements, 0u, 0u), 0u, height, 8u, 9u, 20u);
1627 equalizationSubset<tChannels>(frame, width, height, &normalizedIntegral, iFactor, subframeLeft, subframeWidth, framePaddingElements, subframeTop, subframeHeight);
1633 template <
unsigned int tChannels>
1636 return equalization<tChannels>(source, target, width, height, 0u, 0u, width, height, normalizedIntegral, factor, sourcePaddingElements, targetPaddingElements, worker);
1639 template <
unsigned int tChannels>
1640 bool Histogram::equalization(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int subframeLeft,
const unsigned int subframeTop,
const unsigned int subframeWidth,
const unsigned int subframeHeight,
const IntegralHistogram8BitPerChannel<tChannels>& normalizedIntegral,
const Scalar factor,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker)
1642 ocean_assert(source && target && width > 0u && height > 0u);
1643 ocean_assert(factor >= 0 && factor <= 1);
1645 ocean_assert(subframeLeft + subframeWidth <= width);
1646 ocean_assert(subframeTop + subframeHeight <= height);
1648 if (factor < 0 || factor > 1 || subframeLeft + subframeWidth > width || subframeTop + subframeHeight > height)
1653 const unsigned int iFactor = (
unsigned int)(factor *
Scalar(256));
1657 worker->
executeFunction(
Worker::Function::createStatic(equalizationOfTargetSubset<tChannels>, source, target, width, height, &normalizedIntegral, iFactor, subframeLeft, subframeWidth, sourcePaddingElements, targetPaddingElements, 0u, 0u), subframeTop, subframeHeight, 10u, 11u, 20u);
1661 equalizationOfTargetSubset<tChannels>(source, target, width, height, &normalizedIntegral, iFactor, subframeLeft, subframeWidth, sourcePaddingElements, targetPaddingElements, subframeTop, subframeHeight);
1667 template <
unsigned int tChannels>
1668 bool Histogram::adjustColorToReference(uint8_t* frame,
const unsigned int frameWidth,
const unsigned int frameHeight,
const uint8_t* reference,
const unsigned int referenceWidth,
const unsigned int referenceHeight,
const unsigned int framePaddingElements,
const unsigned int referencePaddingElements,
Worker* worker)
1670 ocean_assert(frame && reference);
1673 integralReferenceHistogram.
normalize(0xFF);
1676 return adjustColorToReference<tChannels>(frame, frameWidth, frameHeight, invertedReferenceHistogram, framePaddingElements, worker);
1679 template <
unsigned int tChannels>
1680 bool Histogram::adjustColorToReference(
const uint8_t* source, uint8_t* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const uint8_t* reference,
const unsigned int referenceWidth,
const unsigned int referenceHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const unsigned int referencePaddingElements,
Worker* worker)
1682 ocean_assert(source && target && reference);
1685 integralReferenceHistogram.
normalize(0xFF);
1688 return adjustColorToReference<tChannels>(source, target, sourceWidth, sourceHeight, invertedReferenceHistogram, sourcePaddingElements, targetPaddingElements, worker);
1691 template <
unsigned int tChannels>
1694 return adjustColorToReference<tChannels>(frame, width, height, 0u, 0u, width, height, invertedNormalizedReferenceIntegral, framePaddingElements, worker);
1697 template <
unsigned int tChannels>
1700 ocean_assert(frame);
1702 if (!frame || subframeLeft + subframeWidth > width || subframeTop + subframeHeight > height)
1714 worker->
executeFunction(
Worker::Function::createStatic(adjustColorToReferenceSubset<tChannels>, frame, width, height, &lookupTable, subframeLeft, subframeWidth, framePaddingElements, 0u, 0u), subframeTop, subframeHeight, 8u, 9u, 20u);
1718 adjustColorToReferenceSubset<tChannels>(frame, width, height, &lookupTable, subframeLeft, subframeWidth, framePaddingElements, subframeTop, subframeHeight);
1724 template <
unsigned int tChannels>
1727 return adjustColorToReference<tChannels>(source, target, width, height, 0u, 0u, width, height, invertedNormalizedReferenceIntegral, sourcePaddingElements, targetPaddingElements, worker);
1730 template <
unsigned int tChannels>
1731 bool Histogram::adjustColorToReference(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int subframeLeft,
const unsigned int subframeTop,
const unsigned int subframeWidth,
const unsigned int subframeHeight,
const IntegralHistogram8BitPerChannel<tChannels>& invertedNormalizedReferenceIntegral,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker)
1733 ocean_assert(source && target);
1735 if (!source || !target || subframeLeft + subframeWidth > width || subframeTop + subframeHeight > height)
1747 worker->
executeFunction(
Worker::Function::createStatic(adjustColorToReferenceOfTargetSubset<tChannels>, source, target, width, height, &lookupTable, subframeLeft, subframeWidth, sourcePaddingElements, targetPaddingElements, 0u, 0u), subframeTop, subframeHeight, 9u, 10u, 20u);
1751 adjustColorToReferenceOfTargetSubset<tChannels>(source, target, width, height, &lookupTable, subframeLeft, subframeWidth, sourcePaddingElements, targetPaddingElements, subframeTop, subframeHeight);
1757 template <
unsigned int tChannels>
1760 ocean_assert(frame !=
nullptr);
1762 ocean_assert(firstColumn + numberColumns <= width);
1763 ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
1767 if (numberColumns == width && framePaddingElements == 0u)
1769 ocean_assert(firstColumn == 0u);
1771 frame += firstRow * width * tChannels;
1772 const uint8_t*
const frameEnd = frame + numberRows * width * tChannels;
1774 while (frame != frameEnd)
1780 else if (framePaddingElements == 0u)
1783 const uint8_t*
const debugFrame = frame;
1786 frame += (firstRow * width + firstColumn) * tChannels;
1787 const uint8_t*
const frameEnd = frame + numberRows * width * tChannels;
1789 const unsigned int rowOffset = (width - numberColumns) * tChannels;
1791 while (frame != frameEnd)
1793 ocean_assert(frame < frameEnd);
1794 ocean_assert((frame - debugFrame) % (width * tChannels) == firstColumn * tChannels);
1796 const uint8_t*
const frameRowEnd = frame + numberColumns * tChannels;
1798 while (frame != frameRowEnd)
1800 ocean_assert(frame < frameEnd);
1801 ocean_assert(frame < frameRowEnd);
1812 const unsigned int frameStrideElements = width * tChannels + framePaddingElements;
1813 frame += firstRow * frameStrideElements + firstColumn * tChannels;
1815 const unsigned int rowOffset = (width - numberColumns) * tChannels + framePaddingElements;
1817 for (
unsigned int y = firstRow; y < firstRow + numberRows; ++y)
1819 for (
unsigned int x = firstColumn; x < firstColumn + numberColumns; ++x)
1830 *histogram += localHistogram;
1833 template <
unsigned int tChannels>
1836 ocean_assert(frame !=
nullptr && normalizedIntegral !=
nullptr);
1837 ocean_assert(width > 0u && height > 0u);
1839 ocean_assert(firstColumn + numberColumns <= width);
1840 ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
1844 ocean_assert(factor <= 256u);
1845 const unsigned int factor_ = 256u - factor;
1847 const unsigned int frameStrideElements = width * tChannels + framePaddingElements;
1849 for (
unsigned int y = firstRow; y < firstRow + numberRows; ++y)
1851 uint8_t* frameRow = frame + y * frameStrideElements + firstColumn * tChannels;
1853 for (
unsigned int x = 0u; x < numberColumns; ++x)
1855 for (
unsigned int n = 0u; n < tChannels; ++n)
1857 frameRow[n] = (uint8_t)((normalizedIntegral->
bin(n, (uint8_t)(frameRow[n])) * factor + frameRow[n] * factor_) >> 8u);
1860 frameRow += tChannels;
1865 template <
unsigned int tChannels>
1866 void Histogram::equalizationOfTargetSubset(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const IntegralHistogram8BitPerChannel<tChannels>* normalizedIntegral,
const unsigned int factor,
const unsigned int firstColumn,
const unsigned int numberColumns,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const unsigned int firstRow,
const unsigned int numberRows)
1868 ocean_assert(source !=
nullptr && target !=
nullptr && normalizedIntegral !=
nullptr);
1869 ocean_assert(width > 0u && height > 0u);
1871 ocean_assert(firstColumn + numberColumns <= width);
1872 ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
1876 ocean_assert(factor <= 256u);
1877 const unsigned int factor_ = 256u - factor;
1879 const unsigned int sourceStrideElements = width * tChannels + sourcePaddingElements;
1880 const unsigned int targetStrideElements = width * tChannels + targetPaddingElements;
1882 for (
unsigned int y = firstRow; y < firstRow + numberRows; ++y)
1884 const uint8_t* sourceRow = source + y * sourceStrideElements + firstColumn * tChannels;
1885 uint8_t* targtRow = target + y * targetStrideElements + firstColumn * tChannels;
1887 for (
unsigned int x = 0u; x < numberColumns; ++x)
1889 for (
unsigned int n = 0u; n < tChannels; ++n)
1891 targtRow[n] = (uint8_t)((normalizedIntegral->
bin(n, sourceRow[n]) * factor + sourceRow[n] * factor_) >> 8u);
1894 sourceRow += tChannels;
1895 targtRow += tChannels;
1900 template <
unsigned int tChannels>
1903 ocean_assert(frame !=
nullptr && lookupTable !=
nullptr);
1905 ocean_assert(firstColumn + numberColumns <= width);
1906 ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
1908 const unsigned int frameStrideElements = width * tChannels + framePaddingElements;
1910 for (
unsigned int y = firstRow; y < firstRow + numberRows; ++y)
1912 uint8_t* frameRow = frame + y * frameStrideElements + firstColumn * tChannels;
1914 for (
unsigned int x = 0u; x < numberColumns; ++x)
1916 for (
unsigned int n = 0u; n < tChannels; ++n)
1918 frameRow[n] = lookupTable->
lookup(n, frameRow[n]);
1921 frameRow += tChannels;
1926 template <
unsigned int tChannels>
1927 void Histogram::adjustColorToReferenceOfTargetSubset(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const LookupTable8BitPerChannel<tChannels>* lookupTable,
const unsigned int firstColumn,
const unsigned int numberColumns,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const unsigned int firstRow,
const unsigned int numberRows)
1929 ocean_assert(source && target && lookupTable);
1931 ocean_assert(firstColumn + numberColumns <= width);
1932 ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
1934 const unsigned int sourceStrideElements = width * tChannels + sourcePaddingElements;
1935 const unsigned int targetStrideElements = width * tChannels + targetPaddingElements;
1937 for (
unsigned int y = firstRow; y < firstRow + numberRows; ++y)
1939 const uint8_t* sourceRow = source + y * sourceStrideElements + firstColumn * tChannels;
1940 uint8_t* targetRow = target + y * targetStrideElements + firstColumn * tChannels;
1942 for (
unsigned int x = 0u; x < numberColumns; ++x)
1944 for (
unsigned int n = 0u; n < tChannels; ++n)
1946 targetRow[n] = lookupTable->
lookup(n, sourceRow[n]);
1949 sourceRow += tChannels;
1950 targetRow += tChannels;
Implementation of Contrast-Limited Adaptive Histogram Equalization (CLAHE).
Definition: Histogram.h:755
static void bilinearInterpolationNEON7BitPrecisionSubset(const uint8_t *const source, const TileLookupCenter2 *lookupCenter2, uint8_t *const target, const uint8_t *const tileLookupTables, const Index32 *const leftBins, const uint8_t *const leftFactors_fixed7, const Index32 *const topBins, const uint8_t *const topFactors_fixed7, const unsigned int sourcePaddingElements=0u, const unsigned int targetPaddingElements=0u, const unsigned int tileStart=0u, const unsigned int tileCount=0u)
Helper function for the histogram normalization by bilinearly interpolating pixels using the CLAHE pe...
LookupCenter2< uint8_t > TileLookupCenter2
Image partitioning and tile boundary lookup.
Definition: Histogram.h:765
static void computeLookupTable(const uint8_t *source, const unsigned int width, const unsigned int height, uint8_t *const lookupTable, const Scalar clipLimit, const unsigned int sourcePaddingElements=0u)
Computation of a lookup table required to normalize an image histogram (used per tile)
Definition: Histogram.h:887
static void bilinearInterpolation7BitPrecisionSubset(const uint8_t *const source, const TileLookupCenter2 *lookupCenter2, uint8_t *const target, const uint8_t *const tileLookupTables, const Index32 *const leftBins, const uint8_t *const leftFactors_fixed7, const unsigned int sourcePaddingElements=0u, const unsigned int targetPaddingElements=0u, const unsigned int rowStart=0u, const unsigned int rowCount=0u)
Integer-based (fixed-point arithmetic) helper function for the histogram normalization by bilinearly ...
static void computeTileLookupTables(const uint8_t *const source, const TileLookupCenter2 &lookupCenter2, std::vector< uint8_t > &tileLookupTables, const Scalar clipLimit, const unsigned int sourcePaddingElements=0u, Worker *worker=nullptr)
Computation of per-tile lookup tables required to normalize an image histogram given a partitioned im...
std::array< unsigned int, histogramSize > TileHistogram
Tile histogram.
Definition: Histogram.h:762
static void bilinearInterpolation(const uint8_t *const source, const TileLookupCenter2 &lookupCenter2, uint8_t *const target, const std::vector< uint8_t > &tileLookupTables, const unsigned int sourcePaddingElements=0u, const unsigned int targetPaddingElements=0u, Worker *worker=nullptr)
Histogram normalization by bilinearly interpolating pixels using the CLAHE per-tile lookup tables.
static void computeTileLookupTablesSubset(const uint8_t *const source, const TileLookupCenter2 *lookupCenter2, uint8_t *const tileLookupTables, const Scalar clipLimit, const unsigned int sourcePaddingElements=0u, const unsigned int firstTile=0u, const unsigned int tileCount=0u)
Helper function for the computation of per-tile lookup tables required to normalize an image histogra...
static void computeLowBilinearInterpolationFactors7BitPrecision(const TileLookupCenter2 &lookupCenter2, const bool isHorizontal, Index32 *lowBins, uint8_t *lowFactors_fixed7)
Computation of the bilinear interpolation parameters for the low bins of an image pixel If isHorizont...
static void equalization8BitPerChannel(const uint8_t *const source, const unsigned int width, const unsigned height, uint8_t *const target, const Scalar clipLimit=Scalar(40), const unsigned int horizontalTiles=8u, const unsigned int verticalTiles=8u, const unsigned int sourcePaddingElements=0u, const unsigned int targetPaddingElements=0u, Worker *worker=nullptr)
Histogram equalization a la CLAHE.
static constexpr unsigned int histogramSize
Number of bins in the tile histograms.
Definition: Histogram.h:759
This class implements a standard histogram object storing 8 bit per channel.
Definition: Histogram.h:208
void incrementBin(const uint8_t index)
Increments a specific bin of this histogram (by one).
Definition: Histogram.h:1232
void increment(const uint8_t *pixel)
Increments all channels of a specific histogram bin (by one).
Definition: Histogram.h:1248
Histogram8BitPerChannel< tChannels > operator+(const Histogram8BitPerChannel< tChannels > &histogram) const
Adds to histogram objects and returns the new histogram.
Definition: Histogram.h:1259
Histogram8BitPerChannel()
Creates a new histogram object and sets all histogram bins to zero.
Definition: Histogram.h:1224
This class implements the base class for all histogram objects holding 8 bit per data channel.
Definition: Histogram.h:41
unsigned int determineHighestValue() const
Determines the highest value within the entire histogram.
unsigned int determineEndBin(const unsigned int channel) const
Determines the last bin that is not zero for a specific channel.
Definition: Histogram.h:1101
void clear()
Clears the entire histogram and sets all bins to zero.
Definition: Histogram.h:1159
void normalize(const unsigned int newMaximalValue)
Normalizes the entire histogram by application of the highest histogram value.
Definition: Histogram.h:1119
unsigned int determineStartBin(const unsigned int channel) const
Determines the first bin that is not zero for a specific channel.
Definition: Histogram.h:1083
void setBin(const unsigned int channel, const uint8_t index, const unsigned int value)
Explicitly sets a value of a specific histogram bin.
Definition: Histogram.h:1202
HistogramBase8BitPerChannel< tChannels > & operator+=(const HistogramBase8BitPerChannel< tChannels > &histogram)
Adds the histogram bins of a second histogram to this histogram.
Definition: Histogram.h:1185
HistogramBase8BitPerChannel()
Creates an empty histogram object and sets all histogram bins to zero.
Definition: Histogram.h:975
const unsigned int * bins() const
Returns the 256 histogram values for a specific channel.
Definition: Histogram.h:1012
unsigned int determineHighestValue() const
Determines the highest value within the histogram for a specific channel.
Definition: Histogram.h:1029
bool isNull() const
Returns whether all bins inside the histogram are zero.
Definition: Histogram.h:1210
const unsigned int * operator()() const
Returns all histogram bins of this histogram.
Definition: Histogram.h:1196
bool operator!=(const HistogramBase8BitPerChannel< tChannels > &histogram) const
Returns whether two histogram objects are not identical according to their histogram bins.
Definition: Histogram.h:1179
unsigned int histogramBins[256u *tChannels]
The histogram bins.
Definition: Histogram.h:199
bool operator==(const HistogramBase8BitPerChannel< tChannels > &histogram) const
Returns whether two histogram objects are identical according to their histogram bins.
Definition: Histogram.h:1165
unsigned int bin() const
Returns the bin value of a specific channel and bin.
unsigned int sumBin(const uint8_t index) const
Returns the sum of all channels stored for a specific bin.
Definition: Histogram.h:998
This class implements an integral histogram object.
Definition: Histogram.h:253
IntegralHistogram8BitPerChannel()
Creates a new integral histogram object and sets all histogram bins to zero.
Definition: Histogram.h:1272
IntegralHistogram8BitPerChannel invert() const
Inverts this (normalized) integral histogram so that the inverted histogram can be used as lookup obj...
Definition: Histogram.h:1309
This class implements a simple lookup table.
Definition: Histogram.h:285
LookupTable8BitPerChannel()
Creates a default lookup table providing the identity lookup result.
Definition: Histogram.h:1339
uint8_t lookup(const uint8_t index) const
Lookup function providing the lookup value for a specific channel and bin.
Definition: Histogram.h:1367
This class implements an image histogram.
Definition: Histogram.h:32
static void adjustColorToReferenceSubset(uint8_t *frame, const unsigned int width, const unsigned int height, const LookupTable8BitPerChannel< tChannels > *lookupTable, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int framePaddingElements, const unsigned int firstRow, const unsigned int numberRows)
Adjusts the color in a subset of a frame according to a given reference frame.
Definition: Histogram.h:1901
static void equalizationOfTargetSubset(const uint8_t *source, uint8_t *target, const unsigned int width, const unsigned int height, const IntegralHistogram8BitPerChannel< tChannels > *normalizedIntegral, const unsigned int factor, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const unsigned int firstRow, const unsigned int numberRows)
Applies a histogram equalization in a subset of a given frame.
Definition: Histogram.h:1866
static bool equalization(const Frame &source, Frame &target, const Scalar factor=1, Worker *worker=nullptr)
Applies a histogram equalization for a given frame.
static bool adjustColorToReference(const Frame &source, Frame &target, const Frame &reference, Worker *worker=nullptr)
Adjusts the color of a frame according to a given reference frame.
static bool adjustColorToReference(Frame &frame, const Frame &reference, const unsigned int horizontalBins, const unsigned int verticalBins, Worker *worker=nullptr)
Adjusts the color of a frame according to a given reference frame while using corresponding bins for ...
static Histogram8BitPerChannel< tChannels > determineHistogram8BitPerChannel(const uint8_t *frame, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, Worker *worker=nullptr)
Determines the standard histogram for a given frame.
Definition: Histogram.h:1383
static bool adjustColorToReference(Frame &frame, const Frame &reference, Worker *worker=nullptr)
Adjusts the color of a frame according to a given reference frame.
static void adjustColorToReferenceOfTargetSubset(const uint8_t *source, uint8_t *target, const unsigned int width, const unsigned int height, const LookupTable8BitPerChannel< tChannels > *lookupTable, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const unsigned int firstRow, const unsigned int numberRows)
Adjusts the color of a frame according to a given reference frame.
Definition: Histogram.h:1927
static bool equalization(Frame &frame, const Scalar factor=1, Worker *worker=nullptr)
Applies a histogram equalization for a given frame.
static void determineHistogram8BitPerChannelSubset(const uint8_t *frame, const unsigned int width, const unsigned int height, Histogram8BitPerChannel< tChannels > *histogram, Lock *lock, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int framePaddingElements, const unsigned int firstRow, const unsigned int numberRows)
Determines the standard histogram in a subset of a given frame.
Definition: Histogram.h:1758
static void equalizationSubset(uint8_t *frame, const unsigned int width, const unsigned int height, const IntegralHistogram8BitPerChannel< tChannels > *normalizedIntegral, const unsigned int factor, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int framePaddingElements, const unsigned int firstRow, const unsigned int numberRows)
Applies a histogram equalization in a subset of a given frame.
Definition: Histogram.h:1834
static Caller< void > createStatic(typename StaticFunctionPointerMaker< void, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass >::Type function)
Creates a new caller container for a static function with no function parameter.
Definition: Caller.h:2876
This class implements Ocean's image class.
Definition: Frame.h:1792
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements a 2D lookup object with values at the bins' center positions defining the indiv...
Definition: Lookup2.h:198
This class provides basic numeric functionalities.
Definition: Numeric.h:57
This class implements an optional recursive scoped lock object locking the lock object only if it's d...
Definition: Lock.h:325
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
bool executeFunction(const Function &function, const unsigned int first, const unsigned int size, const unsigned int firstIndex=(unsigned int)(-1), const unsigned int sizeIndex=(unsigned int)(-1), const unsigned int minimalIterations=1u, const unsigned int threadIndex=(unsigned int)(-1))
Executes a callback function separable by two function parameters.
uint32_t Index32
Definition of a 32 bit index value.
Definition: Base.h:84
float Scalar
Definition of a scalar type.
Definition: Math.h:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15
AutomaticDifferentiationT< T1, TNumeric1 > operator+(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition: AutomaticDifferentiation.h:418