ImageGear for C and C++ on Windows v19.6 - Updated
IG_IP_unsharp_mask
API Reference Guide > Core Component API Reference > Core Component Functions Reference > Image Processing Functions > IG_IP_unsharp_mask

Unsharp masking filter is used for image sharpening and edge enhancement.

Declaration:

 
Copy Code
AT_ERRCOUNT ACCUAPI IG_IP_unsharp_mask (
        HIGEAR hIGear, 
        const LPAT_RECT lpRect, 
        const double dblRadius, 
        const UINT nAmount, 
        const UINT nThreshold, 
        const AT_MODE nColorChannel );

Arguments:

Name Type Description
hIGear HIGEAR HIGEAR handle of image.
lpRect const LPAT_RECT Far pointer to AT_RECT struct specifying a portion of the image to be affected. NULL means entire image. Before ImageGear performs this operation, it will check to see if internal flag has been set to TRUE to make a mask active for this HIGEAR image. If a mask is active, and a valid pointer to a mask can be found, ImageGear will override the settings passed to this structure in favor of the non-rectangular ROI defined by the mask.
dblRadius const double Defines the neighborhood to be considered for each pixel.
nAmount const UINT Amount of sharpening, in percents.
nThreshold const UINT Minimal difference between a pixel and its neighbors at which the pixel will be modified.
nColorChannel const AT_MODE Color channel to which the transform shall be applied.

Return Value:

Returns the number of ImageGear errors that occurred during this function call.

Supported Raster Image Formats:

All pixel formats supported by ImageGear for C and C++, except:
Indexed RGB with non-grayscale palette.

Sample:

Image Processing

Example:

 
Copy Code
HIGEAR hIGear; 
/* Sharpen whole image, radius = 2.0, amount = 150, threshold = 10 */
nErrCount =IG_IP_unsharp_mask ( hIGear, NULL, 2.0, 150, 10, IG_COLOR_CHANNEL_ALL ); 

Remarks:

The algorithm works by subtracting a smoothed version of the image ("unsharp") from the original image.

Parameter dblRadius can range from 0.1 to 500. Typical values for high-resolution images range from 1.0 to 2.0. Use larger values of dblRadius for thicker edges. The smaller dblRadius value is, the faster is this processing .

Parameter nAmount can range from 1 to 500. Typical values for photographic images range from 100 to 200. Use bigger values for greater edge contrast.

Parameter nThreshold can range from 1 to 500. Typical values for photographic images are between 0 and 20. Use nThreshold to apply sharpening only to those areas where contrast changes significantly. Flat areas will remain unchanged. A proper selection of nThreshold allows you to enhance edges on the image while leaving insufficient details, such as noise or grain of the photographic film, unchanged.

Parameter nColorChannel specifies the channel to which the transform shall be applied. The default value is IG_COLOR_COMP_ALL: apply transform to all color channels of the image. To run UnsharpMask process on the Intensity channel of the image, convert the image to YUV colorspace, run UnsharpMask filter with nColorChannel = IG_COLOR_COMP_YUV_Y, and convert back to original colorspace.

This function, like other ImageGear Image Processing and Clipboard API calls, takes AT_RECT structure as an argument, so that you can process a rectangular sub-region of an image. However, before ImageGear performs the operation specified by this function, it will check to see if an internal flag has been set to TRUE, indicating that a mask HIGEAR should be used with the image. If the flag is set to TRUE, and a valid pointer to a mask image has been assigned, ImageGear will override the settings passed to the AT_RECT structure and use the non-rectangular ROI defined by the mask HIGEAR. To create a non-rectangular region of interest, call IG_IP_NR_ROI_to_HIGEAR_mask().