# Can i invert value of every pixel?

## Can i invert value of every pixel?

I would like to invert value of every pixel in my image in-place. Image is allocated with ippiMalloc_32f_C1.

I mean if it was 2, it must become 0.5. So f(x) -> 1/x.

I would like to use only O(1) additional memory.

Thanks!

2 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

Hi Ihor,

just call the next function for each image row:

/* ////////////////////////////////////////////////////////////////////////////
//  Name:       ippsDivCRev
//  Purpose:    Divides a constant value by each element of a vector
//  Arguments:
//    val               Constant value used as a dividend in the operation
//    pSrc              Pointer to the source vector whose elements are used as divisors
//    pDst              Pointer to the destination vector
//    pSrcDst           Pointer to the source and destination vector for in-place operation
//    len               Number of elements in the vector
//    scaleFactor       Scale factor
//  Return:
//    ippStsNullPtrErr  At least one of the pointers is NULL
//    ippStsSizeErr     Vector length is less than 1
//    ippStsDivByZero   Warning status if any element of vector is zero. IF the dividend is zero
//                      than result is NaN, if the dividend is not zero than result is Infinity
//                      with correspondent sign. Execution is not aborted.
//                      For the integer operation zero instead of NaN and the corresponding
//                      bound values instead of Infinity
//    ippStsNoErr       No error
//  Note:
//    DivCRev(v,X,Y)  :    Y[n] = v / X[n]
//    DivCRev(v,X)    :    X[n] = v / X[n]
*/
IPPAPI(IppStatus, ippsDivCRev_16u_I, (                    Ipp16u val, Ipp16u* pSrcDst, int len))
IPPAPI(IppStatus, ippsDivCRev_16u,   (const Ipp16u* pSrc, Ipp16u val, Ipp16u* pDst,    int len))
IPPAPI(IppStatus, ippsDivCRev_32f_I, (                    Ipp32f val, Ipp32f* pSrcDst, int len))
IPPAPI(IppStatus, ippsDivCRev_32f,   (const Ipp32f* pSrc, Ipp32f val, Ipp32f* pDst,    int len))

regards, Igor