# Histogram

In machine vision terminology, a histogram refers to an array of pixels — how many and their individual greyscale values — within a region of interest (ROI). The In-Sight Histogram tool's functions are used to count pixels for the purposes of statistical analysis and feature classification.

## What is a Histogram

The In-Sight Histogram tool performs histogram analysis by examining a ROI and classifying each individual pixel within it according to its greyscale value, and then placing them in a "bin" according to the pixel's greyscale value. In an 8-bit greyscale image, there are 256 bins, based on the number of possible greyscale values (0 to 255). Each bin contains a count of the number of pixels within it, with the bin being the index for the count. For example, if an image were to contain 46 pixels with a greyscale value of 33, the 33rd bin of the histogram for that region would contain the value 46. Additionally, the sum of the bins in the histogram array is always equal to the area of the region from which it was extracted.

The image below is a sample histogram chart from the ExtractHistogram function. The histogram chart displays the greyscale values of the pixels in a dockable window:

- The X-axis of the graph represents the total number of greyscale values (0 to 255).
- The Y-axis of the graph represents the number of pixels at a given greyscale value, and the scale is established by displaying the greyscale value with the greatest number of pixels.
- The green vertical line indicates the threshold.

Note: The histogram chart is a dockable window. For more information, see the Charts topic.

## When are Histogram Tools Used

Histograms are important because they are a compact representation of the pixel data contained in the image, stripped of all positional data, i.e. the functions only return information about the number of pixels in the ROI, and their individual greyscale (or color) values. This means that all of the position-independent greyscale image statistics can be computed directly from the histogram array.

The Histogram Tools are useful in examining images for issues such as detecting the presence/ absence of a feature, checking the illumination values or qualifying the uniformity of greyscale values to determine if there are any scratches, dust or debris.

## How to Use the Histogram Tools

The Histogram Tools are typically utilized in the following manner:

- Step 1 — The ExtractHistogram function is inserted into the spreadsheet and the parameters are configured to define the area of the image that will undergo histogram analysis.
- Step 2 — Next, the first and last non-zero bins are found, using the HistHead and HistTail functions, respectively. The output of the HistHead and HistTail functions will be used to set the range for the other Histogram functions to perform their analysis, removing bins that contain no pixels.
- Step 3 — Finally, the valley and peak between the first and last non-zero bins are determined using the HistMin and HistMax functions, respectively. Additional analysis may be performed, as well, using the other Histogram Tools (with the output of the HistHead and HistTail functions defining the range).

Note: If the HistMin function is given the default FirstBin parameter argument of 0, instead of the output of the HistHead function, HistMin will always return the first bin that contains 0 pixels, bin 0.