Image Processing Best Practices — C++ Part 3

Soubhi Hadri
6 min readDec 14, 2020

Since you are here, I suppose that you have gone through Part1 and Part2 of this series and, hopefully, found them beneficial. As I promised in part 2 of this series, here is a new article which will help you prepare for your next Computer Vision/Image Processing coding interview.


This article is a continuation of the first & second. Please go back and check the previous articles out if you have not already, since this article heavily depends on them.

The main two sections of this article are:
1. Implementation for Gaussian blur with support to gray scale and colored images.
2. Find the closest face to the camera.

Gaussian Blur

Gaussian blur filter is one of the smoothing filters. The smoothing effect is the result of blurring the image by convolving the famous Gaussian function.

Smoothing filters are used usually to reduce the noise in the image. The Gaussian blur filter’s size must be positive and odd and the width and height are not required to match.


For simplicity, our implementation of the Gaussian blur filter in this tutorial will deal with:

  1. [0–255] values for the pixels.
  2. Supporting both 1-channel and 3-channel images.
  3. Using data raw pointer provided by cv::Mat .
  4. Filter size is a squared shape.
  5. Boundary pixel values will keep their values (challenge yourself and try to expand the image and apply the filter on boundary pixels as well).

Gaussian Blur Kernel

As mentioned in the previous section, Gaussian Filter works by applying the convolution operation on the image. Gaussian kernel size (width and height) can differ but they both must be positive and odd. Our implementation will support a square kernel only(challenge yourself and support different width and height. easy, right? ^_^ ). Looking back into the Gaussian function, you can notice that in addition to the filter size, we need sigma as a…



Soubhi Hadri

Software Engineer at Microsoft. Former Computer Vision Engineer at Shiseido Group 資生堂. Interested in drones, CV, ML and DL.