A python script to extract the original pixel art from a PNG image, even if the pixel art has been scaled, translated, or rotated.
positional arguments:
source_image filepath to the source image
options:
-h, --help show this help message and exit
-b, --border add a white border to the image
-s SCALE, --scale SCALE
value to scale the final image up by
-w WIDTH, --width WIDTH
approximate width in actual source image pixels (you may use decimals) of a
'pixel' of your desired target image
- Install Python 3
- Make sure to add Python to PATH during installation
- Install all the required packages using PIP
pip install opencv-python numpy matplotlib
- Download pixel_art_extractor.py to a new folder
- Open a terminal in the folder you have downloaded pixel_art_extractor.py to
- In Windows, you can do this by opening file explorer and shift-right-clicking on the new folder you have just created, then clicking 'Open in Powershell'
- In the command window, type the following command and press enter to check everything is working
python pixel_art_extractor.py -h- You should see a few lines of help text
- Enter the following command followed by a space and then the file path of the PNG source image
python pixel_art_extractor.py- For example:
python pixel_art_extractor.py C:\Path\To\File\picture.png
- If you have spaces in the filepath, you will need to add single quotes to the filepath argument:
python pixel_art_extractor.py 'C:\Folder With Spaces\picture.png'
- A window of the source image will pop up, and you will be prompted to enter a pixel width value into the command line.
- Some more windows will then pop up, showing you a debug view of the image, as well as the final pixelised image.
- A new file should now be created called
pixel_art_output.pngin the same folder aspixel_art_extractor.py- WARNING: every time you run the script, it will overwrite
pixel_art_output.png. If you want to keep the output, rename it and/or move it somewhere else
- WARNING: every time you run the script, it will overwrite
- You can also use any combination of the following optional parameters:
python pixel_art_extractor.py -b C:\Path\To\File\picture.pngif you would like the output to have a 1px wide borderpython pixel_art_extractor.py -s 5 C:\Path\To\File\picture.pngif you would like the output to be scaled up by a factor of 5 (this works for any positive integer)python pixel_art_extractor.py -w 10 C:\Path\To\File\picture.pngif you would like to automatically pass a pixel width of 10 instead of being prompted for it each timepython pixel_art_extractor.py -o C:\Path\To\Output\pixel_art.png C:\Path\To\File\picture.pngif you would like to save the output to a custom filepath--scaleand--widthmust be positive values--outputmust point to an existing directory- if a source image cannot be read, the script now exits with a clear CLI error
Source image:
Hough line detection and pixel detection:
Output image (transparent, and with nice 1px border, then scaled up):


