LEADTOOLS Image Processing (Leadtools.ImageProcessing.Color assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
HistogramCommand Class
See Also  Members  



Creates an array that charts how many times each intensity level occurs in an image. This class can chart red, green, and blue separately or together. It is used for all resolutions, including 12 and 16-bit grayscale. Supported in Silverlight, Windows Phone 7

Object Model

HistogramCommand Class

Syntax

Visual Basic (Declaration) 
Public Class HistogramCommand 
   Inherits Leadtools.ImageProcessing.RasterCommand
   Implements IRasterCommand 
Visual Basic (Usage)Copy Code
Dim instance As HistogramCommand
C# 
public class HistogramCommand : Leadtools.ImageProcessing.RasterCommand, IRasterCommand  
C++/CLI 
public ref class HistogramCommand : public Leadtools.ImageProcessing.RasterCommand, IRasterCommand  

Example

Run the Leadtools.ImageProcessing.Color.HistogramCommand on an image to get the red-channel histogram.

Visual BasicCopy Code
Public Sub HistogramCommandExample()
   Dim codecs As New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True

   Dim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Master.jpg"))

   ' Prepare the command
   Dim command As HistogramCommand = New HistogramCommand
   Dim histogramValues() As Integer
   'Create the red-channel histogram.
   command.Channel = HistogramCommandFlags.Red Or HistogramCommandFlags.AllBits

   command.Run(leadImage)
   codecs.Save(leadImage, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24)
   histogramValues = command.Histogram

End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
public void HistogramCommandExample()
   {
      // Load an image
      RasterCodecs codecs = new RasterCodecs();
      codecs.ThrowExceptionsOnInvalidImages = true;

      RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Master.jpg"));

      // Prepare the command
      HistogramCommand command = new HistogramCommand();
      int [] histogramValues;
      //Create the red-channel histogram.
      command.Channel   = HistogramCommandFlags.Red | HistogramCommandFlags.AllBits;
      command.Run(image);
      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24);
      histogramValues = command.Histogram;

   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
public void HistogramCommandExample(RasterImage image, Stream outStream)
{
   // Prepare the command
   HistogramCommand command = new HistogramCommand();
   //Create the red-channel histogram.
   command.Channel = HistogramCommandFlags.Red | HistogramCommandFlags.AllBits;
   command.Run(image);
   // Save result image
   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24);
   image.Dispose();

   //This is where the histogram information is stored
   int[] histogramValues = command.Histogram;
}
SilverlightVBCopy Code
Public Sub HistogramCommandExample(ByVal image As RasterImage, ByVal outStream As Stream)
   ' Prepare the command
   Dim command As HistogramCommand = New HistogramCommand()
   'Create the red-channel histogram.
   command.Channel = HistogramCommandFlags.Red Or HistogramCommandFlags.AllBits
   command.Run(image)
   ' Save result image
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24)
   image.Dispose()

   'This is where the histogram information is stored
   Dim histogramValues As Integer() = command.Histogram
End Sub

