Applying GaussianBlur to individual pixels

I am writing a C ++ application using OpenCV to apply a Gaussian filter to individual pixels in an image. For example, I look at each pixel in the image and, if it corresponds to a certain RGB value, I want to apply the Gaussian algorithm only to these pixels, so that blurring occurs only around those parts of the image.

However, I was having trouble finding a way to do this. The GaussianBlur() function, offered by the OpenCV library, allows me to blur the whole image, and not just apply the algorithm and the kernel to one pixel at a time. Does anyone have any ideas on how I can achieve this (for example, is there another method that I don't know about)? I hope that I don’t need to write the whole algorithm myself to apply it to one pixel.

+4
source share
2 answers

My friend came up with a good solution:

  • clone the original matrix
  • apply GaussianBlur() to the clone
  • compare each pixel with an RGB value
  • if match, replace original pixel with clone pixel

I can’t believe how simple it was.

+3
source

You can encode the Gaussian blur yourself if you need to apply it on only a few pixels. It is much simpler than you think, and takes only a few lines. This is a simple stencil operator using the gaussian function for its kernel. All you need is the coordinates of the pixel and its neighbors.

The rest is straight. Here is an example of a Gaussian matrix that you can easily code or generate using the Gaussian function:

Example of Gaussian blur matrix

In short, this is just a weighted average of neighboring values.

+1
source

All Articles