Intel® Integrated Performance Primitives (Intel® IPP) Developer Guide and Reference

ID 790148
Date 3/22/2024
Public
Document Table of Contents

GetHuMoments

Retrieves image Hu moment invariants computed by ippiMoments function.

Syntax

IppStatus ippiGetHuMoments_64f(const IppiMomentState_64f* pState, int nChannel, IppiHuMoment_64f pHm);

Include Files

ippi.h

Domain Dependencies

Headers: ippcore.h, ippvm.h, ipps.h

Libraries: ippcore.lib, ippvm.lib, ipps.lib

Parameters

pState

Pointer to the structure that stores image moments.

nChannel

The channel for which the moment is returned.

pHm

Pointer to the array containing the Hu moment invariants.

Description

This function returns the pointer pHm to the array of seven Hu moment invariants previously computed by the ippiMoments function.

Return Values

ippStsNoErr

Indicates no error. Any other value indicates an error or a warning.

ippStsNullPtrErr

Indicates an error condition if pState or pHm pointer is NULL.

ippStsContextMatchErr

Indicates an error condition if a pointer to an invalid structure is passed.

ippStsMoment00ZeroErr

Indicates an error condition if M(0,0) value is close to zero.

Example

/*******************************************************************************
* Copyright 2015 Intel Corporation.
*
*
* This software and the related documents are Intel copyrighted materials, and your use of them is governed by
* the express license under which they were provided to you ('License'). Unless the License provides otherwise,
* you may not use, modify, copy, publish, distribute, disclose or transmit this software or the related
* documents without Intel's prior written permission.
* This software and the related documents are provided as is, with no express or implied warranties, other than
* those that are expressly stated in the License.
*******************************************************************************/

//    A simple example of computing Hu moment values for images.
// implemented with Intel(R) Integrated Performance Primitives (Intel(R) IPP) functions:
//     ippiSet_8u_C1R
//     ippiMomentGetStateSize_64f
//     ippiMomentInit_64f
//     ippiMoments64f_8u_C1R
//     ippiGetHuMoments_64f

#include <stdio.h>
#include "ipp.h"

/* Next two defines are created to simplify code reading and understanding */
#define EXIT_MAIN exitLine:                                  /* Label for Exit */
#define check_sts(st) if((st) != ippStsNoErr) goto exitLine; /* Go to Exit if Intel(R) IPP function returned status different from ippStsNoErr */

/* Results of ippMalloc() are not validated because Intel(R) IPP functions perform bad arguments check and will return an appropriate status  */

int main(void)
{
    IppStatus status = ippStsNoErr;
    Ipp8u pSrc[64];                              /* Pointer to source image */
    IppiSize roiA={8,8}, roiH={8,1}, roiV={1,8}; /* Used image ROI sizes */
    int sizeState = 0;                           /* State size */
    IppiHuMoment_64f hmH = {0}, hmV= {0};        /* Horizontal and vertical moments */
    IppiMomentState_64f *pState = NULL;          /* Pointers to state structure */

    check_sts( status = ippiMomentGetStateSize_64f(ippAlgHintNone, &sizeState) )

    /* memory allocation */
    pState  = (IppiMomentState_64f*) ippMalloc( sizeState );

    check_sts( status = ippiMomentInit_64f(pState, ippAlgHintNone) )

    /* set horizontal edge */
    check_sts( status = ippiSet_8u_C1R( 0, pSrc, 8, roiA ) )
    check_sts( status = ippiSet_8u_C1R( 3, pSrc, 8, roiH ) )

    /* compute spatial moment values */
    check_sts( status = ippiMoments64f_8u_C1R( pSrc, 8, roiA, pState ) )

    /* compute seven Hu moment invariants */
    check_sts( status = ippiGetHuMoments_64f( pState, 0, hmH ) )

    /* set vertical edge */
    check_sts( status = ippiSet_8u_C1R( 0, pSrc, 8, roiA ) )
    check_sts( status = ippiSet_8u_C1R( 3, pSrc, 8, roiV ) )

    /* compute spatial moment values */
    check_sts( status = ippiMoments64f_8u_C1R( pSrc, 8, roiA, pState ) )

    /* compute seven Hu moment invariants */
    check_sts( status = ippiGetHuMoments_64f( pState, 0, hmV ) )

EXIT_MAIN
    ippFree( pState );
    printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status));
    return (int)status;
}