Top answer in this link How to pixelate a square image to 256 big pixels with python? uses PIL
to pixelate image. Converting image from PIL
to cv2.Mat
is possible but I'm not allowed to use other library, and I couldn't find any good method using opencv.
Is there any way to pixelate image using OpenCV
library only in Python? Any sample image is fine. Solution with pixel size parameter that I can control for later adjustment would be very appreciated.
EDIT^2
With the help of himself, I moved Mark Setchell's answer, which is the above mentioned top answer, to plain
OpenCV
Python code. (Have a look at the revision history of my answer to see the old version using a loop.)Input (from linked question):
Output:
Disclaimer: I'm new to Python in general, and specially to the Python API of OpenCV (C++ for the win). Comments, improvements, highlighting Python no-gos are highly welcome!