Skip to content

dan-giddins/pixel-art-extractor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pixel Art Extractor

Description

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

Installation and Usage

  1. Install Python 3
    • Make sure to add Python to PATH during installation
  2. Install all the required packages using PIP
    • pip install opencv-python numpy matplotlib
  3. Download pixel_art_extractor.py to a new folder
  4. 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'
  5. 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
  6. 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'
  7. A window of the source image will pop up, and you will be prompted to enter a pixel width value into the command line.
  8. Some more windows will then pop up, showing you a debug view of the image, as well as the final pixelised image.
  9. A new file should now be created called pixel_art_output.png in the same folder as pixel_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
  10. You can also use any combination of the following optional parameters:
    • python pixel_art_extractor.py -b C:\Path\To\File\picture.png if you would like the output to have a 1px wide border
    • python pixel_art_extractor.py -s 5 C:\Path\To\File\picture.png if 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.png if you would like to automatically pass a pixel width of 10 instead of being prompted for it each time
    • python pixel_art_extractor.py -o C:\Path\To\Output\pixel_art.png C:\Path\To\File\picture.png if you would like to save the output to a custom filepath
    • --scale and --width must be positive values
    • --output must point to an existing directory
    • if a source image cannot be read, the script now exits with a clear CLI error

Example

Source image:

Hough line detection and pixel detection:

Output image (transparent, and with nice 1px border, then scaled up):

About

Python script to extract the original pixel art from an image.

Resources

License

Stars

Watchers

Forks

Contributors

Languages