I want to use an image filter, which should replace the pixel it's dealing with with the highest occurence of the neighbors.
For example if the pixel has the value 10, and the 8 neighbors have 9, 9, 9, 27, 27, 200, 200, 210, then it should pick 9, because 9 has the highest occurence in the neighborhood. It also should consider the pixel itself, too. So for example if the pixel has the value 27 and the 8 neighbors have 27, 27, 30, 30, 34, 70, 120, 120 then it should pick 27, because 27 is there 3 times, including the pixel itself.
I also should have the option to choose the size of the kernel.
I didn't find a filter like that. Is there one? Or do i have to create it on my own? I use opencv with python.
Background information:
I can't just use Median filter, because my images are different. I have gray images with 3 to 6 different gray values. Therfore i can't use some morphological transformations. I don't get the result i want. The median filter would pick the median value, because the idea is that the values represent the image in the right way. But my images are the result of kmeans and the 3-6 different gray values don't have a logical connection.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…