Histogram

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (one more touch-up)
(*Classic* add turned version, *Levels* add "factor" image, *Color* annotate vector)
Line 17: Line 17:
 
<div style="max-width:62em" >
 
<div style="max-width:62em" >
  
[[Image:histogram_classic.jpg]]
+
[[File:histogram_classic.jpg]]
  
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.  
+
Available in [[YUV]] mode only. This will add a per-line luminance graph (usually called a [[wikipedia:Waveform_monitor|Waveform Monitor]]) on the right side of the video, increasing clip.[[Clip_properties|Width]] by 256. The left side of the graph represents luma=0 and the right side represents luma=255. Values outside the [[Limiter|valid CCIR-601 range]] are shown with a brown/yellowish color background; 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.
+
If you prefer to see luma=0 on bottom and luma=255 on top, use <code>[[TurnRight]].Histogram.[[TurnLeft]]</code> like this:
 +
 
 +
::[[File:Histogram_classic-v2-turned.jpg]]
 +
 
 
</div>
 
</div>
  
Line 33: Line 35:
 
[[File:Histogram-vortex-levels.jpg]]
 
[[File: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.
+
Available in all planar modes, except [[Y8]]. This mode will display three histograms on the right side of the video frame, increasing clip.[[Clip_properties|Width]] by 256. 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 top graph displays the ''Y'' (luma) distribution of the frame, where the left side represents Y=0 and the right side represents Y=255. Values outside the [[Limiter|valid CCIR601 range]] have been indicated with faded colors; Y=128 has been marked with a dotted line. The vertical axis shows the number of pixels for a given luma (Y) value.  
  
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.
+
The middle graph is similar, and displays the ''U'' component; the bottom graph displays the ''V'' component.
  
'''NOTE''', {{FuncArg|factor}} is an ''unnamed ''optional argument; <br style="line-height:60%" />
+
The {{FuncArg|factor}} option (100.0 by default) specifies how the histograms are displayed, exaggerating the vertical scale. It is specified as percentage of the total population (that is number of luma or chroma pixels in a frame). For example, compare the output of <code>Histogram("levels", 0.5)</code> to the previous image:
<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]].
+
[[File:Histogram-vortex-levels-v3-levels0,5.jpg]]
 +
 
 +
'''NOTE''', {{FuncArg|factor}} is an ''unnamed ''optional argument; <br style="line-height:60%" />
 +
<code>Histogram(mode="levels", '''factor='''0.5)</code> will not work, but <code>Histogram("levels", 0.5)</code> works fine.
 
</div>
 
</div>
  
Line 52: Line 56:
 
[[File:Histogram-vortex-color.jpg]]
 
