IPSDK 4.1.0.2
IPSDK : Image Processing Software Development Kit
Histogram measurement 2d
HistogramDatahistogramMsr2d (inImg)
HistogramDatahistogramMsr2d (inImg,histoPrms)

Detailed Description

calculates the histogram for each 2d plan of an input image

The histogram of an image is generally used as a tool to visualize the distribution of grey levels of the pixels of an image.

This algorithm computes the histogram for each 2d plan of the input image. In other words, the results will be computed :

Two wrappers can be called : the histogramMsr2d wrapper is only used to compute the histogram measurements on a grey level 2d image, whereas the multiSlice_histogramMsr2d wrapper must be used for more complex data (volume, sequence and/or color).

Consider:

Then, we can split the range $[min_{idt}; max_{idt}]$ in $nbClasses-1$ intervals $binIntvl_i = [min_{histo}+(i-1)*binWidth, min_{histo}+i*binWidth[ $ ( $i$ integer, $i \in {[1; nbClasses-1]}$) and one interval $binIntvl_{nbClasses} = [min_{histo}+(nbClasses-1)*binWidth; max_{histo}]$. These intervals are adjacent.

If images levels are encoded on floating values, then

\[ nbClasses = \dfrac {max_{idt}-min_{idt}} {binWidth} \]

Else,

\[ nbClasses = \begin{cases} \left\lfloor{\dfrac {max_{idt}-min_{idt}} {binWidth}} \right\rfloor & \text { if remainder of $\dfrac {max_{idt}-min_{idt}} {binWidth}$ equals to 0} \\ \left\lfloor{\dfrac {max_{idt}-min_{idt}} {binWidth}} \right\rfloor + 1 & \text { otherwise} \end{cases} \]

Then, the histogram of input parameters $min_{histo}$, $max_{histo}$ and $binWidth$ computed on $inImg$ is the collection $\left\{n_i\right\}$ ( $i$ integer, $i \in [1; nbClasses]$), with $n_i$ the number of pixels in $inImg$ whose levels belong to $binIntvl_i$.

There are different ways to compute the histogram of an input image:

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLGlobalMeasure as glbmsr

Code Example

# opening of input image
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# definition of histogram measure parameters (optional step)
histogramMsrParams = PyIPSDK.createHistoMsrParamsWithBinWidth(0, 255, 2)
# statistics measurement
histogramMsr2dResult = glbmsr.histogramMsr2d(inImg, histogramMsrParams)
# retrieve measurement results
frequencies = histogramMsr2dResult.frequencies
print("Population for bin [100, 101] is " + str(frequencies[50]))

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLGlobalMeasure/Processor/HistogramMsr2d/HistogramMsr2d.h>

Code Example

// ------------ Calculation on a mono-slice grey level image ------------ //
// Load the input image
ImagePtr pInImg = loadTiffImageFile(inImgPath);
// Compute statistics on input image
HistogramDataPtr pHistogram = histogramMsr2d(pInImg);
// ------------ Calculation on a mono-slice grey level image ------------ //
// Load the input image
ImagePtr pInImg_multiSlice = loadTiffImageFile(inImgPath_multiSlice);
// Compute statistics on input image
PlanIndexedHistogramDataPtr pHistogram_multiSlice = multiSlice_histogramMsr2d(pInImg_multiSlice);