Remarks

  • For 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, and 32 bit color images, intensity levels range from 0 to 255. Therefore, the resulting array has 256 items, indexed by intensity value. The value of each item is the number of occurrences of the intensity level.
  • For 48 and 64-bit images, the intensity levels range from 0 to 65535. Therefore, the resulting array has 65536 items, indexed by intensity value. The value of each item is the number of occurrences of the intensity level.
  • This class also works on 12 and 16-bit grayscale images. Intensity values in these images can range from 0 to (2^16 - 1) for 16-bit grayscale or from 0 to (2^12 - 1) for 12- bit grayscale. The Leadtools.RasterImage.LowBit and Leadtools.RasterImage.HighBit of this image identify which bits in a 12-bit or 16-bit entry are used. The Leadtools.RasterImage.LowBit and Leadtools.RasterImage.HighBit can be obtained by using the MinMaxCommand or by looking at the corresponding properties in the Leadtools.RasterImage class itself.
  • Specifically, the table must hold at least 2^(Leadtools.RasterImage.HighBit - LowBit + 1) entries if HistogramCommandFlags.LowHighBits is set in the Channel Property. If HistogramCommandFlags.AllBits is set in the Channel Property, the table must hold at least 4096 for 12-bit images and 65536 for 16-bit images.
  • For example, suppose HistogramCommandFlags.LowHighBits is set in the Channel property and you have a 16-bit grayscale image with Leadtools.RasterImage.LowBit = 2 and Leadtools.RasterImage.HighBit = 7. There are 2^(7-2+1) = 64 possible grayscale intensities. The table must therefore hold at least 64 entries. The number of grayscale values with bits 2 - 7 set to 0 can be found in Histogram [0]. The number of grayscale values with bit 2 set to 1 and bits 3 - 7 set to 0 can be found in Histogram [1], and so on up to Histogram [63]. Since the low bit is 2 and the high bit is 7, bits 0, 1, and bits 8 - 15 must all be 0. Therefore the values set in bits 2 - 7 determine the intensities present in the image. In the table below, the gray columns represent those bits that are always 0 for the image. The columns bit 7 through bit 2 represent possible settings for those bits. The last column gives the location within the Histogram array of the number of grayscale values having the corresponding settings. For example, Histogram [0] contains the number of grayscale values of intensity 0 (all bits set to 0). Histogram [1] contains all the grayscale values with intensity 4 (the 2 bit position set to 1). Histogram [2] contains all the grayscale values with intensity 8 (the 3 bit set to 1 and the remaining bits set to 0) and so on.
    bits 8 - 15 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 count location in Histogram
    all 0s
    0
    0
    0
    0
    0
    0
    0
    0
    Histogram [0]
    all 0s
    0
    0
    0
    0
    0
    1
    0
    0
    Histogram [1]
    all 0s
    0
    0
    0
    0
    1
    0
    0
    0
    Histogram [2]
    all 0s
    0
    0
    0
    0
    1
    1
    0
    0
    Histogram [3]
    all 0s
    0
    0
    0
    1
    0
    0
    0
    0
    Histogram [4]
    _
    0
    0
    0
    0
    0
    0
    _
    _
    and so on
    all 0s
    1
    1
    1
    1
    1
    1
    0
    0
    Histogram [63]
  • As another example, suppose you have a 16-bit grayscale image with Leadtools.RasterImage.LowBit = 0 and Leadtools.RasterImage.HighBit = 15. The table must hold 2^16 = 65,536 integer values.
  • This class supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available only in the Document/Medical toolkits.
  • This command does not support 32-bit grayscale images.
For more information, refer to Changing Brightness and Contrast.
For more information, refer to Grayscale Images.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.RasterCommand
      Leadtools.ImageProcessing.Color.HistogramCommand

Requirements

Target Platforms: Silverlight, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also

Reference

HistogramCommand Members
Leadtools.ImageProcessing.Color Namespace
Changing Brightness and Contrast
Grayscale Images
Color Halftone and Halftone Images
ChangeIntensityCommand Class
GammaCorrectCommand Class
ChangeContrastCommand Class
HistogramContrastCommand Class
StretchIntensityCommand Class
RemapIntensityCommand Class
InvertCommand Class
ChangeHueCommand Class
ChangeSaturationCommand Class
HistogramEqualizeCommand Class
Leadtools.ImageProcessing.FillCommand
Leadtools.ImageProcessing.Core.WindowLevelCommand
ChannelMixerCommand Class
Leadtools.ImageProcessing.Effects.DeinterlaceCommand
DesaturateCommand Class
Leadtools.ImageProcessing.Effects.EdgeDetectStatisticalCommand
LightControlCommand Class
Leadtools.ImageProcessing.Effects.SmoothEdgesCommand
LocalHistogramEqualizeCommand Class
AddWeightedCommand Class
ColorMergeCommand Class
ColorSeparateCommand Class
MultiplyCommand Class
AutoColorLevelCommand Class
ColorLevelCommand Class
Leadtools.ImageProcessing.Core.CorrelationListCommand
GrayScaleToDuotoneCommand Class
GrayScaleToMultitoneCommand Class
Leadtools.ImageProcessing.Core.HolePunchRemoveCommand
SelectiveColorCommand Class
Leadtools.ImageProcessing.Effects.SkeletonCommand
ChangeHueSaturationIntensityCommand Class
ColorReplaceCommand Class
ColorThresholdCommand Class
MathematicalFunctionCommand Class
SegmentCommand Class
AdaptiveContrastCommand Class
ApplyMathematicalLogicCommand Class
ColorIntensityBalanceCommand Class
Leadtools.ImageProcessing.Core.ColorizeGrayCommand
ContrastBrightnessIntensityCommand Class
Leadtools.ImageProcessing.Core.DigitalSubtractCommand
DynamicBinaryCommand Class
Leadtools.ImageProcessing.Effects.EdgeDetectEffectCommand
Leadtools.ImageProcessing.SpecialEffects.FunctionalLightCommand
Leadtools.ImageProcessing.Core.MultiscaleEnhancementCommand
Leadtools.ImageProcessing.Core.SelectDataCommand
Leadtools.ImageProcessing.Core.ShiftDataCommand