Function:ImageFilter

From CUVI Wiki
Revision as of 12:42, 26 April 2012 by Jawad (talk | contribs)

Linear filters are an important part of Image Processing Applications. CUVI provides a single generic filter function to apply any filter of any size to an image. We have in-build flags for various famous filters and programmer can input his custom filter elements as well.

Function

CuviStatus imageFilter(CuviImage* srcImage,
                       CuviImage* dstImage,
                       CuviROI roi,
                       CuviFilter* filter,
                       CuviStream* stream = NULL);

Parameters

Name Type Description
srcImage CuviImage* Input Image
dstImage CuviImage* Output Image
roi CuviROI Region of Interest
filter CuviFilter* This structure contains filter parameters including dimensions of the filter kernel, coefficients and anchor position
stream CuviStream* GPU stream ID for execution

Image Type Support

Input Output
8uC1 8uC1
8uC3 8uC3
16uC1 16uC1
16uC3 16uC3
32fC1 32fC1
32fC3 32fC3
8uC1 32fC1
8uC3 32fC3
16uC1 32fC1
16uC3 32fC3


Anchor Position

For creating custom square or rectangular filter kernel, you need to specify the taps as 1D row-major 32bit floating-point array. By default, the center of the 2D filter kernelis placed on the image pixel that corresponds to the current output location. This is known as the filter kernel anchor and it’s position is given by a 2D point. For a 3x3 filter kernel, the default anchor position is -1,-1 which corresponds to the center of the filter kernel, -2,-2 for 5x5 filter and so on. You can change this to another location within the filter kernel through the anchorPositionargument of the imFilter function. Here’s how you create a custom filter kernel and populate it with taps:

Anchor.png

Sample

Input
Average 5x5
Gaussian 5x5 with sigma=0.35
Unsharp with alpha=0.2
Input
X Derivative
Y Derivative


Example

//Input image
CuviImage* gimg = new CuviImage(cuviSize(img->width,img->height),img->depth,img->nChannels);
gimg->upload(img->imageData,img->widthStep);

//Output Image
CuviImage* gout = new CuviImage(cuviSize(img->width,img->height),img->depth,img->nChannels);

//Choosing ROI
CuviROI roi = cuviROI(0,0,img->width,img->height);

//Creating a 5x5 Averaging Filter. User can also enter custom coefficients 
CuviFilter* f;
cuviCreateFilter(&f,5,5);
cuviCreateFilterSpecial(f,CUVI_FILTER_AVERAGE);

//Applying filter 'f' on the image
cuvi::imageFiltering::imFilter(gimg,gout,roi,f);