[[File: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]]. This mode will display the chroma values (U/V color placement) in a two dimensional graph (called a [[wikipedia:Vectorscope|vectorscope]]) on the right side of the video frame, increasing clip.[[Clip_properties|Width]] by 256. It can be used to read of the [[wikipedia:Hue|hue]] and [[wikipedia:Colorfulness#Saturation|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 chroma value. The lighter background denotes the [[Limiter|valid CCIR-601 range]].  
  
Available in all planar modes except Y8.
+
 
<div>
+
<div id="colorvector">
 
{| border="0"  
 
{| border="0"  
 
|
 
|
[[File:Labeled-vector6b.png|left|Histogram(mode="color") output with added labels]]  
+
[[File:Labeled-vector6b.png|left|Histogram("color") output with added labels]]  
 
|style="vertical-align:top; margin-right:10%"|  
 
|style="vertical-align:top; margin-right:10%"|  
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 vectorscope image to the left has labels added for the ''U'' and ''V'' axes and degrees of [[wikipedia:Hue|hue]]. Spots have also been added, showing 75% saturated [[ColorBars]]. 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.
+
The position of a point on the scope corresponds to a chroma value from the input clip. So the graph can be used to read of the hue (shown as angular position, with 0 degrees at 3 o'clock) and the saturation (shown as distance from the center). As the hue of a color changes, it moves around the square. At the center of the scope, U=0 and V=0, which means that the saturation is zero and 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 scope.  
 
|}</div>
 
|}</div>
 +
At U=255, V=128 the hue is zero (blue, approximately) and the saturation is at maximum, that is, <br>
 +
 +
::saturation = sqrt( (U-128)<sup>2</sup> + (V-128)<sup>2</sup> ) or 127 <br>
 +
 +
When turning hue clockwise 90 degrees, the chroma is given by U=128, V=255 (red, approximately). 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, only it fades slowly to [[GreyScale|greyscale]].
 
</div>
 
</div>
  
Line 73: Line 82:
 
[[File:Histogram-vortex-color2.jpg]]
 
[[File: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.
+
Available in all planar modes except [[Y8]]. This mode will display the pixels in a two dimensional graph (called a [[wikipedia:Vectorscope|vectorscope]]) on the right side of the video frame, increasing clip.[[Clip_properties|Width]] by 256. It can be used to read of the [[wikipedia:Hue|hue]] and [[wikipedia:Colorfulness#Saturation|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 ''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 white square denotes the [[Limiter|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, <br>
+
<div id="colorvector">
 
+
{| border="0"
::sqrt((U-128)<sup>2</sup> + (V-128)<sup>2</sup>) = 127 <br>
+
|
 
+
[[File:Labeled-vector-color2.png|left|Histogram("color2") output with added labels]]
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 ...
+
|style="vertical-align:top; margin-right:10%"| As in the previous [[#colorvector|vectorscope image]], labels have been added. The position of a point on the scope corresponds to a chroma value from the input clip, exactly as with <code>Histogram("color")</code>. A color wheel is shown around the circumference of the scope and divided into six hues (red, yellow, green, cyan, blue and magenta), with white tick marks at 15 degree intervals, to help you reading of the hue values.   
 
+
|}</div>
Available in all planar modes except Y8.
+
 
</div>
 
</div>
  
Line 95: Line 102:
 
[[Image:histogram_modeluma.jpg]]
 
[[Image: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. 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.
+
 
</div>
 
</div>
  
Line 107: Line 112:
 
[[Image:histogram_audiolevels.jpg]]
 
[[Image:histogram_audiolevels.jpg]]
  
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.  
+
[[Planar]] video is required. Audio is converted to 16 bit.  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''}} ([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:
 
* 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:
Line 116: Line 121:
  
 
::[[File:Histogram-eq-2.png|x16px|<math> max = 20 \cdot log_{10}(max_{j} (sample(j)) / 32768) </math>]]
 
::[[File:Histogram-eq-2.png|x16px|<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 [[wikipedia: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
Line 131: Line 134:
 
[[Image:histogram_modestereo.gif|256px|]]
 
[[Image:histogram_modestereo.gif|256px|]]
 
   
 
   
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.  
+
Requires a source clip with stereo audio; '''StereoOverlay''' also requires a source clip with a [[Planar|planar]] color format. 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×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.
 
 
</div>
 
</div>
  

Revision as of 20:12, 6 March 2016

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

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



Classic mode

Histogram classic.jpg

Available in YUV mode only. This will add a per-line luminance graph (usually called a Waveform Monitor) on the right side of the video, increasing clip.Width by 256. The left side of the graph represents luma=0 and the right side represents luma=255. Values outside the valid CCIR-601 range are shown with a brown/yellowish color background; a greenish line represents Y=128.


If you prefer to see luma=0 on bottom and luma=255 on top, use TurnRight.Histogram.TurnLeft like this:

Histogram classic-v2-turned.jpg



Levels mode

Histogram-vortex-levels.jpg

Available in all planar modes, except Y8. This mode will display three histograms on the right side of the video frame, increasing clip.Width by 256. 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. Values outside the valid CCIR601 range have been indicated with faded colors; 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 is similar, and displays the U component; the bottom graph displays the V component.

The factor option (100.0 by default) specifies how the histograms are displayed, exaggerating the vertical scale. It is specified as percentage of the total population (that is number of luma or chroma pixels in a frame). For example, compare the output of Histogram("levels", 0.5) to the previous image:

Histogram-vortex-levels-v3-levels0,5.jpg

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



Color mode

Histogram-vortex-color.jpg

Available in all planar modes except Y8. This mode will display the chroma values (U/V color placement) in a two dimensional graph (called a vectorscope) on the right side of the video frame, increasing clip.Width by 256. 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 chroma value. The lighter background denotes the valid CCIR-601 range.


Histogram("color") output with added labels

The vectorscope image to the left has labels added for the U and V axes and degrees of hue. Spots have also been added, showing 75% saturated ColorBars. 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 point on the scope corresponds to a chroma value from the input clip. So the graph can be used to read of the hue (shown as angular position, with 0 degrees at 3 o'clock) and the saturation (shown as distance from the center). As the hue of a color changes, it moves around the square. At the center of the scope, U=0 and V=0, which means that the saturation is zero and 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 scope.

At U=255, V=128 the hue is zero (blue, approximately) and the saturation is at maximum, that is,

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

When turning hue clockwise 90 degrees, the chroma is given by U=128, V=255 (red, approximately). 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, only it fades slowly to greyscale.



Color2 mode

Histogram-vortex-color2.jpg

Available in all planar modes except Y8. This mode will display the pixels in a two dimensional graph (called a vectorscope) on the right side of the video frame, increasing clip.Width by 256. 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 white square denotes the valid CCIR-601 range.


Histogram("color2") output with added labels
As in the previous vectorscope image, labels have been added. The position of a point on the scope corresponds to a chroma value from the input clip, exactly as with Histogram("color"). A color wheel is shown around the circumference of the scope and divided into six hues (red, yellow, green, cyan, blue and magenta), with white tick marks at 15 degree intervals, to help you reading of the hue values.



Luma mode

Histogram modeluma.jpg

Available in planar and YUY2 modes. 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.



Audiolevels mode

Histogram audiolevels.jpg

Planar video is required. Audio is converted to 16 bit. 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>

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

Requires a source clip with stereo audio; StereoOverlay also requires a source clip with a planar color format. 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).



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