Histogram

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (tweak opening bullet list and Levels section)
m (one more touch-up)
Line 1: Line 1:
{{Template:FuncDef|Histogram(clip ''clip'' [, string ''mode''] [, float ''factor''])}}
+
{{FuncDef
 +
|Histogram(clip ''clip'' [, string ''mode''] [, float ''factor''])
 +
}}
  
 
A multipurpose audio/video analysis tool, which supports the following '''''modes''''':
 
A multipurpose audio/video analysis tool, which supports the following '''''modes''''':
Line 13: Line 15:
 
----
 
----
 
=== Classic mode ===
 
=== Classic mode ===
 +
<div style="max-width:62em" >
  
 
[[Image:histogram_classic.jpg]]
 
[[Image:histogram_classic.jpg]]
  
This will add a per-line luminance graph (which is usually called a [http://en.wikipedia.org/wiki/Waveform_monitor Waveform Monitor]) on the right side of the video.  
+
This will add a per-line luminance graph (which is usually called a [[wikipedia:Waveform_monitor|Waveform Monitor]]) on the right side of the video.  
  
 
The left side of the graph represents luma=0 and the right side represents luma=255. The non-valid CCIR-601 ranges are shown in a brown/yellowish color, and a greenish line represents Y=128.
 
The left side of the graph represents luma=0 and the right side represents luma=255. The non-valid CCIR-601 ranges are shown in a brown/yellowish color, and a greenish line represents Y=128.
  
Available in YUV mode.
+
Available in [[YUV]] mode.
 +
</div>
  
  
 
----
 
----
 
=== Levels mode ===
 
=== Levels mode ===
 +
<div style="max-width:62em" >
  
 
[[File:Histogram-vortex-levels.jpg]]
 
[[File:Histogram-vortex-levels.jpg]]
Line 32: Line 37:
 
The top graph displays the ''Y'' (luma) distribution of the frame, where the left side represents Y=0 and the right side represents Y=255. The valid CCIR601 range has been indicated by a slightly different color and Y=128 has been marked with a dotted line. The vertical axis shows the number of pixels for a given luma (Y) value. The middle graph displays the ''U'' component, and the bottom graph displays the ''V'' component.
 
The top graph displays the ''Y'' (luma) distribution of the frame, where the left side represents Y=0 and the right side represents Y=255. The valid CCIR601 range has been indicated by a slightly different color and Y=128 has been marked with a dotted line. The vertical axis shows the number of pixels for a given luma (Y) value. The middle graph displays the ''U'' component, and the bottom graph displays the ''V'' component.
  
The ''factor'' option (100.0 by default) specifies the way how the graphs are displayed. It is specified as percentage of the total population (that is number of luma or chroma pixels in a frame). For example, Histogram("Levels", 1.5625) will achieve a 1/64th cap.
+
The {{FuncArg|factor}} option (100.0 by default) specifies how the graphs are displayed. It is specified as percentage of the total population (that is number of luma or chroma pixels in a frame). For example, Histogram("Levels", 1.5625) will achieve a 1/64th cap.
  
'''NOTE''', "factor" is an ''unnamed ''optional argument; <br style="line-height:60%" />
+
'''NOTE''', {{FuncArg|factor}} is an ''unnamed ''optional argument; <br style="line-height:60%" />
 
<code>Histogram(mode="levels", '''factor='''2.5)</code> will not work, but <code>Histogram("levels", 2.5)</code> works fine.
 
<code>Histogram(mode="levels", '''factor='''2.5)</code> will not work, but <code>Histogram("levels", 2.5)</code> works fine.
  
 
Available in all planar modes, except [[Y8]].
 
Available in all planar modes, except [[Y8]].
 +
</div>
  
  
 
----
 
----
 
=== Color mode ===
 
=== Color mode ===
 +
<div style="max-width:62em" >
  
 
[[File:Histogram-vortex-color.jpg]]
 
[[File:Histogram-vortex-color.jpg]]
Line 47: Line 54:
 
This mode will display the chroma values (U/V color placement) in a two dimensional graph (which is called a vectorscope) on the right side of the video frame. It can be used to read of the hue and saturation of a clip. At the same time it is a histogram. The whiter a pixel in the vectorscope, the more pixels of the input clip correspond to that pixel (that is the more pixels have this chroma value).
 
This mode will display the chroma values (U/V color placement) in a two dimensional graph (which is called a vectorscope) on the right side of the video frame. It can be used to read of the hue and saturation of a clip. At the same time it is a histogram. The whiter a pixel in the vectorscope, the more pixels of the input clip correspond to that pixel (that is the more pixels have this chroma value).
  
 +
Available in all planar modes except Y8.
 
<div>
 
<div>
 
{| border="0"  
 
{| border="0"  
Line 56: Line 64:
 
The position of a white pixel in the graph corresponds to the chroma value of a pixel of the input clip. So the graph can be used to read of the hue (color flavor) and the saturation (the dominance of the hue in the color). As the hue of a color changes, it moves around the square. At the center of the square, the saturation is zero, which means that the corresponding pixel has no color. If you increase the amount of a specific color, while leaving the other colors unchanged, the saturation increases, and you move towards the edge of the square.
 
The position of a white pixel in the graph corresponds to the chroma value of a pixel of the input clip. So the graph can be used to read of the hue (color flavor) and the saturation (the dominance of the hue in the color). As the hue of a color changes, it moves around the square. At the center of the square, the saturation is zero, which means that the corresponding pixel has no color. If you increase the amount of a specific color, while leaving the other colors unchanged, the saturation increases, and you move towards the edge of the square.
 
|}</div>
 
|}</div>
 
+
</div>
Available in all planar modes except Y8.
+
  
  
 
----
 
----
 
=== Color2 mode ===
 
=== Color2 mode ===
 +
<div style="max-width:62em" >
  
 
[[File:Histogram-vortex-color2.jpg]]
 
[[File:Histogram-vortex-color2.jpg]]
Line 71: Line 79:
 
The position of a pixel in the graph corresponds to the chroma value of a pixel of the input clip. So the graph can be used to read of the hue (color flavor) and the saturation (the dominance of the hue in the color). As the hue of a color changes, it moves around the circle. At the center of the circle, the saturation is zero, which means that the corresponding pixel has no color. If you increase the amount of a specific color, while leaving the other colors unchanged, the saturation increases, and you move towards the edge of the circle. A color wheel is plotted and divided into six hues (red, yellow, green, cyan, blue and magenta) to help you reading of the hue values. Also every 15 degrees a white dot is plotted.
 
The position of a pixel in the graph corresponds to the chroma value of a pixel of the input clip. So the graph can be used to read of the hue (color flavor) and the saturation (the dominance of the hue in the color). As the hue of a color changes, it moves around the circle. At the center of the circle, the saturation is zero, which means that the corresponding pixel has no color. If you increase the amount of a specific color, while leaving the other colors unchanged, the saturation increases, and you move towards the edge of the circle. A color wheel is plotted and divided into six hues (red, yellow, green, cyan, blue and magenta) to help you reading of the hue values. Also every 15 degrees a white dot is plotted.
  
At U=255, V=128 the hue is zero (which corresponds to blue) and the saturation is maximal, that is, <code>sqrt( (U-128)^2 + (V-128)^2 ) = 127</code>. When turning clock-wise, say 90 degrees, the chroma is given by U=128, V=255 (which corresponds to red). Keeping the hue constant and decreasing the saturation, means that we move from the circle to the center of the vectorscope. Thus the color flavor remains the same (namely red), only it changes slowly to [[GreyScale|greyscale]].  Etc ...
+
At U=255, V=128 the hue is zero (which corresponds to blue) and the saturation is maximal, that is, <br>
 +
 
 +
::sqrt((U-128)<sup>2</sup> + (V-128)<sup>2</sup>) = 127 <br>
 +
 
 +
When turning clock-wise, say 90 degrees, the chroma is given by U=128, V=255 (which corresponds to red). Keeping the hue constant and decreasing the saturation, means that we move from the circle to the center of the vectorscope. Thus the color flavor remains the same (namely red), only it changes slowly to [[GreyScale|greyscale]].  Etc ...
  
 
Available in all planar modes except Y8.  
 
Available in all planar modes except Y8.  
 +
</div>
  
  
 
----
 
----
 
=== Luma mode ===
 
=== Luma mode ===
 +
<div style="max-width:62em" >
  
 
[[Image:histogram_modeluma.jpg]]
 
[[Image:histogram_modeluma.jpg]]
Line 84: Line 98:
  
 
Available in planar and YUY2 modes.
 
Available in planar and YUY2 modes.
 +
</div>
  
  
 
----
 
----
 
=== Audiolevels mode ===
 
=== Audiolevels mode ===
 +
<div style="max-width:62em" >
  
 
[[Image:histogram_audiolevels.jpg]]
 
[[Image:histogram_audiolevels.jpg]]
Line 93: Line 109:
 
Shows the audio levels in [[wikipedia:Decibel|decibels]] for each channel present. For example, if the source has six channels of audio, six vertical bars will be shown.  
 
Shows the audio levels in [[wikipedia:Decibel|decibels]] for each channel present. For example, if the source has six channels of audio, six vertical bars will be shown.  
  
* The green bars show the {{Serif|''RMS''}} ([http://en.wikipedia.org/wiki/Root_mean_square Root Mean Square]) level of the audio in each video frame (let's say {{Serif|''n''}} samples) using the following formula:
+
* The green bars show the {{Serif|''RMS''}} ([wikipedia:Root_mean_square|Root Mean Square]]) level of the audio in each video frame (let's say {{Serif|''n''}} samples) using the following formula:
  
 
::[[File:Histogram-eq-1.png|x46px|<math> RMS = 20 \cdot log_{10}( 1/32768 \cdot \sqrt{ 1/n \cdot \sum_{j=1}^{n} sample(j)^{2}} ) </math>]]
 
::[[File:Histogram-eq-1.png|x46px|<math> RMS = 20 \cdot log_{10}( 1/32768 \cdot \sqrt{ 1/n \cdot \sum_{j=1}^{n} sample(j)^{2}} ) </math>]]
Line 103: Line 119:
 
[[Planar]] video is required. Audio is converted to 16 bit.  
 
[[Planar]] video is required. Audio is converted to 16 bit.  
  
The maximum possible level without [http://en.wikipedia.org/wiki/Clipping_%28audio%29 clipping] is 0 dB by definition. The minimum level for 16 bit audio is therefore
+
The maximum possible level without [[wikipedia:Clipping_%28audio%29|clipping]] is 0 dB by definition. The minimum level for 16 bit audio is therefore
  
::[[File:Histogram-eq-4.png|x16px|<math> 20 \cdot log_{10}(1/32768) = - 90.31 \ dB </math>]] &nbsp;&nbsp;&nbsp;(since 2^16 / 2 = 32768)
+
::[[File:Histogram-eq-4.png|x16px|<math> 20 \cdot log_{10}(1/32768) = - 90.31 \ dB </math>]] &nbsp;&nbsp;&nbsp;(since 2<sup>16</sup> / 2 = 32768)
 +
</div>
  
  
 
----
 
----
 
 
=== Stereo, StereoY8 and StereoOverlay mode ===
 
=== Stereo, StereoY8 and StereoOverlay mode ===
 +
<div style="max-width:62em" >
  
 
[[Image:histogram_modestereo.gif|256px|]]
 
[[Image:histogram_modestereo.gif|256px|]]
 
   
 
   
These modes show a classic stereo graph (or [http://en.wikipedia.org/wiki/Lissajous_curve Lissajous] pattern) from the clip audio, often seen in recording studios. They are used to view the left-right phase distribution of the input signal. In-phase stereo appears predominantly vertical (as shown), but incorrectly phased stereo appears predominantly horizontal. Two-channel Mono appears as a vertical line.  
+
These modes show a classic stereo graph (or [[wikipedia:Lissajous_curve|Lissajous]] pattern) from the clip audio, often seen in recording studios. They are used to view the left-right phase distribution of the input signal. In-phase stereo appears predominantly vertical (as shown), but incorrectly phased stereo appears predominantly horizontal. Two-channel Mono appears as a vertical line.  
  
'''StereoOverlay''' will overlay the graph on top of the original. Each frame will contain only information from the current frame to the beginning of the next frame. The signal is linearly upsampled 8x, to provide clearer visuals. '''Stereo''' and '''StereoY8''' won't overlay the graph on the video, but will just return the graph alone as a 512 x  512 video clip (in [[YV12]] or [[Y8]] format respectively).
+
'''StereoOverlay''' will overlay the graph on top of the original. Each frame will contain only information from the current frame to the beginning of the next frame. The signal is linearly upsampled 8x, to provide clearer visuals. '''Stereo''' and '''StereoY8''' won't overlay the graph on the video, but will just return the graph alone as a 512×512 video clip (in [[YV12]] or [[Y8]] format respectively).
  
 
These modes require a source clip with stereo audio; '''StereoOverlay''' also requires a source clip with a [[Planar|planar]] color format.
 
These modes require a source clip with stereo audio; '''StereoOverlay''' also requires a source clip with a [[Planar|planar]] color format.
 +
</div>
  
  
Line 124: Line 142:
  
 
=== Changes ===
 
=== Changes ===
 
+
<div style="max-width:62em" >
 
{| border="1"
 
{| border="1"
 
|-
 
|-
Line 142: Line 160:
 
| Added different modes.
 
| Added different modes.
 
|}
 
|}
 +
</div>
  
  

Revision as of 04:34, 28 February 2016

Histogram(clip clip [, string mode] [, float factor])

A multipurpose audio/video analysis tool, which supports the following modes:



Classic mode

Histogram classic.jpg

This will add a per-line luminance graph (which is usually called a Waveform Monitor) on the right side of the video.

The left side of the graph represents luma=0 and the right side represents luma=255. The non-valid CCIR-601 ranges are shown in a brown/yellowish color, and a greenish line represents Y=128.

Available in YUV mode.



Levels mode

Histogram-vortex-levels.jpg

This mode will display three histograms on the right side of the video frame. This will show the distribution of the Y, U and V components in the current frame.

The top graph displays the Y (luma) distribution of the frame, where the left side represents Y=0 and the right side represents Y=255. The valid CCIR601 range has been indicated by a slightly different color and Y=128 has been marked with a dotted line. The vertical axis shows the number of pixels for a given luma (Y) value. The middle graph displays the U component, and the bottom graph displays the V component.

The factor option (100.0 by default) specifies how the graphs are displayed. It is specified as percentage of the total population (that is number of luma or chroma pixels in a frame). For example, Histogram("Levels", 1.5625) will achieve a 1/64th cap.

NOTE, factor is an unnamed optional argument;
Histogram(mode="levels", factor=2.5) will not work, but Histogram("levels", 2.5) works fine.

Available in all planar modes, except Y8.



Color mode

Histogram-vortex-color.jpg

This mode will display the chroma values (U/V color placement) in a two dimensional graph (which is called a vectorscope) on the right side of the video frame. It can be used to read of the hue and saturation of a clip. At the same time it is a histogram. The whiter a pixel in the vectorscope, the more pixels of the input clip correspond to that pixel (that is the more pixels have this chroma value).

Available in all planar modes except Y8.

Histogram(mode="color") output with added labels

The U component is displayed on the horizontal (X) axis, with the leftmost side being U=0 and the rightmost side being U=255. The V component is displayed on the vertical (Y) axis, with the top representing V=0 and the bottom representing V=255.

The position of a white pixel in the graph corresponds to the chroma value of a pixel of the input clip. So the graph can be used to read of the hue (color flavor) and the saturation (the dominance of the hue in the color). As the hue of a color changes, it moves around the square. At the center of the square, the saturation is zero, which means that the corresponding pixel has no color. If you increase the amount of a specific color, while leaving the other colors unchanged, the saturation increases, and you move towards the edge of the square.



Color2 mode

Histogram-vortex-color2.jpg

This mode will display the pixels in a two dimensional graph (called a vectorscope) on the right side of the video frame. It can be used to read of the hue and saturation of a clip.

The U component is displayed on the horizontal (X) axis, with the leftmost side being U=0 and the rightmost side being U=255. The V component is displayed on the vertical (Y) axis, with the top representing V=0 and the bottom representing V=255. The grey square denotes the valid CCIR-601 range.

The position of a pixel in the graph corresponds to the chroma value of a pixel of the input clip. So the graph can be used to read of the hue (color flavor) and the saturation (the dominance of the hue in the color). As the hue of a color changes, it moves around the circle. At the center of the circle, the saturation is zero, which means that the corresponding pixel has no color. If you increase the amount of a specific color, while leaving the other colors unchanged, the saturation increases, and you move towards the edge of the circle. A color wheel is plotted and divided into six hues (red, yellow, green, cyan, blue and magenta) to help you reading of the hue values. Also every 15 degrees a white dot is plotted.

At U=255, V=128 the hue is zero (which corresponds to blue) and the saturation is maximal, that is,

sqrt((U-128)2 + (V-128)2) = 127

When turning clock-wise, say 90 degrees, the chroma is given by U=128, V=255 (which corresponds to red). Keeping the hue constant and decreasing the saturation, means that we move from the circle to the center of the vectorscope. Thus the color flavor remains the same (namely red), only it changes slowly to greyscale. Etc ...

Available in all planar modes except Y8.



Luma mode

Histogram modeluma.jpg

This mode will amplify luminance, and display very small luminance variations. This is good for detecting blocking and noise, and can be helpful at adjusting filter parameters. In this mode a 1 pixel luminance difference will show as a 16 pixel luminance pixel, thus seriously enhancing small flaws.

Available in planar and YUY2 modes.



Audiolevels mode

Histogram audiolevels.jpg

Shows the audio levels in decibels for each channel present. For example, if the source has six channels of audio, six vertical bars will be shown.

  • The green bars show the RMS ([wikipedia:Root_mean_square|Root Mean Square]]) level of the audio in each video frame (let's say n samples) using the following formula:
<math> RMS = 20 \cdot log_{10}( 1/32768 \cdot \sqrt{ 1/n \cdot \sum_{j=1}^{n} sample(j)^{2}} ) </math>
  • The blue bars show the max (peak) level of the audio in each video frame using the following formula:
<math> max = 20 \cdot log_{10}(max_{j} (sample(j)) / 32768) </math>

Planar video is required. Audio is converted to 16 bit.

The maximum possible level without clipping is 0 dB by definition. The minimum level for 16 bit audio is therefore

<math> 20 \cdot log_{10}(1/32768) = - 90.31 \ dB </math>    (since 216 / 2 = 32768)



Stereo, StereoY8 and StereoOverlay mode

Histogram modestereo.gif

These modes show a classic stereo graph (or Lissajous pattern) from the clip audio, often seen in recording studios. They are used to view the left-right phase distribution of the input signal. In-phase stereo appears predominantly vertical (as shown), but incorrectly phased stereo appears predominantly horizontal. Two-channel Mono appears as a vertical line.

StereoOverlay will overlay the graph on top of the original. Each frame will contain only information from the current frame to the beginning of the next frame. The signal is linearly upsampled 8x, to provide clearer visuals. Stereo and StereoY8 won't overlay the graph on the video, but will just return the graph alone as a 512×512 video clip (in YV12 or Y8 format respectively).

These modes require a source clip with stereo audio; StereoOverlay also requires a source clip with a planar color format.



Changes

v2.60 Added StereoY8 mode. Added factor option.
v2.58 Added planar support. Color2 and Audiolevels modes added.
v2.56 Added invalid colors in YUY2 mode.
v2.56 Added dots to mode = "stereo" to show bias/offsets.
v2.53 Added different modes.
Personal tools