Rate This Document
Findability
Accuracy
Completeness
Readability

CountInRange

Counts the number of pixels whose values are within a specified range and saves the result to the counts array. In the case of multiple channels, the number of pixels in the specified range is calculated on each channel and stored in the counts array.

The function interface declaration is as follows:

  • Single-channel operation:

    HmppResult HMPPI_CountInRange_32f_C1R(const float *src, int32_t srcStep, HmppiSize roiSize, int32_t *counts, float lowerBound, float upperBound);

    HmppResult HMPPI_CountInRange_8u_C1R(const uint8_t *src, int32_t srcStep, HmppiSize roiSize, int32_t *counts, uint8_t lowerBound, uint8_t upperBound);

  • Multi-channel operation:

    HmppResult HMPPI_CountInRange_8u_C3R(const uint8_t *src, int32_t srcStep, HmppiSize roiSize, int32_t counts[3], uint8_t lowerBound[3], uint8_t upperBound[3]);

    HmppResult HMPPI_CountInRange_8u_AC4R(const uint8_t *src, int32_t srcStep, HmppiSize roiSize, int32_t counts[3], uint8_t lowerBound[3], uint8_t upperBound[3]);

    HmppResult HMPPI_CountInRange_32f_C3R(const float *src, int32_t srcStep, HmppiSize roiSize, int32_t counts[3], float lowerBound[3], float upperBound[3]);

    HmppResult HMPPI_CountInRange_32f_AC4R(const float *src, int32_t srcStep, HmppiSize roiSize, int32_t counts[3], float lowerBound[3], float upperBound[3]);

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

The value must be zero or a positive integer.

Input

roiSize

Size of the ROI of the source and destination images, in pixels

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

Input

counts

Pointer to the number of pixels within the specified range (single-channel scenario)

The value must be zero or a positive integer.

Input/Output

counts[]

Array that contains the number of pixels of each channel within the specified range (multi-channel scenario)

The value must be zero or a positive integer.

Input/Output

lowerBound

Lower bound of the specified intensity range (single-channel scenario)

Range of the input data type

Input

lowerBound[]

Array that contains the lower bounds of the specified intensity range for each channel (multi-channel scenario)

Range of the input data type

Input

upperBound

Upper bound of the specified intensity range (single-channel scenario)

Range of the input data type

Input

upperBound[]

Array that contains the upper bounds of the specified intensity range for each channel (multi-channel scenario)

Range of the input data type

Input

Return Value

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

Error Codes

Error Code

Description

HMPP_STS_NULL_PTR_ERR

The value of src is NULL.

HMPP_STS_SIZE_ERR

The width or height of roiSize is zero or negative.

HMPP_STS_STEP_ERR

The value of srcStep is zero or negative.

HMPP_STS_NOT_EVEN_STEP_ERR

The value of srcStep cannot be exactly divided by the byte length of the data type to which src belongs.

HMPP_STS_ROI_ERR

roiSize.width > Step

HMPP_STS_RANGE_ERR

The value of lowerBound is greater than that of upperBound.

Example

void CountInRangeExample()
{
    HmppiSize roi = {3, 4};
    uint8_t src[9 * 4] = {1, 1, 1, 2, 2, 2, 3, 3, 3, 
                          4, 4, 4, 5, 5, 5, 6, 6, 6, 
                          7, 7, 7, 8, 8, 8, 9, 9, 9,
                          10, 10, 10, 11, 11, 11, 12, 12, 12};
    int32_t srcStep =9*sizeof(uint8_t);
    int32_t counts[3] = {0};
    uint8_t lowerBound[3] = {0, 2, 4};
    uint8_t upperBound[3] = {8, 8, 8};
    int32_t i;
    HmppResult result =HMPPI_CountInRange_8u_C3R(src, srcStep, roi, counts, lowerBound, upperBound);
    printf("result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    for(i =0; i <3; i++) {
        printf("%d ", counts[i]);
    }
    printf("\n");
}

Output:

result = 0
8 7 5