The histogram of an image is usually depicted as a bar graph and conveys information about the distribution of the pixel intensities in a predefined number of bins (ranges of intensities), spanning from the minimum to the maximum intensity. The information depicted in a histogram can provide a rough idea about how bright, or dark an image is. It can also give a first estimation of the optimal threshold for segmenting the pixels of an image into two or more distinct classes based on their intensities.
To calculate the histogram of an image, we may use the inherent MATLAB function imhist
. This function outputs a one-dimensional matrix containing the distribution of the pixels in the input image in a set of bins (the default value for grayscale images is 256). The user can also give an extra input for different number of bins to be used. Let's see how this works for our previous example:
>> img = imread('my_image.bmp'); >> subplot...