DicomObjects.NET.8.48 Documentation
DicomObjects Namespace / DicomImage Class / Histogram Method
The lowest pixel value to be included
The highest pixel value to be included
The number of adjacent pixel values to be grouped into each bin
Example

In This Topic
    Histogram Method
    In This Topic
    Returns an array containing the distribution of raw pixel values.
    Syntax
    'Declaration
     
    
    Public Function Histogram( _
       ByVal MinValue As System.Integer, _
       ByVal MaxValue As System.Integer, _
       ByVal BinSize As System.Integer _
    ) As System.Integer()
    public System.int[] Histogram( 
       System.int MinValue,
       System.int MaxValue,
       System.int BinSize
    )

    Parameters

    MinValue
    The lowest pixel value to be included
    MaxValue
    The highest pixel value to be included
    BinSize
    The number of adjacent pixel values to be grouped into each bin

    Return Value

    An integer array containing the distribution.
    Remarks
    The format of the returned data is suitable for creating DICOM Image Histogram modules, though to use this a few other attributes must be added. In keeping with the image histogram module, the values used are raw pixel values before application of a modality lookup table or rescaling � apply Lookup Tables if such translation is required. For multi-frame images, only the first frame is used for this method.
    Example
    DicomImage image = new DicomImage("your_dicom_image.dcm");
                
    int minPixelValue = 0;
    int maxPixelValue = 3000;
    int binSize = 50;
                
    int[] histogram = image.Histogram(minPixelValue, maxPixelValue, binSize);
                         
    // Example output: 
    // histogram[0] = 55772 -> 55,772 pixels have values between 0-49
    // histogram[1] = 0 -> No pixels have values between 50 - 99
                         
    // Printing histogram values (mapping index to HU range)
    for (int i = 0; i < histogram.Length; i++)
    {
        int lowerBound = minPixelValue + (i * binSize);
        int upperBound = lowerBound + binSize - 1;
        Console.WriteLine($"Bin {lowerBound} to {upperBound}: {histogram[i]} pixels");
    }
    Requirements

    Target Platforms: .NET CLR 4.8 or higher

    See Also