FilterBilateral

Performs bilateral filtering of the image.

Syntax

IppStatus ippiFilterBilateral_8u_C1R(const Ipp8u* pSrc, int srcStep, Ipp8u* pDst, int dstStep, IppiSize dstRoiSize, IppiSize kernelSize, IppiFilterBilateralSpec* pSpec);

Parameters

pSrc

Pointer to the source image ROI.

srcStep

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

pDst

Pointer to the destination image ROI.

dstStep

Distance in bytes between starts of consecutive lines in the destination image.

dstRoiSize

Size of the source and destination ROI in pixels.

kernelSize

Size of the filter kernel.

pSpec

Pointer to the bilateral filter structure.

Description

The function ippiFilterBilateral is declared in the ippi.h file. It operates with ROI (see Regions of Interest in Intel IPP). This function applies the bilateral filter with the rectangular kernel of the size kernelSize to the pixels of ROI of the source image pSrc. The anchor cell is always central cell of the kernel. Therefore, both dimensions of the filter kernel should be odd; if some of size is even, the function changes its value to the nearest less odd number.

The bilateral filter structure pSpec contains the parameters of filtering and must be initialized by the function ippiFilterBilateralInit beforehand. The size of the filter kernel should not be greater than the value maxKernelSize specified in the filter structure.

Example “Using Bilateral Filtering Functions” shows how to use the function ippiFilterBilateral.

Return Values

ippStsNoErr

Indicates no error. Any other value indicates an error.

ippStsNullPtrErr

Indicates an error condition if one of the specified pointers is NULL.

ippStsSizeErr

Indicates an error condition if dstRoiSize has a field with a zero or negative value.

ippStsMaskSizeErr

Indicates an error condition if kernelSize has a field with a zero or negative value.

ippStsStepErr

Indicates an error condition if srcStep or dstStep is less than or equal to 0.

ippStsContextMatchErr

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

Using Bilateral Filtering Functions

#include <stdlib.h>
#include <stdio.h>
#include "ippcore.h"
#include "ipps.h"
#include "ippi.h"

#define D_WIDTH     8
#define D_HEIGHT    8
#define D_MAX_W_KNL 5
#define D_MAX_H_KNL 5

int main( void )
{
    Ipp8u       *src, *src_start;
    Ipp8u       *dst1, *dst2, *dst3;
    Ipp8u       *ptmp;
    int         width_src, height_src;
    int         width_dst, height_dst;
    int         step_src;
    int         step_dst1, step_dst2, step_dst3;
    int         bufsize;
    int         stepInKernel;
    IppiSize    roi;
    IppiSize    kernel;
    int         i, j;
    Ipp32f      valsigma;
    Ipp32f      possigma;
    IppiFilterBilateralSpec *pSpec;


    width_src = D_WIDTH + D_MAX_W_KNL - 1;
    height_src = D_HEIGHT + D_MAX_H_KNL - 1;
    src = ippiMalloc_8u_C1( width_src, height_src, &step_src );
    for ( i = 0, ptmp = src; i < height_src; i++ ) {
        for ( j = 0; j < width_src; j++ ) {
            ptmp[j] = (Ipp8u)rand();
        }
        ptmp = (Ipp8u *)( (char *)ptmp + step_src );
    }
    src_start = (Ipp8u *)( (char *)src + (D_MAX_H_KNL>>1) * step_src );
    src_start += (D_MAX_W_KNL>>1);

    width_dst = D_WIDTH;
    height_dst = D_HEIGHT;
    dst1 = ippiMalloc_8u_C1( width_dst, height_dst, &step_dst1 );
    dst2 = ippiMalloc_8u_C1( width_dst, height_dst, &step_dst2 );
    dst3 = ippiMalloc_8u_C1( width_dst, height_dst, &step_dst3 );


    roi.width = D_WIDTH;
    roi.height = D_HEIGHT;
    kernel.width = D_MAX_W_KNL;
    kernel.height = D_MAX_H_KNL;
    ippiFilterBilateralGetBufSize_8u_C1R( ippiFilterBilateralGauss, roi,
                                              kernel, &bufsize);
    pSpec = (IppiFilterBilateralSpec *)ippsMalloc_8u( bufsize );

    valsigma = 16.f;
    possigma = 16.f;
    stepInKernel = 1;
    ippiFilterBilateralInit_8u_C1R( ippiFilterBilateralGauss, kernel, valsigma,
                                    possigma, stepInKernel, pSpec );
    ippiFilterBilateral_8u_C1R( src_start, step_src, dst1, step_dst1, roi,
                                   kernel, pSpec );

    valsigma = 1.f;
    possigma = 1.f;
    stepInKernel = 1;
    ippiFilterBilateralInit_8u_C1R( ippiFilterBilateralGauss, kernel, valsigma,
                                    possigma, stepInKernel, pSpec );
    ippiFilterBilateral_8u_C1R( src_start, step_src, dst2, step_dst2, roi,
                                   kernel, pSpec );


    valsigma = 16.f;
    possigma = 16.f;
    stepInKernel = 2;
    ippiFilterBilateralInit_8u_C1R( ippiFilterBilateralGauss, kernel, valsigma,
                                    possigma, stepInKernel, pSpec );
    ippiFilterBilateral_8u_C1R( src_start, step_src, dst3, step_dst3, roi,
                                   kernel, pSpec );


    
    ippsFree( pSpec );
    
    printf("\n Src =");
    for ( i = 0, ptmp = src; i < height_src; i++ ) {
        printf("\n");
        for ( j = 0; j < width_src; j++ ) {
            printf("%3d ",ptmp[j]);
        }
        ptmp = (Ipp8u *)( (char *)ptmp + step_src );
    }

    printf("\n Dst1 =");
    for ( i = 0, ptmp = dst1; i < height_dst; i++ ) {
        printf("\n");
        for ( j = 0; j < width_dst; j++ ) {
            printf("%3d ",ptmp[j]);
        }
        ptmp = (Ipp8u *)( (char *)ptmp + step_dst1 );
    }
    printf("\n Dst2 =");
    for ( i = 0, ptmp = dst2; i < height_dst; i++ ) {
        printf("\n");
        for ( j = 0; j < width_dst; j++ ) {
            printf("%3d ",ptmp[j]);
        }
        ptmp = (Ipp8u *)( (char *)ptmp + step_dst2 );
    }
    printf("\n Dst3 =");
    for ( i = 0, ptmp = dst3; i < height_dst; i++ ) {
        printf("\n");
        for ( j = 0; j < width_dst; j++ ) {
            printf("%3d ",ptmp[j]);
        }
        ptmp = (Ipp8u *)( (char *)ptmp + step_dst3 );
    }

    ippiFree(dst3); 
    ippiFree(dst2); 
    ippiFree(dst1); 
    ippsFree(src); 
    return 0;
}

Submit feedback on this help topic

Copyright © 2000 - 2010, Intel Corporation. All rights reserved.