Rate This Document
Findability
Accuracy
Completeness
Readability

Histogram

Computes the intensity histogram of each channel of an image and stores the result in the hist array. The actual operation is to divide the entire range into several bins, specify the region for image statistics, and calculate how many pixels fall into each bin in the region.

  • levels is an array with length levelsLen. A bin consists of two adjacent values of levels, in the format of [a, b). The number of values in the hist array is levelsLen – 1.
  • hist[k] is the number of source image pixels src(x, y) that meet the condition levels[k] <= src(x,y) < levels[k+1].

The function interface is declared as follows:

  • Initialization:

    HmppResult HMPPI_HistogramInit(HmppDataType dataType, const float *levels[], int32_t levelsLen[], int32_t numChannels,HmppiHistogramPolicy **policy);

    HmppResult HMPPI_HistogramUniformInit(HmppDataType dataType, float lowerLevel[], float upperLevel[],int32_t levelsLen[], int32_t numChannels, HmppiHistogramPolicy **policy);

  • Single-channel main functions:

    HmppResult HMPPI_Histogram_8u_C1R(const uint8_t *src, int32_t srcStep, HmppiSize roiSize, uint32_t *hist, const HmppiHistogramPolicy *policy);

    HmppResult HMPPI_Histogram_16u_C1R(const uint16_t *src, int32_t srcStep, HmppiSize roiSize, uint32_t *hist, const HmppiHistogramPolicy *policy);

    HmppResult HMPPI_Histogram_16s_C1R(const int16_t *src, int32_t srcStep, HmppiSize roiSize, uint32_t *hist, const HmppiHistogramPolicy *policy);

    HmppResult HMPPI_Histogram_32f_C1R(const float *src, int32_t srcStep, HmppiSize roiSize, uint32_t *hist, const HmppiHistogramPolicy *policy);

  • Multi-channel main functions:

    HmppResult HMPPI_Histogram_8u_C3R(const uint8_t *src, int32_t srcStep, HmppiSize roiSize, uint32_t *hist[3], const HmppiHistogramPolicy *policy);

    HmppResult HMPPI_Histogram_16u_C3R(const uint16_t *src, int32_t srcStep, HmppiSize roiSize, uint32_t *hist[3], const HmppiHistogramPolicy *policy);

    HmppResult HMPPI_Histogram_16s_C3R(const int16_t *src, int32_t srcStep, HmppiSize roiSize, uint32_t *hist[3], const HmppiHistogramPolicy *policy);

    HmppResult HMPPI_Histogram_32f_C3R(const float *src, int32_t srcStep, HmppiSize roiSize, uint32_t *hist[3], const HmppiHistogramPolicy *policy);

    HmppResult HMPPI_Histogram_8u_C4R(const uint8_t *src, int32_t srcStep, HmppiSize roiSize, uint32_t *hist[4], const HmppiHistogramPolicy *policy);

    HmppResult HMPPI_Histogram_16u_C4R(const uint16_t *src, int32_t srcStep, HmppiSize roiSize, uint32_t *hist[4], const HmppiHistogramPolicy *policy);

    HmppResult HMPPI_Histogram_16s_C4R(const int16_t *src, int32_t srcStep, HmppiSize roiSize, uint32_t *hist[4], const HmppiHistogramPolicy *policy);

    HmppResult HMPPI_Histogram_32f_C4R(const float *src, int32_t srcStep, HmppiSize roiSize, uint32_t *hist[4], const HmppiHistogramPolicy *policy);

  • Obtaining the bin bounds:

    HmppResult HMPPI_HistogramGetLevels(const HmppiHistogramPolicy *policy, float *levels[]);

  • Release:

    HmppResult HMPPI_HistogramRelease(HmppiHistogramPolicy *policy);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the source image ROI

The value cannot be NULL.

Input

srcStep

Distance between starts of consecutive lines in the source image, in bytes

(0, INT_MAX]

Input

roiSize

Size of the source image ROI, in pixels

roiSize.width ∈ (0, INT_MAX], roiSize.height ∈ (0, INT_MAX]

Input

hist

