Download scripts/pixelfix.py from Cnass/Claude: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/spaces/Cnass/Claude/resolve/main/scripts/pixelfix.py
- Command line
-
hf download hf://spaces/Cnass/Claude/scripts/pixelfix.py
-
curl -L -o pixelfix.py https://huggingface.co/spaces/Cnass/Claude/resolve/main/scripts/pixelfix.py
1.68 kB
| #!/usr/bin/env python3 | |
| """Fake pixel art -> real pixel art (Retro Diffusion pixel-art-fixer, MIT, vendor/pixelfixer). | |
| python3 scripts/pixelfix.py in.png out.png [--mode full|fast] [--step 8] [--colors 0] | |
| Finds the pseudo-pixel grid of an upscaled / AI-generated "pixel art" image and | |
| rebuilds every cell as one true pixel. Prints a JSON line: cols, rows, step_x, | |
| step_y, consensus, confidence, timings. Needs numpy, scipy, opencv, Pillow. | |
| """ | |
| import argparse | |
| import json | |
| import os | |
| import sys | |
| sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'vendor', 'pixelfixer')) | |
| def main(): | |
| ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) | |
| ap.add_argument('input') | |
| ap.add_argument('output') | |
| ap.add_argument('--mode', choices=['full', 'fast'], default='full') | |
| ap.add_argument('--step', type=float, default=None, help='force the cell size in source pixels') | |
| ap.add_argument('--colors', type=int, default=0, help='structure quantisation colours (0 = adaptive)') | |
| args = ap.parse_args() | |
| try: | |
| from pixelfixer.api import process | |
| except ImportError as err: | |
| print(json.dumps({'error': f'pixelfixer needs numpy, scipy, opencv-python-headless and Pillow: {err}'})) | |
| sys.exit(2) | |
| with open(args.input, 'rb') as f: | |
| data = f.read() | |
| try: | |
| result = process(data, mode=args.mode, force_step=args.step, k_colors=args.colors) | |
| except ValueError as err: | |
| print(json.dumps({'error': str(err)})) | |
| sys.exit(1) | |
| with open(args.output, 'wb') as f: | |
| f.write(result.pop('png')) | |
| print(json.dumps(result)) | |
| if __name__ == '__main__': | |
| main() | |