Functions for estimation of image histogram. More...
Functions | |
| SIMD_API void | SimdAbsSecondDerivativeHistogram (const uint8_t *src, size_t width, size_t height, size_t stride, size_t step, size_t indent, uint32_t *histogram) |
| Calculates a histogram of second-derivative magnitudes for an 8-bit gray image. More... | |
| SIMD_API void | SimdHistogram (const uint8_t *src, size_t width, size_t height, size_t stride, uint32_t *histogram) |
| Calculates a histogram for an 8-bit gray image. More... | |
| SIMD_API void | SimdHistogramMasked (const uint8_t *src, size_t srcStride, size_t width, size_t height, const uint8_t *mask, size_t maskStride, uint8_t index, uint32_t *histogram) |
| Calculates a masked histogram for an 8-bit gray image. More... | |
| SIMD_API void | SimdHistogramConditional (const uint8_t *src, size_t srcStride, size_t width, size_t height, const uint8_t *mask, size_t maskStride, uint8_t value, SimdCompareType compareType, uint32_t *histogram) |
| Calculates a conditional masked histogram for an 8-bit gray image. More... | |
| SIMD_API void | SimdNormalizedColors (const uint32_t *histogram, uint8_t *colors) |
| Gets a histogram-equalization color map for a given 256-bin histogram. More... | |
| SIMD_API void | SimdChangeColors (const uint8_t *src, size_t srcStride, size_t width, size_t height, const uint8_t *colors, uint8_t *dst, size_t dstStride) |
| Applies an 8-bit lookup table to an 8-bit gray image. More... | |
| SIMD_API void | SimdNormalizeHistogram (const uint8_t *src, size_t srcStride, size_t width, size_t height, uint8_t *dst, size_t dstStride) |
| Performs histogram equalization for an 8-bit gray image. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | AbsSecondDerivativeHistogram (const View< A > &src, size_t step, size_t indent, uint32_t *histogram) |
| Calculates histogram of second derivative for 8-bit gray image. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | Histogram (const View< A > &src, uint32_t *histogram) |
| Calculates histogram for 8-bit gray image. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | HistogramMasked (const View< A > &src, const View< A > &mask, uint8_t index, uint32_t *histogram) |
| Calculates histogram for 8-bit gray image with using mask. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | HistogramConditional (const View< A > &src, const View< A > &mask, uint8_t value, SimdCompareType compareType, uint32_t *histogram) |
| Calculates histogram of 8-bit gray image for those points when mask points satisfying certain condition. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | ChangeColors (const View< A > &src, const uint8_t *colors, View< A > &dst) |
| Changes colors for 8-bit gray image with using of color map. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | NormalizeHistogram (const View< A > &src, View< A > &dst) |
| Normalizes histogram for 8-bit gray image. More... | |
| SIMD_INLINE double | Mean (const uint32_t *histogram) |
| Calculates mean from image histogram. More... | |
| SIMD_INLINE uint8_t | OtsuThreshold (const uint32_t *histogram) |
| Calculates Otsu threshold from image histogram. More... | |
Detailed Description
Functions for estimation of image histogram.
Function Documentation
◆ SimdAbsSecondDerivativeHistogram()
| void SimdAbsSecondDerivativeHistogram | ( | const uint8_t * | src, |
| size_t | width, | ||
| size_t | height, | ||
| size_t | stride, | ||
| size_t | step, | ||
| size_t | indent, | ||
| uint32_t * | histogram | ||
| ) |
Calculates a histogram of second-derivative magnitudes for an 8-bit gray image.
The function clears histogram and processes only pixels inside the rectangle without the indent-pixel border. For every processed pixel:
avgX = (src[x - step, y] + src[x + step, y] + 1) / 2; avgY = (src[x, y - step] + src[x, y + step] + 1) / 2; dx = Abs(src[x, y] - avgX); dy = Abs(src[x, y] - avgY); histogram[Max(dx, dy)]++;
The output histogram has 256 bins and is overwritten. The parameters must satisfy: width > 2*indent, height > 2*indent and indent >= step.
- Note
- This function has a C++ wrapper Simd::AbsSecondDerivativeHistogram(const View<A>& src, size_t step, size_t indent, uint32_t * histogram).
- Parameters
-
[in] src - a pointer to pixels data of input 8-bit gray image. [in] width - an image width. [in] height - an image height. [in] stride - a row size of the image (in bytes). [in] step - an offset in pixels for second-derivative calculation. [in] indent - a number of pixels skipped at every image boundary. [out] histogram - a pointer to the output histogram (array of 256 unsigned 32-bit values).
◆ SimdHistogram()
| void SimdHistogram | ( | const uint8_t * | src, |
| size_t | width, | ||
| size_t | height, | ||
| size_t | stride, | ||
| uint32_t * | histogram | ||
| ) |
Calculates a histogram for an 8-bit gray image.
The function clears histogram and then counts every pixel:
for(y = 0; y < height; ++y)
for(x = 0; x < width; ++x)
histogram[src[x, y]]++;
The output histogram has 256 bins and is overwritten.
- Note
- This function has a C++ wrapper Simd::Histogram(const View<A>& src, uint32_t * histogram).
- Parameters
-
[in] src - a pointer to pixels data of input 8-bit gray image. [in] width - an image width. [in] height - an image height. [in] stride - a row size of the image (in bytes). [out] histogram - a pointer to the output histogram (array of 256 unsigned 32-bit values).
◆ SimdHistogramMasked()
| void SimdHistogramMasked | ( | const uint8_t * | src, |
| size_t | srcStride, | ||
| size_t | width, | ||
| size_t | height, | ||
| const uint8_t * | mask, | ||
| size_t | maskStride, | ||
| uint8_t | index, | ||
| uint32_t * | histogram | ||
| ) |
Calculates a masked histogram for an 8-bit gray image.
The function clears histogram and counts only source pixels whose mask value is equal to index:
for(y = 0; y < height; ++y)
for(x = 0; x < width; ++x)
if(mask[x, y] == index)
histogram[src[x, y]]++;
The output histogram has 256 bins and is overwritten. The input image and mask must have the same width and height.
- Note
- This function has a C++ wrapper Simd::HistogramMasked(const View<A> & src, const View<A> & mask, uint8_t index, uint32_t * histogram).
- Parameters
-
[in] src - a pointer to pixels data of input 8-bit gray image. [in] srcStride - a row size of the image (in bytes). [in] width - an image width. [in] height - an image height. [in] mask - a pointer to pixels data of the mask 8-bit image. [in] maskStride - a row size of the mask image (in bytes). [in] index - a mask value selecting pixels to count. [out] histogram - a pointer to the output histogram (array of 256 unsigned 32-bit values).
◆ SimdHistogramConditional()
| void SimdHistogramConditional | ( | const uint8_t * | src, |
| size_t | srcStride, | ||
| size_t | width, | ||
| size_t | height, | ||
| const uint8_t * | mask, | ||
| size_t | maskStride, | ||
| uint8_t | value, | ||
| SimdCompareType | compareType, | ||
| uint32_t * | histogram | ||
| ) |
Calculates a conditional masked histogram for an 8-bit gray image.
The function clears histogram and counts only source pixels whose mask value satisfies the comparison with value:
for(y = 0; y < height; ++y)
for(x = 0; x < width; ++x)
if(Compare(mask[x, y], value, compareType))
histogram[src[x, y]]++;
The output histogram has 256 bins and is overwritten. The input image and mask must have the same width and height.
- Note
- This function has a C++ wrapper Simd::HistogramConditional(const View<A>& src, const View<A>& mask, uint8_t value, SimdCompareType compareType, uint32_t * histogram).
- Parameters
-
[in] src - a pointer to pixels data of input 8-bit gray image. [in] srcStride - a row size of the image (in bytes). [in] width - an image width. [in] height - an image height. [in] mask - a pointer to pixels data of the mask 8-bit image. [in] maskStride - a row size of the mask image (in bytes). [in] value - a value to compare with every mask pixel. [in] compareType - a compare operation type (see SimdCompareType). [out] histogram - a pointer to the output histogram (array of 256 unsigned 32-bit values).
◆ SimdNormalizedColors()
| void SimdNormalizedColors | ( | const uint32_t * | histogram, |
| uint8_t * | colors | ||
| ) |
Gets a histogram-equalization color map for a given 256-bin histogram.
The function builds cumulative sums, finds the first non-zero histogram bin minColor with count minCount, and calculates:
integral[i] = Sum(histogram[j]), j <= i;
norm = integral[255] - minCount;
colors[i] = i < minColor ? 0 :
(norm ? (255*(integral[i] - minCount) + norm/2)/norm : minColor);
The output color map can be used by SimdChangeColors.
- Parameters
-
[in] histogram - a pointer to histogram (array of 256 unsigned 32-bit values). [out] colors - a pointer to the color map (array of 256 unsigned 8-bit values).
◆ SimdChangeColors()
| void SimdChangeColors | ( | const uint8_t * | src, |
| size_t | srcStride, | ||
| size_t | width, | ||
| size_t | height, | ||
| const uint8_t * | colors, | ||
| uint8_t * | dst, | ||
| size_t | dstStride | ||
| ) |
Applies an 8-bit lookup table to an 8-bit gray image.
The input and output images must have the same width and height. For every pixel:
for(y = 0; y < height; ++y)
for(x = 0; x < width; ++x)
dst[x, y] = colors[src[x, y]];
- Note
- This function has a C++ wrapper Simd::ChangeColors(const View<A> & src, const uint8_t * colors, View<A> & dst).
- Parameters
-
[in] src - a pointer to pixels data of input 8-bit gray image. [in] srcStride - a row size of the image (in bytes). [in] width - an image width. [in] height - an image height. [in] colors - a pointer to the color map (array of 256 unsigned 8-bit values). [out] dst - a pointer to pixels data of output 8-bit gray image. [in] dstStride - a row size of the output gray image (in bytes).
◆ SimdNormalizeHistogram()
| void SimdNormalizeHistogram | ( | const uint8_t * | src, |
| size_t | srcStride, | ||
| size_t | width, | ||
| size_t | height, | ||
| uint8_t * | dst, | ||
| size_t | dstStride | ||
| ) |
Performs histogram equalization for an 8-bit gray image.
The input and output images must have the same width and height. The function calculates SimdHistogram for src, creates the lookup table with SimdNormalizedColors, and applies it with SimdChangeColors.
- Note
- This function has a C++ wrapper Simd::NormalizeHistogram(const View<A> & src, View<A> & dst).
- Parameters
-
[in] src - a pointer to pixels data of input 8-bit gray image. [in] srcStride - a row size of the image (in bytes). [in] width - an image width. [in] height - an image height. [out] dst - a pointer to pixels data of output 8-bit image with normalized histogram. [in] dstStride - a row size of the output image (in bytes).
◆ AbsSecondDerivativeHistogram()
| void AbsSecondDerivativeHistogram | ( | const View< A > & | src, |
| size_t | step, | ||
| size_t | indent, | ||
| uint32_t * | histogram | ||
| ) |
Calculates histogram of second derivative for 8-bit gray image.
For all points except the boundary (defined by parameter indent):
dx = abs(src[x, y] - average(src[x+step, y], src[x-step, y])); dy = abs(src[x, y] - average(src[x, y+step], src[x, y-step])); histogram[max(dx, dy)]++;
- Note
- This function is a C++ wrapper for function SimdAbsSecondDerivativeHistogram.
- Parameters
-
[in] src - an input 8-bit gray image. [in] step - a step for second derivative calculation. [in] indent - a indent from image boundary. [out] histogram - a pointer to histogram (array of 256 unsigned 32-bit values).
◆ Histogram()
| void Histogram | ( | const View< A > & | src, |
| uint32_t * | histogram | ||
| ) |
Calculates histogram for 8-bit gray image.
For all points:
histogram[src[i]]++.
- Note
- This function is a C++ wrapper for function SimdHistogram.
- Parameters
-
[in] src - an input 8-bit gray image. [out] histogram - a pointer to histogram (array of 256 unsigned 32-bit values).
◆ HistogramMasked()
| void HistogramMasked | ( | const View< A > & | src, |
| const View< A > & | mask, | ||
| uint8_t | index, | ||
| uint32_t * | histogram | ||
| ) |
Calculates histogram for 8-bit gray image with using mask.
For every point:
if(mask[i] == index)
histogram[src[i]]++.
- Note
- This function is a C++ wrapper for function SimdHistogramMasked.
- Parameters
-
[in] src - an input 8-bit gray image. [in] mask - a mask 8-bit image. [in] index - a mask index. [out] histogram - a pointer to histogram (array of 256 unsigned 32-bit values).
◆ HistogramConditional()
| void HistogramConditional | ( | const View< A > & | src, |
| const View< A > & | mask, | ||
| uint8_t | value, | ||
| SimdCompareType | compareType, | ||
| uint32_t * | histogram | ||
| ) |
Calculates histogram of 8-bit gray image for those points when mask points satisfying certain condition.
For every point:
if(compare(mask[x, y], value))
histogram[src[x, y]]++.
- Note
- This function is a C++ wrapper for function SimdHistogramConditional.
- Parameters
-
[in] src - an input 8-bit gray image. [in] mask - a mask 8-bit image. [in] value - a second value for compare operation. [in] compareType - a compare operation type (see SimdCompareType). [out] histogram - a pointer to histogram (array of 256 unsigned 32-bit values).
◆ ChangeColors()
Changes colors for 8-bit gray image with using of color map.
The input and output 8-bit gray images must have the same size. Algorithm description:
for(y = 0; y < height; ++y)
for(x = 0; x < width; ++x)
dst[x, y] = colors[src[x, y]];
- Note
- This function is a C++ wrapper for function SimdChangeColors.
- Parameters
-
[in] src - an input 8-bit gray image. [in] colors - a pointer to the color map (array of 256 unsigned 8-bit values). [out] dst - an output 8-bit gray image.
◆ NormalizeHistogram()
Normalizes histogram for 8-bit gray image.
The input and output 8-bit gray images must have the same size.
- Note
- This function is a C++ wrapper for function SimdNormalizeHistogram.
- Parameters
-
[in] src - an input 8-bit gray image. [out] dst - an output 8-bit image with normalized histogram.
◆ Mean()
| double Mean | ( | const uint32_t * | histogram | ) |
Calculates mean from image histogram.
- Parameters
-
[in] histogram - a pointer to image histogram (array of 256 unsigned 32-bit integer values).
- Returns
- value of mean for image with given histogram.
◆ OtsuThreshold()
| uint8_t OtsuThreshold | ( | const uint32_t * | histogram | ) |
Calculates Otsu threshold from image histogram.
- Parameters
-
[in] histogram - a pointer to image histogram (array of 256 unsigned 32-bit integer values).
- Returns
- value of Otsu threshold for image with given histogram.