SMIL  0.11.3-dev

Histogram evaluation and applications. More...

Detailed Description

Histogram evaluation and applications.

This module contains functions to evaluate image histograms and some applications such as contrast enhancement, histogram manipulation and thresholding

+ Collaboration diagram for Histogram:

Classes

struct  threshLine< T, T_out >
 

Functions

template<class T >
 histogram (const Image< T > &imIn, size_t *h)
 Image histogram. More...
 
template<class T >
RES_T histogram (const Image< T > &imIn, const Image< T > &imMask, size_t *h)
 Image histogram. More...
 
template<class T >
std::map< T, UINT > histogram (const Image< T > &imIn, bool fullRange=false)
 histogram() - Image histogram More...
 
template<class T >
std::map< T, UINT > histogram (const Image< T > &imIn, const Image< T > &imMask, bool fullRange=false)
 histogram() - Image histogram with a mask image. More...
 
template<typename T >
std::map< T, UINT > histogramMap (const Image< T > &imIn, T binSize=1)
 histogramMap() - More...
 
template<typename T >
std::map< T, UINT > histogramMap (const Image< T > &imIn, const Image< T > imMask, T binSize=1)
 histogramMap() - More...
 
template<class T , class T_out >
RES_T threshold (const Image< T > &imIn, T minVal, T maxVal, T_out trueVal, T_out falseVal, Image< T_out > &imOut)
 threshold() - Image threshold More...
 
template<class T , class T_out >
RES_T threshold (const Image< T > &imIn, T minVal, T maxVal, Image< T_out > &imOut)
 threshold() - Image threshold More...
 
template<class T , class T_out >
RES_T threshold (const Image< T > &imIn, T minVal, Image< T_out > &imOut)
 threshold() - Image threshold More...
 
template<class T , class T_out >
RES_T threshold (const Image< T > &imIn, Image< T_out > &imOut)
 threshold() - Otsu Image threshold More...
 
template<class T1 , class T2 >
RES_T stretchHist (const Image< T1 > &imIn, T1 inMinVal, T1 inMaxVal, Image< T2 > &imOut, T2 outMinVal=numeric_limits< T2 >::min(), T2 outMaxVal=numeric_limits< T2 >::max())
 stretchHist() - Stretch histogram More...
 
template<class T1 , class T2 >
RES_T stretchHist (const Image< T1 > &imIn, Image< T2 > &imOut, T2 outMinVal, T2 outMaxVal)
 stretchHist() - Stretch histogram More...
 
template<class T1 , class T2 >
RES_T stretchHist (const Image< T1 > &imIn, Image< T2 > &imOut)
 stretchHist() - Stretch histogram More...
 
template<class T >
vector< T > histogramRange (const Image< T > &imIn, double ignorePercent, bool cumulative=true)
 histogramRange() - Min and Max values of an histogram ignoring left/right low values (lower than a given height/cumulative height). More...
 
template<class T >
RES_T enhanceContrast (const Image< T > &imIn, Image< T > &imOut, double saturation=0.25)
 enhanceContrast() - Enhance contrast More...
 
template<class T >
vector< T > otsuThresholdValues (map< T, UINT > &hist, UINT threshLevels=1)
 otsuThresholdValues() - Return threshold values and the value of the resulting variance between classes More...
 
template<class T >
vector< T > otsuThresholdValues (const Image< T > &im, UINT threshLevels=1)
 otsuThresholdValues() - Return threshold values and the value of the resulting variance between classes More...
 
template<class T >
vector< T > otsuThresholdValues (const Image< T > &im, const Image< T > &imMask, UINT threshLevels=1)
 otsuThresholdValues() - Return threshold values and the value of the resulting variance between classes More...
 
template<class T , class T_out >
vector< T > otsuThreshold (const Image< T > &imIn, Image< T_out > &imOut, UINT nbrThresholds)
 otsuThreshold() - Otsu Threshold More...
 
template<class T , class T_out >
otsuThreshold (const Image< T > &imIn, Image< T_out > &imOut)
 otsuThreshold() - Otsu Threshold More...
 
template<class T , class T_out >
vector< T > otsuThreshold (const Image< T > &imIn, const Image< T > &imMask, Image< T_out > &imOut, UINT nbrThresholds=1)
 otsuThreshold() - Otsu Threshold More...
 

Function Documentation

◆ histogram() [1/4]

histogram ( const Image< T > &  imIn,
size_t *  h 
)

Image histogram.

Calculate the histogram of the image

Parameters
[in]imIn: input image
[out]h: vector with histogram
Note
Available only in C++

◆ histogram() [2/4]

RES_T smil::histogram ( const Image< T > &  imIn,
const Image< T > &  imMask,
size_t *  h 
)

Image histogram.

Returns the histogram of the image in the region defined by the image mask.

Parameters
[in]imIn: input image
[in]imMask: image mask
[out]h: vector with histogram
Note
Available only in C++

◆ histogram() [3/4]

std::map<T, UINT> smil::histogram ( const Image< T > &  imIn,
bool  fullRange = false 
)

histogram() - Image histogram

