Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy the center pixel value to the majority value in the block

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

like image 863
Lisa Mathew Avatar asked Dec 06 '22 11:12

Lisa Mathew


1 Answers

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

enter image description here

Now try your filter and you can see the corners are rounded:

convert test.png -statistic mode 10x10 result.png

enter image description here

Now try again with a bigger "radius":

convert test.png -statistic mode 20x20 result.png

enter image description here

Maybe you can experiment with that and see if it does what you want before anyone wastes too much time coding anything.

like image 97
Mark Setchell Avatar answered Jan 04 '23 22:01

Mark Setchell