Function:ImageFilter

From CUVI Wiki
Revision as of 20:34, 18 April 2013 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(const CuviImage& src,
                       CuviImage& dst,
                       const CuviFilter& filter,
                       const CuviStream& stream = CuviStream());

CuviStatus imageFilter(const CuviImage& src,
                       CuviImage& dst,
                       const CuviRect& roi,
                       const CuviFilter& filter,
                       const CuviStream& stream = CuviStream());

Parameters

Name Type Description
src const CuviImage& Input Image
dst CuviImage& Output Image
roi const CuviRect& Region of Interest
filter const CuviFilter& This structure contains filter parameters including dimensions of the filter kernel, coefficients and anchor position
stream const CuviStream& GPU stream ID for execution

Image Type Support

Input Output
8uC1 8uC1
8uC3 8uC3
16uC1 16uC1
16uC3 16uC3
32fC1 32fC1
32fC3 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:

Error creating thumbnail: Unable to save thumbnail to destination

Sample

Error creating thumbnail: Unable to save thumbnail to destination
Input
Error creating thumbnail: Unable to save thumbnail to destination
Average 5x5
Error creating thumbnail: Unable to save thumbnail to destination
Gaussian 5x5 with sigma=0.35
Error creating thumbnail: Unable to save thumbnail to destination
Unsharp with alpha=0.2
Error creating thumbnail: Unable to save thumbnail to destination
Input
Error creating thumbnail: Unable to save thumbnail to destination
X Derivative
Error creating thumbnail: Unable to save thumbnail to destination
Y Derivative


Example

//Input image
CuviImage gimg = cuvi::io::loadImage(path);

//Output image
CuviImage gout;

//Choosing ROI
CuviRect roi(0,0,gimg.width(),gimg.height());

//Creating a 3x3 Averaging Filter. User can also enter custom coefficients 

Cuvi32f coeffs[9] = {
                      1/9.0f, 1/9.0f, 1/9.0f,
                      1/9.0f, 1/9.0f, 1/9.0f,
                      1/9.0f, 1/9.0f, 1/9.0f,
                    };

CuviFilter f(3,3,coeffs);

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