Parameters
[in]imIn: input image
[in]fullRange: result contains all possible values in the image type range
Returns
the histogram as a map with the pairs <value, count>.

◆ histogram() [4/4]

std::map<T, UINT> smil::histogram ( const Image< T > &  imIn,
const Image< T > &  imMask,
bool  fullRange = false 
)

histogram() - Image histogram with a mask image.

Returns the histogram of the image in the region defined by the image mask.

Parameters
[in]imIn: input image
[in]imMask: image mask
[in]fullRange: result contains all possible values in the image type range
Returns
the histogram as a map with the pairs <value, count>.

◆ histogramMap() [1/2]

std::map<T, UINT> smil::histogramMap ( const Image< T > &  imIn,
binSize = 1 
)

histogramMap() -

Parameters
[in]imIn: input image
[in]binSize: size of bin
Returns
the histogram as a map.

◆ histogramMap() [2/2]

std::map<T, UINT> smil::histogramMap ( const Image< T > &  imIn,
const Image< T >  imMask,
binSize = 1 
)

histogramMap() -

Parameters
[in]imIn: input image
[in]imMask: image mask
[in]binSize: size of bin
Returns
the histogram as a map.

◆ threshold() [1/4]

RES_T smil::threshold ( const Image< T > &  imIn,
minVal,
maxVal,
T_out  trueVal,
T_out  falseVal,
Image< T_out > &  imOut 
)

threshold() - Image threshold

Image threshold based on a range of values defined by [minVal, maxVal].

The result is a image where :

  • imOut(x) = (imIn(x) >= minVal && imIn(x) < maxVal ? trueVal : falseVal)
Parameters
[in]imIn: input image
[in]minVal,maxVal: interest range of pixel values
[in]trueVal: value to assign to pixels in the interest range
[in]falseVal: value to assign to pixels outside the interest range
[out]imOut: output image

◆ threshold() [2/4]

RES_T smil::threshold ( const Image< T > &  imIn,
minVal,
maxVal,
Image< T_out > &  imOut 
)

threshold() - Image threshold

Image threshold based on a range of values defined by [minVal, maxVal].

The result is a image where :

  • imOut(x) = (imIn(x) >= minVal && imIn(x) < maxVal ? max(T) : min(T))
Parameters
[in]imIn: input image
[in]minVal,maxVal: interest range of pixel values
[out]imOut: output image

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ threshold() [3/4]

RES_T smil::threshold ( const Image< T > &  imIn,
minVal,
Image< T_out > &  imOut 
)

threshold() - Image threshold

Image threshold based on some threshold.

The result is a image where :

  • imOut(x) = (imIn(x) >= minVal ? max(T) : men(T))
Parameters
[in]imIn: input image
[in]minVal: threshold
[out]imOut: output image

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ threshold() [4/4]

RES_T smil::threshold ( const Image< T > &  imIn,
Image< T_out > &  imOut 
)

threshold() - Otsu Image threshold

Parameters
[in]imIn: input image
[out]imOut: output image
See also

◆ stretchHist() [1/3]

RES_T smil::stretchHist ( const Image< T1 > &  imIn,
T1  inMinVal,
T1  inMaxVal,
Image< T2 > &  imOut,
T2  outMinVal = numeric_limits<T2>::min(),
T2  outMaxVal = numeric_limits<T2>::max() 
)

stretchHist() - Stretch histogram

Create a new image based on a linear transformation of the histogram of the input image.

The output image is created by the following rules :

  • coef = (outMaxVal - outMinVal) / (inMaxVal - inMinVal)
  • imOut(x) = coeff * (imIn(x) - inMinVal) + outMinVal
  • output values are upper and lower bounded by the valid range [min(T2), max(T2)]
Parameters
[in]imIn: input image
[in]inMinVal,inMaxVal: input range coefficient
[out]imOut: output image
[out]outMinVal,outMaxVal: output range

◆ stretchHist() [2/3]

RES_T smil::stretchHist ( const Image< T1 > &  imIn,
Image< T2 > &  imOut,
T2  outMinVal,
T2  outMaxVal 
)

stretchHist() - Stretch histogram

Create a new image based on a linear transformation of the histogram of the input image.

As before but the range values in the input image are taken from the range of its histogram.

The output image is created by the following rules :

  • (inMinVal, inMaxVal) = range(imIn). See rangeVal()
  • coef = (outMaxVal - outMinVal) / (inMaxVal - inMinVal)
  • imOut(x) = coeff * (imIn(x) - inMinVal) + outMinVal
  • output values are upper and lower bounded by the valid range [min(T2), max(T2)]
Parameters
[in]imIn: input image
[out]imOut: output image
[out]outMinVal,outMaxVal: output range

◆ stretchHist() [3/3]

RES_T smil::stretchHist ( const Image< T1 > &  imIn,
Image< T2 > &  imOut 
)

stretchHist() - Stretch histogram

Create a new image based on a linear transformation of the histogram of the input image.

As before but the range values in the input image are taken from the range of its histogram and the range values in the output image are the range defined by the data type.

