Calculates a histogram of image(s)
hist = calcHist(imgs, channels, mask, dims, bins_sizes, ranges)
Input images (a single image or a list of images of Mat type).
List of dims channels of the image used to compute the histogram (1 x dims double)
Optional mask, must be same size as the image or empty (Mat type).
Dimension of the output histogram (1 double).
Sizes of the bins in each dimension (1 x dims double).
Array of the dims arrays of the bin boundaries in each dimension (2 x dims double).
Output histogram (dims dimensions Mat).
calcHist
computes one histogram of one or several channels, on one or several images.
The output histogram is multi dimensional with dims dimensions, and contains the cross distribution of the channels channels.
To have separate histograms of each channel independently, calcHist
must be called several times, with the dims equal to 1 and the channels argument set to the corresponding channel.
scicv_Init(); img_gray = imread(getSampleImage("lena.jpg"), CV_LOAD_IMAGE_GRAYSCALE); // Histogram of the gray level hist = calcHist(img_gray, 0, [], 1, 32, [0 256]); bar(hist(:), 'black'); delete_Mat(img_gray); delete_Mat(hist); | ![]() | ![]() |
scicv_Init(); img = imread(getSampleImage("lena.jpg")); // Histogram of the three RBG channels taken separately // Note: OpenCV color channel order is reversed (BGR) histB = calcHist(img, 0, [], 1, 32, [0 256]); scf(); bar(histB(:), 'blue'); histG = calcHist(img, 1, [], 1, 32, [0 256]); scf(); bar(histG(:), 'green'); histR = calcHist(img, 2, [], 1, 32, [0 256]); scf(); bar(histR(:), 'red'); delete_Mat(img); delete_Mat(histB); delete_Mat(histG); delete_Mat(histR); | ![]() | ![]() |