I want to use a kernel that performs a pixel operation based on a conditional expression.
Let's say I have this grayscale image (6x6 resolution):
and I use a 3x3 pixel kernel, how would I change the value of the centre kernel pixel (centre) IF AND ONLY IF the centre pixel is the local minimum or maximum within the 3x3 kernel?
For example, say I wanted to set the centre kernel pixel to the average value of the surrounding 8 pixels, like this:
Is there a way to do this with OpenCV
?
EDIT: another more detailed example GIF - 9 passes implementing my example:
This was produced in Excel using the following formula (not the relative cell references - they show the kernel shape of 3x3 around the focus 'picell':
=IF(OR(C55=MIN(B54:D56),C55=MAX(B54:D56)),(SUM(B54:D56)-C55)/8,C55)
Here is the top left corner of the table with the source values for the first pass (these values control the cell colour):
This table refers to another source table. Each frame in the GIF is the next calculated colour table. There are 3 tables of formulae in between each image frame. Here is more context: