IPSDK 0.2
IPSDK : Image Processing Software Development Kit
Masked histogram measurement 2dSee full documentation
HistogramDatahistogramMaskMsr2d (inImg,inMaskImg)
HistogramDatahistogramMaskMsr2d (inImg,inMaskImg,histoPrms)

Detailed Description

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

This algorithm computes the histogram on a subset of pixels for each 2d plan of a given input image. The subsets of pixels to consider are defined by the set of pixels whose values is different from 0 in the associated mask image.

The mask image is binary, and must have the same sizes as the input image.

See also
Histogram measurement 2d for details about the definition of the histogram.
Note
Calling this algorithm with a mask image with all pixels set to 1 is equivalent to call histogramMsr2d algorithm.

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

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLGlobalMeasure as glbmsr

Code Example

# load input image from file
inImg = PyIPSDK.loadTiffImageFile(os.path.join(PyIPSDK.getIPSDKDirectory(PyIPSDK.eInternalDirectory.eID_Images), "Lena_510x509_UInt8.tif"))
# ------------------------------------------------------------------------
# build mask image; remember, we want a mask image with pixels of upper-left quarter
# set to 1, and all other pixels set to 0
maskImg = PyIPSDK.createImage(PyIPSDK.eImageBufferType.eIBT_Binary, inImg.getSizeX(), inImg.getSizeY())
# first, initialize all pixels values of pMaskImg to 0
util.eraseImg(maskImg, 0);
halfImSzX = int(inImg.getSizeX() / 2)
halfImSzY = int(inImg.getSizeY() / 2)
upperLeftQuarterMaskImg = PyIPSDK.createImage(PyIPSDK.eImageBufferType.eIBT_Binary, halfImSzX, halfImSzY)
util.eraseImg(upperLeftQuarterMaskImg, 1);
# copy upperLeftQuarterMaskImg (with all pixels set to 1) in the upper left quarter of
# maskImg (with all pixels initially set to 0)
# after this operation, our mask image is as expected
util.putROI2dImg(maskImg, upperLeftQuarterMaskImg, 0, 0);
# compute histogram on expected portion of input image (portion defined by set of voxels different from 0 in binary image pInMaskImg)
outHisto = glbmsr.histogramMaskMsr2d(inImg, maskImg)

Example of C++ code :

Example informations

Header file

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

Code Example

// in this example, we want to compute the histogram on the upper-left quarter
// of the Lena grey levels image only
// ------------------------------------------------------------------------
// load input image from image samples folder
ImagePtr pInImg = loadTiffImageFile(getIPSDKDirectory(eInternalDirectory::eID_Images) / "Lena_510x509_UInt8.tif");
// ------------------------------------------------------------------------
// build mask image; remember, we want a mask image with pixels of upper-left quarter
// set to 1, and all other pixels set to 0
boost::shared_ptr<MemoryImage> pMaskImg = boost::make_shared<MemoryImage>();
pMaskImg->init(*geometry2d(eImageBufferType::eIBT_Binary, pInImg->getSizeX(), pInImg->getSizeY()));
// first, initialize all pixels values of pMaskImg to 0
util::eraseImg(pMaskImg, 0);
boost::shared_ptr<MemoryImage> pUpperLeftQuarterMaskImg = boost::make_shared<MemoryImage>();
pUpperLeftQuarterMaskImg->init(*geometry2d(eImageBufferType::eIBT_Binary, pInImg->getSizeX() / 2, pInImg->getSizeY() / 2));
util::eraseImg(pUpperLeftQuarterMaskImg, 1);
// copy pUpperLeftQuarterMaskImg (with all pixels set to 1) in the upper left quarter of
// pMaskImg (with all pixels initially set to 0)
// after this operation, our mask image is as expected
util::putROI2dImg(pMaskImg, pUpperLeftQuarterMaskImg, 0, 0);
// ------------------------------------------------------------------------
// apply the histogram computation on the portion of the image that interests us
HistogramDataPtr pHistogram = glbmsr::histogramMaskMsr2d(pInImg, pMaskImg, createHistoMsrParamsWithBinWidth(0, 255, 1.0));