The Histogram block computes the frequency distribution of the elements in each input image by sorting the elements into a specified number of discrete bins. You can use the Histogram block to calculate the histogram of the R, G, and/or B values in an image. This example shows you how to accomplish this task:
You can open the example model by typing
on the MATLAB® command line.
Image From File
Computer Vision System Toolbox™ > Sources
Computer Vision System Toolbox > Sinks
Simulink > Math Operations
DSP System Toolbox > Sinks
DSP System Toolbox > Statistics
Use the Image From File block to import an RGB image. Set the block parameters as follows:
Sample time = inf
Image signal = Separate color signals
Output port labels: = R|G|B
On the Data Types tab, Output data type: = double
Lower limit of histogram: 0
Upper limit of histogram: 1
Number of bins: = 256
Find the histogram over: = Entire Input
The R, G, and B input values to the Histogram block are double-precision floating point and range between 0 and 1. The block creates 256 bins between the maximum and minimum input values and counts the number of R, G, and B values in each bin.
Scope Properties pane, Input domain = User-defined
Display Properties pane, clear the Frame number check box
Display Properties pane, select the Channel legend check box
Display Properties pane, select the Compact display check box
Axis Properties pane, clear the Inherit sample increment from input check box.
Axis Properties pane, Minimum Y-limit = 0
Axis Properties pane, Maximum Y-limit = 1
Axis Properties pane, Y-axis label = Count
Line Properties pane, Line markers = .|s|d
Line Properties pane, Line colors = [1 0 0]|[0 1 0]|[0 0 1]
Solver pane, Stop time = 0
Solver pane, Type = Fixed-step
Solver pane, Solver = Discrete (no continuous states)
The original image appears in the Video Viewer window.
The scaled histogram of the image appears in the Vector Scope window.
You have now used the 2-D Histogram block to calculate the histogram of the R, G, and B values in an RGB image. To open a model that illustrates how to use this block to calculate the histogram of the R, G, and B values in an RGB video stream, type viphistogram at the MATLAB command prompt.