Visible to Intel only — GUID: GUID-663C2697-F60B-4B52-898E-46211C37E279
Visible to Intel only — GUID: GUID-663C2697-F60B-4B52-898E-46211C37E279
Inpaint
MODIFIED API. Restores unknown image pixels.
Syntax
IppStatus ippiInpaint_8u_C1R(const Ipp8u* pSrc, int srcStep, Ipp8u* pDst, int dstStep, IppiSize roiSize, IppiInpaintState_8u_C1R* pState, Ipp8u* pBuffer);
IppStatus ippiInpaint_8u_C3R(const Ipp8u* pSrc, int srcStep, Ipp8u* pDst, int dstStep, IppiSize roiSize, IppiInpaintState_8u_C1R* pState, Ipp8u* pBuffer);
Include Files
ippcv.h
Domain Dependencies
Headers: ippcore.h, ippvm.h, ipps.h, ippi.h
Libraries: ippcore.lib, ippvm.lib, ipps.lib, ippi.lib
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.
- roiSize
- Size of the image ROI in pixels.
- pState
- The pointer to the inpainting structure.
- pBuffer
- Pointer to the work buffer.
Description
Before using this function, compute the size of the state structure and work buffer using InpaintGetSize and initialize the structure using InpaintInit.
This function operates with ROI (see Regions of Interest in Intel IPP).
This function reconstructs damaged part of the image, or removes a selected object (see Figure “Image Inpainting”). The image part to restore is defined by the mask that is created when the inpainting structure pState is initialized by the InpaintInit function. Different distant transforms can be used, but the Fast Marching method (ippiFastMarching) provides the best results. The order of pixel restoration is defined by the distance through the initialization the inpainting structure pState by the InpaintInit function. Pixels are restored in according to the growing of their distance value. When a pixel is inpainted, it is treated as the known one.
Two algorithms of direct inpainting are supported (controlled by the parameter flags of the InpaintInit function):
- image restoration of the unknown pixel by the weighted sum of approximations by known pixels in the neighborhood (flags = IPP_INPAINT_TELEA) [Telea04],
- image restoration based on the Navier-Stokes equations (flags = IPP_INPAINT_NS) [Bert01].
The inpainting structure pState can be used to perform restoration of several different images of the same size roiSize.
Return Values
ippStsNoErr |
Indicates no error. Any other value indicates an error or a warning. |
ippStsNullPtrErr |
Indicates an error when one of the specified pointers is NULL. |
ippStsSizeErr |
Indicates an error when roiSize has a field with zero or negative value, or if differs from the corresponding parameter that is specified when the inpainting structure is initialized by InpaintInit. |
ippStsStepErr |
Indicates an error condition if srcStep or dstStep is less than roiSize.width * < pixelSize>. |
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 restoring damaged image area by direct inpainting
// using Intel(R) Integrated Primitives (Intel(R) IPP) functions:
// ippiFastMarchingGetBufferSize_8u32f_C1R
// ippiFastMarching_8u32f_C1R
// ippiInpaintGetSize
// ippiInpaintInit_8u_C1R
// ippiInpaint_8u_C1R
#include <stdio.h>
#include "ipp.h"
#define WIDTH 128 /* Image width*/
#define HEIGHT 128 /* Image height*/
#define RADIUS 3.f /* Neighborhood radius*/
#define INPAINT_FLAGS IPP_INPAINT_NS /* Specifies algorithm for image inpainting*/
/* 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 = NULL, *pDst = NULL; /* Pointers to source/destination images */
int srcStep = 0, dstStep = 0; /* Steps, in bytes, through the source/destination images */
IppiSize roiSize = { WIDTH, HEIGHT }; /* Size of source/destination ROI in pixels */
Ipp8u *pMask = NULL; /* Pointer to mask image */
int maskStep; /* Step, in bytes, through the mask image */
Ipp32f *pFMDist = NULL; /* Pointer to distances image */
int fmDistStep = 0; /* Step, in bytes, through the distances image */
Ipp8u *pFMBuffer = NULL; /* Pointer to the Fast marching work buffer */
int fmBufferSize = 0;
IppiInpaintState_8u_C1R *pInpState = NULL; /* Pointer to inpainting structure */
Ipp8u *pInpBuffer = NULL; /* Pointer to the Inpaint work buffer */
int inpBufferSize = 0;
Ipp8u *pInpStateBuf = NULL; /* Pointer to the Inpaint structure buffer */
int inpStateSize = 0;
pSrc = ippiMalloc_8u_C1(roiSize.width, roiSize.height, &srcStep);
pDst = ippiMalloc_8u_C1(roiSize.width, roiSize.height, &dstStep);
pMask = ippiMalloc_8u_C1(roiSize.width, roiSize.height, &maskStep);
pFMDist = ippiMalloc_32f_C1(roiSize.width, roiSize.height, &fmDistStep);
/* Compute the temporary work buffer size for Fast Marching */
check_sts( status = ippiFastMarchingGetBufferSize_8u32f_C1R(roiSize, &fmBufferSize) )
pFMBuffer = ippsMalloc_8u(fmBufferSize);
/* Calculate distance by the Fast Marching Method */
check_sts( status = ippiFastMarching_8u32f_C1R(pMask, maskStep, pFMDist, fmDistStep, roiSize, RADIUS, pFMBuffer) )
/* Calculate State and work buffer sizes for Inpaint */
check_sts( status = ippiInpaintGetSize(pMask, maskStep, roiSize, RADIUS, INPAINT_FLAGS, ippC1, &inpStateSize, &inpBufferSize) )
/* Memory allocation for State and work buffer */
pInpStateBuf = ippsMalloc_8u(inpStateSize);
pInpBuffer = ippsMalloc_8u(inpBufferSize);
/* Initialize the Inpaint State for direct methods of image inpainting */
check_sts( status = ippiInpaintInit_8u_C1R(&pInpState, pFMDist, fmDistStep, pMask, maskStep, roiSize, RADIUS, INPAINT_FLAGS, pInpStateBuf, pInpBuffer) )
/* Restores damaged image area by direct inpainting */
check_sts( status = ippiInpaint_8u_C1R(pSrc, srcStep, pDst, dstStep, roiSize, pInpState, pInpBuffer) )
EXIT_MAIN
ippsFree(pFMBuffer);
ippsFree(pFMDist);
ippsFree(pInpBuffer);
ippiFree(pInpStateBuf);
ippiFree(pSrc);
ippiFree(pDst);
ippiFree(pMask);
printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status));
return (int)status;
}