intelliproject logo

Location: Computer science - Image processing    License: The Intelliproject Open License (IPOL)

Image Processing - Convolution Filters with c++ and GDI+

Posted by Silviu Caragea

A brief description of several useful convolution filters which allows you to apply various effects on photos for certain features.

Skill: Advanced

Posted: 29/10/2008

Views: 965

Rating: 5.00 /5

Popularity: 0.00

Sign Up to vote for this article

Introduction

Image Convolution filters allows you to apply various effects on photos for certain features.

In essential a convolution filter it’s just a matrix. For every pixel of the image you take the sum of products. Each product is the color value of the current pixel or a neighbor of it, with the corresponding value of the filter matrix. The sum of the products is divided by a factor, and optionally is added an offset value.

Usually the factor is the sum of all values in the matrix filter, which ensures the end value will be in the range 0-255. 

There are numerous types of matrix filters: smoothing, Gaussian blur, edge detection, etc. The main issue in matrix convolution is that it requires a biggest number of computations. To avoid this issue you can reduce the size of the filter. Most of the time small filters 3x3 can do the job perfectly.

main.jpg

Using the source code

You can use the following class to apply 6 different convolution filters described hereinafter.

The following function applies a specified convolution filter to an image buffer bytes. The image should be in RGB24 pixel format.

BYTE * pBuff – image buffer
int nWidth – image width
int nHeight – image height
UINT filter – convolution filter identifier as follow:

  • GAUSSIAN_BLUR
  • SHARPEN
  • MEAN_REMOVAL
  • EMBOSSING
  • EDGE_DETECTION
  • SMOTH

The following method converts a RGB image to gray scale.

BYTE *picData – image buffer
int nWidth  – image width
int nHeight – image height
int nBitCount – number of bits per pixel

The following function applies a color subtraction filter to a specified image.

BYTE *picSrc – image buffer
int width – image width
int height – image height
int bpp – bytes per pixel

Smoothing

This effect is applied in order to reduce noise and/or to prepare images for further processing such as segmentation. The output image is based on a local averaging of the input filter where all of the values within the filter support have the same weight.

smoothing.jpg

Gaussian Blur

Gaussian blur, it is a widely used effect in graphics software, typically to reduce image noise and reduce detail. A Gaussian Blur is distinct from other blurs in that it has a well defined effect on different levels of detail within an image. As the level of detail becomes smaller the filter lets through less and less. With other types of blur (e.g. Mean Filter) the amount let through may vary considerably.

gaussianblur.jpg

Sharpen

Sharpening filters are used to enhance the edges of objects and adjust the contrast and the shade characteristics. In combination with threshold they can be used as edge detectors. Sharpening or high-pass filters let high frequencies pass and reduce the lower frequencies and are extremely sensitive to shut noise.

sharpen.jpg

Mean Removal

This filter sharpens the image by changing the colors of neighboring pixels with approximately the same color, so that small differences are evened out.

mean_removal.jpg

Embossing

The Emboss filter makes a selection appear raised or stamped by suppressing the color within the selection and tracing its edges with black.

embossing.jpg

Edge Detection

Edge detection is a terminology in image processing and computer vision, particularly in the areas of feature detection and feature extraction, to refer to algorithms which aim at identifying points in a digital image at which the image brightness changes sharply or more formally has discontinuities.

edge_detection.jpg

Update history

02/11/2008 Image size limitation was removed
Few minor bugs fixed

License

This article, along with any associated source code and files, is licensed under The Intelliproject Open License (IPOL)

About the author

Silviu Caragea

Silviu Caragea is the Founder, Administrator and Chief Editor who wrote and runs The IntelliProject.

He's been programming since 2000 and now he's student at The Faculty of Economic Cybernetics, Statistics and Informatics from Bucharest. In the same time he's working as software developer at Cratima Software, a Romanian software and web design company that activates both on the local and foreign market, providing its customers with software development services, internet and intranet solutions, web design, graphic design and IT consultancy.

His programming experience includes:
- C,C++, Visual C++(Win32 API, MFC, ADO, STL, DAO, ODBC, ATL, COM, DirectShow, DirectDraw, WTL)
- Open Source libraries :CURL & Boost
- HTML, CSS
- Java (SE,ME)
- JavaScript, Ajax, Google Web Toolkit (GWT)
- Php, MySQL
-Oracle, PL SQL
- C# .NET
-Objective C, IPhone SDK, Cocoa

Location: Romania
Ocupation: Software Engineer
Home page: http://www.intelliproject.net

Posted by Yanmai Her at 19/02/2010 00:43
very nice codes. thank you.

Sign up to post message on the article message board!