The output image is created by the following rules :

  • (inMinVal, inMaxVal) = range(imIn). See rangeVal()
  • coef = (max(T2) - min(T2)) / (inMaxVal - inMinVal)
  • imOut(x) = coeff * (imIn(x) - inMinVal) + min(T2)
Parameters
[in]imIn: input image
[out]imOut: output image

◆ histogramRange()

vector<T> smil::histogramRange ( const Image< T > &  imIn,
double  ignorePercent,
bool  cumulative = true 
)

histogramRange() - Min and Max values of an histogram ignoring left/right low values (lower than a given height/cumulative height).

If cumulative is true, it stops when the integral of the histogram values reaches ignorePercent * NbrPixels. Otherwise, it stops at the first value of the histogram higher than ignorePercent * max(histogram)

Parameters
[in]imIn: input image
[in]ignorePercent: explained above
[in]cumulative: explained above
Returns
a vector with the pair of extrema values of the histogram.

◆ enhanceContrast()

RES_T smil::enhanceContrast ( const Image< T > &  imIn,
Image< T > &  imOut,
double  saturation = 0.25 
)

enhanceContrast() - Enhance contrast

Parameters
[in]imIn: input image
[out]imOut: output image
[in]saturation:

◆ otsuThresholdValues() [1/3]

vector<T> smil::otsuThresholdValues ( map< T, UINT > &  hist,
UINT  threshLevels = 1 
)

otsuThresholdValues() - Return threshold values and the value of the resulting variance between classes

Parameters
[in]hist: image histogram
[in]threshLevels: number of threshold levels (default : 1)
Returns
vector with the threshold levels

◆ otsuThresholdValues() [2/3]

vector<T> smil::otsuThresholdValues ( const Image< T > &  im,
UINT  threshLevels = 1 
)

otsuThresholdValues() - Return threshold values and the value of the resulting variance between classes

Parameters
[in]im: image
[in]threshLevels: number of threshold levels (default : 1)
Returns
vector with the threshold levels

◆ otsuThresholdValues() [3/3]

vector<T> smil::otsuThresholdValues ( const Image< T > &  im,
const Image< T > &  imMask,
UINT  threshLevels = 1 
)

otsuThresholdValues() - Return threshold values and the value of the resulting variance between classes

Parameters
[in]im: image
[in]imMask: image mask
[in]threshLevels: number of threshold levels (default : 1)
Returns
vector with the threshold levels

◆ otsuThreshold() [1/3]

vector<T> smil::otsuThreshold ( const Image< T > &  imIn,
Image< T_out > &  imOut,
UINT  nbrThresholds 
)

otsuThreshold() - Otsu Threshold

Image threshold based on the Otsu algorithm.

See also
Parameters
[in]imIn: input image
[out]imOut: output image
[in]nbrThresholds: number of thresholds. The output image will have nbrThresholds + 1 classes.

Example

from smilPython import *
# Load an image
im1 = Image("https://smil.cmm.minesparis.psl.eu/images/lena.png")
im1.show()
# Manual threshold (between 100 and 255)
im2 = Image(im1)
threshold(im1, 100, 255, im2)
im2.show()
# Otsu automatic threshold
im3 = Image(im1)
# Generate two threshold values (i.e. 3 classes)
otsuThreshold(im1, im3, 2)
# Display the resulting image with three labels values corresponding to the three classes
im3.showLabel()

◆ otsuThreshold() [2/3]

T smil::otsuThreshold ( const Image< T > &  imIn,
Image< T_out > &  imOut 
)

otsuThreshold() - Otsu Threshold

Image threshold based on the Otsu algorithm.

Output image will have only two classes.

See also
Parameters
[in]imIn: input image
[out]imOut: output image

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ otsuThreshold() [3/3]

vector<T> smil::otsuThreshold ( const Image< T > &  imIn,
const Image< T > &  imMask,
Image< T_out > &  imOut,
UINT  nbrThresholds = 1 
)

otsuThreshold() - Otsu Threshold

Image threshold based on the Otsu algorithm (a mask will be applied before threshold).

See also
Parameters
[in]imIn: input image
[in]imMask: mask image
[out]imOut: output image
[in]nbrThresholds: number of thresholds. The output image will have nbrThresholds + 1 classes.

Example

from smilPython import *
# Load an image
im1 = Image("https://smil.cmm.minesparis.psl.eu/images/lena.png")
im1.show()
# Manual threshold (between 100 and 255)
im2 = Image(im1)
threshold(im1, 100, 255, im2)
im2.show()
# Otsu automatic threshold
im3 = Image(im1)
# Generate two threshold values (i.e. 3 classes)
otsuThreshold(im1, im3, 2)
# Display the resulting image with three labels values corresponding to the three classes
im3.showLabel()
smil::otsuThreshold
vector< T > otsuThreshold(const Image< T > &imIn, Image< T_out > &imOut, UINT nbrThresholds)
otsuThreshold() - Otsu Threshold
Definition: DImageHistogram.hpp:785
smil::threshold
RES_T threshold(const Image< T > &imIn, T minVal, T maxVal, T_out trueVal, T_out falseVal, Image< T_out > &imOut)
threshold() - Image threshold
Definition: DImageHistogram.hpp:269