- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Gaussian Filter Generation in C++
As we know the Gaussian Filtering is very much useful applied in the field of image processing. It is used to reduce the noise of an image. In this section we will see how to generate a 2D Gaussian Kernel. Gaussian Distribution for generating 2D kernel is as follows.
$$G(x,y)= \frac{1}{2\Pi\:\sigma^{2}}e^{\frac{x^{2}+y^{2}}{2\sigma^{2}}}$$
Example
Let us see the following implementation to get better understanding −
#include <cmath> #include <iomanip> #include <iostream> #define PI 3.1415 using namespace std; void calc_filter(double kernel[][5]) { double sigma = 1.0; double p, q = 2.0 * sigma * sigma; double sum = 0.0; for (int x = -2; x <= 2; x++) { for (int y = -2; y <= 2; y++) { p = sqrt(x * x + y * y); kernel[x + 2][y + 2] = (exp(-(p * p) / q)) / (PI * q); sum += kernel[x + 2][y + 2]; } } for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) kernel[i][j] /= sum; } int main() { double kernel[5][5]; calc_filter(kernel); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; ++j) cout << kernel[i][j] << " "; cout << endl; } }
Output
0.00296902 0.0133062 0.0219382 0.0133062 0.00296902 0.0133062 0.0596343 0.0983203 0.0596343 0.0133062 0.0219382 0.0983203 0.162103 0.0983203 0.0219382 0.0133062 0.0596343 0.0983203 0.0596343 0.0133062 0.00296902 0.0133062 0.0219382 0.0133062 0.00296902
- Related Articles
- Random number generation in C++
- Gaussian Library Arduino
- Mid-Point Line Generation Algorithm in C++
- Fourier Transform of a Gaussian Signal
- How to implement Gaussian blur in OpenCV using Java?
- Gaussian filtering an image with NaN in Python Matplotlib
- Wait state generation in 8085 Microprocessor
- Generation of time delay in 8085
- Filter array with filter() and includes() in JavaScript
- Blurring an image using the OpenCV function Gaussian Blur()
- C++ Program to Implement Park-Miller Random Number Generation Algorithm
- Pure-bred tall pea plants are first crossed with pure-bred dwarf pea plants. The pea plants obtained in F1 generation are then cross-bred to produce F2 generation of pea plants.(a) What do the plants of F1 generation look like? (b) What is the ratio of tall plants to dwarf plants in F2 generation? (c) Which type of plants were missing in F1 generation but reappeared in F2 generation?
- How to find Gaussian pyramids for an image using OpenCV in Python?
- Filter in Python
- When two parents are crossed, the offspring are referred to as:(a) recessives (b) test cross (c) F1 generation (d) F2 generation

Advertisements