Rate This Document
Findability
Accuracy
Completeness
Readability

Mean

Computes the mean of image pixel values. For multi-channel images, the mean is calculated over each channel and saved in the corresponding channel array.

The function interface declaration is as follows:

HmppResult HMPPI_Mean_8u_C3R(const uint8_t *src, int32_t srcStep, HmppiSize roiSize, double mean[3]);

HmppResult HMPPI_Mean_8u_C4R(const uint8_t *src, int32_t srcStep, HmppiSize roiSize, double mean[4]);

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

mean[]

Array for storing the mean values for each channel of the source image (multi-channel scenario)

Value range of the pixel data type of the source image

Input/Output

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

The value of roiSize.width is greater than the step.

HMPP_STS_COI_ERR

The value of coi is not 1, 2, or 3.

Example

void MeanExample()
{
    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);
    double mean[3] = {0.0};
    int32_t i;
    HmppResult result =HMPPI_Mean_8u_C3R(src, srcStep, roi, mean);
    printf("result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    for(i =0; i <3; i++) {
        printf("%lf ", mean[i]);
    }
    printf("\n");
}

Output:

result = 0
6.500000 6.500000 6.500000