I have a image pixel prediction array that is of size 9085x10852. I want to get a 10x10 block around each pixel. if the center pixel value is different from the majority pixel values in the block, then replace the center pixel value with the majority value. Can anyone help me please
As you seem a little unsure/inconsistent about the details of your question, I would like to suggest a very simple, alternative solution, not in Python but too big for a comment, that helps you and others explore whether you really want this and what you actually want - before anyone spends hours coding Python.
I suggest you use ImageMagick which is installed on most Linux distros and is available for macOS and Windows. So, just in Terminal, you can make a sample image which is black with a white square in the middle, like this:
convert -size 100x100 xc:black -fill white -draw "rectangle 10,10 90,90" test.png
Now try your filter and you can see the corners are rounded:
convert test.png -statistic mode 10x10 result.png
Now try again with a bigger "radius":
convert test.png -statistic mode 20x20 result.png
Maybe you can experiment with that and see if it does what you want before anyone wastes too much time coding anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With