Pointer to the computed histogram. In the case of multi-channel data, hist is an array of pointers to the histogram of each channel.

The value cannot be NULL.

Output

datatype

Data type of the source image

HMPP8U, HMPP16U

HMPP16S, HMPP32F

Input

Levels

Pointer to the array of levels

The value cannot be NULL.

Input

lowerLevel

Lower bound of the level of a uniform histogram, for each channel

The value cannot be NULL.

Input

upperLevel

Upper bound of the level of a uniform histogram, for each channel

The value cannot be NULL.

Input

numChannels

Number of channels

1, 3, 4

Input

levelsLen

Number of levels in the array. Each channel has a separate number of levels.

The total number of levels in the array for each channel cannot exceed 50,000,000.

Generally, the number of levels in an integer array does not exceed the number of integers between the specified range of this type, and the number of levels in a floating-point array is far less than 50,000,000.

Input

policy (in the Init function)

Pointer to pointer to the HistogramPolicy structure

The value cannot be NULL.

Output

policy (in the main and release functions)

Pointer to the Histogram structure

The value cannot be NULL.

Input

Return Value

  • Success: HMPP_STS_NO_ERR
  • Failure: An error code is returned.

Error Codes

Error Code

Description

HMPP_STS_NULL_PTR_ERR

Any of the specified pointers is NULL.

HMPP_STS_DATETYPE_ERR

The input data type is not HMPP8U, HMPP16U, HMPP16S or HMPP32F.

HMPP_STS_HISTOLEVELS_ERR

The number of levels in the array is less than 2.

HMPP_STS_NUMCHANNELS_ERR

The number of channels is not 1, 3, or 4.

HMPP_STS_MALLOC_FAILED

Memory allocation failed.

HMPP_STS_OVERFLOW

The number of levels in the array for each channel exceeds 500,000,000.

HMPP_STS_POLICY_STATE_ERR

The flag value of the policy structure is incorrect.

HMPP_STS_STEP_ERR

The value of srcStep is less than or equal to 0.

HMPP_STS_ROI_ERR

roiSize.width x Number of channels x Number of bytes occupied by the data type > Step

HMPP_STS_SIZE_ERR

The value of roiSize.width or roiSize.height is less than or equal to 0.

HMPP_STS_RANGE_ERR

The levels array in Init mode is not a non-decreasing sequence, or the value of lowerLevel is greater than that of upperLevel in Uniform mode.

Example

void HistogramExample()
{
    const int32_t numChannels = 3;
    HmppiSize roiSize = {2,3};
    uint8_t src[28] = { 1, 2, 3, 4, 5, 6, 7, 
                        102, 103, 104, 105, 106, 107, 108,
                        203, 204, 205, 255, 255, 255, 209,
                        4, 5, 6, 7, 8, 9, 10 };
    int32_t srcStep = 7 * sizeof(uint8_t);
    int32_t levelsLen[3] = {3, 4, 5};
    float p0[3] = {0, 105, 256};
    float p1[4] = {0, 100, 200, 256};
    float p2[5] = {0, 60, 105, 205, 256};
    const float *levels[3] = {p0, p1, p2};
    uint32_t h0[2], h1[3], h2[4];
    uint32_t *hist[3] = {h0, h1, h2};

    HmppiHistogramPolicy *policy = NULL;
    HmppResult result = HMPPI_HistogramInit(HMPP8U, levels, levelsLen, numChannels, &policy);
    if (result != HMPP_STS_NO_ERR) {
        printf("Histogram Init error: %d\n", result);
    }
    result = HMPPI_Histogram_8u_C3R(src, srcStep, roiSize, hist, policy);
    if (result != HMPP_STS_NO_ERR) {
        printf("Histogram error: %d\n", result);
    }
    HMPPI_HistogramRelease(policy);

    printf("hist:\n");
    for (int32_t i = 0; i < 3; i++){
        for (int32_t j = 0; j < levelsLen[i] - 1; j++){
            printf("%d ", hist[i][j]);
        }
        printf("\n");
    }
}

int main()
{
    HistogramExample();
    return 0;
}

Output:

hist:
3 3
2 2 2
2 1 1 2