Products & Services Solutions Academia Support User Community Company

Learn more about Video and Image Processing Blockset   

Pixel Statistics

Blocks That Compute Pixel Statistics

The Video and Image Processing Blockset software together with the Signal Processing Blockset software contains blocks that can provide information about the data values that make up an image. Blocks from the Statistics library, such as the Maximum and 2-D Autocorrelation blocks, can help you determine this information.

Finding the Histogram of an Image

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:

  1. Create a new Simulink model, and add to it the blocks shown in the following table.

    Block

    Library

    Quantity

    Image From File

    Video and Image Processing Blockset > Sources

    1

    Video Viewer

    Video and Image Processing Blockset > Sinks

    1

    Matrix Concatenation

    Simulink > Math Operations

    1

    Vector Scope

    Signal Processing Blockset > Signal Processing Sinks

    1

    Histogram

    Signal Processing Blockset > Statistics

    3

  2. Place the blocks so that your model resembles the following figure.

  3. 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

    • Output data type: = double

  4. Use the Video Viewer block to automatically display the original image in the viewer window when you run the model. Set the Image signal parameter to Separate color signals.

  5. Use the Histogram block to calculate the histogram of the R, G, and B values in the image. Set the Main tab block parameters as follows:

    • Lower limit of histogram: 0

    • Upper limit of histogram: 1

    • Number of bins: = 256

    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.

  6. Use the Matrix Concatenation block to concatenate the R, G, and B column vectors into a single matrix so they can be displayed using the Vector Scope block. Set the Number of inputs parameter to 3.

  7. Use the Vector Scope block to display the histograms of the R, G, and B values of the input image. Set the block parameters as follows:

    • 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 title = Count

    • Line Properties pane, Line markers = .|s|d

    • Line Properties pane, Line colors = [1 0 0]|[0 1 0]|[0 0 1]

  8. Connect the blocks as shown in the following figure.

  9. Set the configuration parameters. Open the Configuration dialog box by selecting Configuration Parameters from the Simulation menu. Set the parameters as follows:

    • Solver pane, Stop time = 0

    • Solver pane, Type = Fixed-step

    • Solver pane, Solver = Discrete (no continuous states)

  10. Run the model.

    The original image appears in the Video Viewer window.

  11. Right-click in the Vector Scope window and select Autoscale.

    The scaled histogram of the image appears in the Vector Scope window.

You have now used the Histogram block to calculate the histogram of the R, G, and B values in an RGB image. For more information about this block, see the Histogram block reference page in the Video and Image Processing Blockset Reference. To open a demo 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.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS