Histogram

TD COMPs / TOPs / 2023 – Present

A Histogram represents the frequency distribution of pixel values in an image. By showing how often each intensity (or color channel value) occurs, histograms provide critical insights into contrast, brightness, and the tonal balance of an image. They form the foundation for many operations in computer vision and image processing, from thresholding and segmentation to equalization and enhancement.

A Cumulative Distribution Function (CDF) is the running sum of a histogram. Instead of showing how many pixels fall into a single bin, the CDF shows the cumulative proportion of pixels up to that bin. This makes CDFs especially important for operations like Histogram Equalization, where remapping pixel intensities to achieve a more uniform distribution improves image contrast and feature visibility.

This family of COMPs expands on the default Histogram COMP included in the TouchDesigner palette. Each operator processes and stores the given image’s statistical representations as a strip of 32‐bit float RGBA pixels appended to the bottom of said image, embedding the data directly into the TOP stream. This appended strip of pixels 2 high and 255 in width, encode both histogram and CDF information and serves as the foundation for all subsequent components in the Histogram family. It is crucial to include for proper use of these components.

Index:
Histogram, Histogram deCompiler, Histogram reCompiler, Histogram Conversion, Histogram Equalization, Histogram Similarity

Histogram

Statistical Representation of Images

This component calculates the statistical distribution of any given input image. Depending on the selected operating mode, this component can generate and display two different statistical representations:

  1. Histogram ( h ):

    Displays the frequency of pixel ( ι ) values across the image ( Ι ). This reveals how intensities are distributed, providing insight into contrast, brightness, and tonal balance.

    h i = ι Ι [ Ι (ι) = i ]


    Normalized:

    h i = 1 N ι Ι [ Ι (ι) = i ]


  2. Cumulative Distribution Function (CDF) ( H ):

    Shows the running sum of those frequencies, mapping the cumulative proportion of pixels ( ι ) up to each value. The CDF ( H ) is especially useful for tasks like histogram equalization, where pixel ( ι ) intensities are remapped to enhance contrast.

    H i = j = 0 i h j


    Normalized:

    H i = 1 N j = 0 i h j


Within this component family, the Histogram COMP serves as the entry point: it generates and encodes these statistical representations so they can be interpreted by other Histogram operators in the workflow. By coupling the original image with its histogram or CDF, this component provides a streamlined way to analyze and share image statistics across TouchDesigner TOP networks.

Resources:

Download the .tox files
Image Histogram on Wikipedia
CDF on Wikipedia

Parameters

Output:

Defines whether the component calculates a Histogram or a CDF of the input image.

Normalize:

Normalizes the statistical representations so that all values sum to 1.


Method:

Defines how the statistical representations is calculated:
Fast (GLSL calculation, GPU‐accelerated, efficient for real‐time workflows.) or
Accurate (Python calculation, CPU‐based, precise but slower.)

ReCalculate:

When using the Accurate method, this pulse forces a recalculation of the statistical representations in case any errors appear in the output.


Display:

Controls how the RGB channels of the statistical representations are visualized. Options include RGB Overlay (overlaying channels together) or RGB Parade (presenting channels sequentially).

Interpolate Values:

Toggles between a discrete bar‐graph style visualization or a smoother representation where values are interpolated between bins.

Square Values:

Applies a squaring function to the visualization, emphasizing smaller differences and improving readability of low‐frequency values.

In‐ / Outputs

Input 0TOP image to analyze.

Output 0TOP input image and it's statistical representations metadata.

Updated2/9/2025


Histogram Compilers

Metadata Extraction & Reconstruction

These two components manage the encoded metadata strip used by the Histogram component family. By design, the histogram or CDF data is appended to the bottom of the input image so it can travel through the TOP stream alongside the original texture. The deCompiler and reCompiler provide tools for explicitly separating or reconstructing this combined representation.

  • Histogram deCompiler:

    Accepts a TOP input that contains both the image and its statistical metadata strip. Outputs two TOPs: the original image with the strip removed, and the extracted metadata on its own.


  • Histogram reCompiler:

    Performs the reverse operation. Accepts two TOP inputs — an image and a histogram/CDF metadata strip — and appends them together into a single TOP. The result can then be read and used by other Histogram components.

Together, these operators make it possible to isolate, reuse, or restructure histogram metadata within a TouchDesigner workflow, providing flexibility for both analysis and creative manipulation.

Resources:

Download the .tox files
Image Histogram on Wikipedia
CDF on Wikipedia

Parameters

Input:

Specifies which type of metadata is being provided to the reCompiler Component (Histogram or CDF). Ensures the correct statistical representation is appended to the output.

Output:

Defines whether the component outputs a Histogram or a CDF along with the input image.

Normalize Output:

Normalizes the statistical representations so that all values sum to 1.


Display:

Controls how the RGB channels of the statistical representations are visualized. Options include RGB Overlay (overlaying channels together) or RGB Parade (presenting channels sequentially).

Interpolate Values:

Toggles between a discrete bar‐graph style visualization or a smoother representation where values are interpolated between bins.

Square Values:

Applies a squaring function to the visualization, emphasizing smaller differences and improving readability of low‐frequency values.

deCompiler In‐ / Outputs

Input 0TOP image with appended metadata.

Output 0TOP input only (metadata removed).
Output 1TOP metadata only (image removed)

reCompiler In‐ / Outputs

Input 0TOP image without metadata.
Input 1TOP metadata without image.

Output 0TOP image with appended metadata.

Updated2/9/2025


Histogram Conversion

Statistical Representation Converter

This component processes an image with appended statistical metadata and converts the embedded representation between the two available modes:

  1. Histogram ( h ):

    Displays the frequency of pixel ( ι ) values across the image ( Ι ). This reveals how intensities are distributed, providing insight into contrast, brightness, and tonal balance.

    h i = ι Ι [ Ι (ι) = i ]


  2. Cumulative Distribution Function (CDF) ( H ):

    Shows the running sum of those frequencies, mapping the cumulative proportion of pixels ( ι ) up to each value. The CDF ( H ) is especially useful for tasks like histogram equalization, where pixel ( ι ) intensities are remapped to enhance contrast.

    H i = j = 0 i h j


In addition to format conversion, this component also provides an option to normalize the metadata so that values sum to 1, ensuring consistency across different inputs and improving comparability between images.

By maintaining both the image and its updated statistical strip together, the Histogram Conversion component allows for seamless switching between representations while preserving compatibility with other operators in the Histogram component family.

Resources:

Download the .tox files
Image Histogram on Wikipedia
CDF on Wikipedia

Parameters

Method:

Defines the type of conversion applied to the metadata:
HistogramCDF or CDFHistogram.

Normalize:

Normalizes the statistical representations so that all values sum to 1.


Display:

Controls how the RGB channels of the statistical representations are visualized. Options include RGB Overlay (overlaying channels together) or RGB Parade (presenting channels sequentially).

Interpolate Values:

Toggles between a discrete bar‐graph style visualization or a smoother representation where values are interpolated between bins.

Square Values:

Applies a squaring function to the visualization, emphasizing smaller differences and improving readability of low‐frequency values.

In‐ / Outputs

Input 0TOP image with appended metadata.

Output 0TOP image with converted metadata appended.

Updated2/9/2025


Histogram Equalization

Intensity Remapping

This component redistributes the pixel ( ι ) intensities of an image ( Ι ) to achieve a more uniform distribution of values, thereby enhancing contrast and making features more visible. Histogram Equalization works by mapping the original pixel ( ι ) values to new values according to the normalized Cumulative Distribution Function ( H ).

Formally, the transformation function is defined as:

Ι ' (ι) = ( L1 ) · H (Ι (ι) )


This mapping ensures that the output image’s histogram spans the available intensity range more evenly, improving contrast in areas that were previously compressed.

In practice, Histogram Equalization is especially useful for:

  • Enhancing low‐contrast images (e.g., foggy or underexposed).

  • Highlighting features in medical, scientific, or technical imagery.

  • Preprocessing steps for segmentation or edge detection, where uniform contrast improves results.

Resources:

Download the .tox files
Histogram Equalization on Wikipedia
Histogram Equalization on Medium

Parameters

Output:

Defines whether the component calculates a Histogram or a CDF of the input image.

Normalize:

Normalizes the statistical representations so that all values sum to 1.


Method:

Defines how the statistical representations is calculated:
Fast (GLSL calculation, GPU‐accelerated, efficient for real‐time workflows) or
Accurate (Python calculation, CPU‐based, precise but slower).

ReCalculate:

When using the Accurate method, this pulse forces a recalculation of the statistical representations in case any errors appear in the output.


Display:

Controls how the RGB channels of the statistical representations are visualized. Options include RGB Overlay (overlaying channels together) or RGB Parade (presenting channels sequentially).

Interpolate Values:

Toggles between a discrete bar‐graph style visualization or a smoother representation where values are interpolated between bins.

Square Values:

Applies a squaring function to the visualization, emphasizing smaller differences and improving readability of low‐frequency values.

In‐ / Outputs

Input 0TOP image with appended metadata.

Output 0TOP image with equalized histogram applied.

Updated2/9/2025


Histogram Similarity

Statistical Difference Measurement

This component compares the statistical distributions of two images and calculates their difference as a single vector of distances, with one value for each channel (R, G, B, & A). Both inputs must contain appended statistical metadata; if the data is stored as CDFs, the component automatically converts them into Histograms before comparison.

The resulting distance vector quantifies how dissimilar the two distributions are, providing a detailed breakdown of per‐channel differences. A variety of comparison methods are provided, grouped into categories according to their mathematical basis:

  1. Distance:

    Manhattan ( L1 ):

    Ι (p, q) = i | p i q i |


    Euclidean ( L2 ):

    Ι (p, q) = i ( p i q i ) 2


    Chebyshev ( L ):

    Ι (p, q) = max ( | p i q i | )


    Fractional ( 0<r<1 ):

    Ι (p, q) = ( i | p i q i | r ) 1 r



  2. Correlation‐Based:

    Cosine Similarity:

    Ι (p, q) = 1 i p i q i i p i 2 i q i 2


    Pearson’s Correlation Coefficient:

    Ι (p, q) = 1 i ( p i p ¯ ) ( q i q ¯ ) i ( p i p ¯ ) 2 i ( q i q ¯ ) 2



  3. Probability & Divergence:

    Hellinger Distance:

    Ι (p, q) = 1 2 i ( p i q i ) 2


    Kolmogorov‐Smirnov Divergence:

    Ι (p, q) = max ( | P ( i ) Q ( i ) | )


    Cramér‐von Mises Criterion:

    Ι (p, q) = i ( P ( i ) Q ( i ) ) 2


    Bhattacharyya Distance:

    Ι (p, q) = ln ( i p i q i )


    Kullback‐Leibler Divergence (KL):

    Ι (p, q) = i p i ln ( p i q i )


    Jeffrey Divergence:

    Ι (p, q) = i ( p i q i ) ln ( p i q i )



  4. Intersection & Overlap:

    Histogram Intersection:

    Ι (p, q) = i min ( p i , q i )


    Jaccard Index:

    Ι (p, q) = 1 i min ( p i , q i ) i max ( p i , q i )



  5. Composite & Weighted:

    Canberra 1:

    Ι (p, q) = i | p i q i | min ( | p i | , | q i | )


    Canberra 2 (symmetric variant):

    Ι (p, q) = i | p i q i | | p i | + | q i |


    Chi‐Square (χ2 Statistic):

    Ι (p, q) = i ( p i q i ) 2 p i + q i


    Squared Chord:

    Ι (p, q) = i ( p i q i ) 2



  6. Other:

    Bray‐Curtis Dissimilarity, Sørensen‐Dice Coefficient:

    Ι (p, q) = i | p i q i | i ( p i + q i )


    Matching Distance:

    Ι (p, q) = i | p i q i |



Unlike other operators in this Histogram component family that output TOPs, this component outputs a CHOP, containing the per‐channel distance values. This makes it a powerful tool for image similarity measurement, pattern recognition, and statistical analysis.

Resources:

Download the .tox files
Histogram Similarity Assessment

Parameters

Method:

Selects the type of comparison to perform. Options are grouped by mathematical basis:
Distance, Correlation, Probability & Divergence, Intersection & Overlap, Composite & Weighted, and Other

Similarity Metric 1:

Specifies the exact metric used when the Method is set to Distance.
Options are:
Manhattan, Euclidean, Chebyshev, and Fractional

Similarity Metric 2:

Specifies the exact metric used when the Method is set to Correlation.
Options are:
Cosine Similarity or Pearson’s Correlation Coefficient

Similarity Metric 3:

Specifies the exact metric used when the Method is set to Probability & Divergence.
Options are:
Hellinger Distance, Kolmogorov‐Smirnov Divergence, Cramér‐von Mises Criterion, Bhattacharyya Distance, Kullback‐Leibler Divergence, and Jeffrey Divergence

Similarity Metric 4:

Specifies the exact metric used when the Method is set to Intersection & Overlap.
Options are:
Intersection or Jaccard Index

Similarity Metric 5:

Specifies the exact metric used when the Method is set to Weighted.
Options are:
Canberra 1, Canberra 2, Chi‐Square, and Squared Chord

Similarity Metric 6:

Specifies the exact metric used when the Method is set to Other.
Options are:
Bray‐Curtis Dissimilarity or Matching Distance

Fractional Power (p):

Specifies the exponent used in the Fractional ( Lp ) distance metric.
Lower values of ( p ) (between 0 and 1) emphasize small differences between histogram bins, while values closer to 1 behave more like the Manhattan distance.
This parameter is only active when the selected Similarity Metric is set to Fractional.


Display:

Controls how the RGB channels of the statistical representations are visualized. Options include RGB Overlay (overlaying channels together) or RGB Parade (presenting channels sequentially).

Interpolate Values:

Toggles between a discrete bar‐graph style visualization or a smoother representation where values are interpolated between bins.

Square Values:

Applies a squaring function to the visualization, emphasizing smaller differences and improving readability of low‐frequency values.

In‐ / Outputs

Input 0TOP image with appended metadata.

Input 1TOP image with appended metadata.

Output 0CHOP Calculated similarity of both inputs.

Updated2/9/2025