Skip to content

Files

Latest commit

 Cannot retrieve latest commit at this time.

History

History
71 lines (58 loc) · 3.37 KB

README.md

File metadata and controls

71 lines (58 loc) · 3.37 KB

Dithered Image

Bayer Dithering

Python

This Python script applies a Bayer matrix dithering to images, gifs or videos. It offers a variety of customizable options such as matrix size, filters, sharpness, contrast, and downscaling. It also supports multi-threading for faster processing.

Features

  • Dithering for images and videos: Applies Bayer matrix dithering to PNG, JPG, GIF, and MP4 files.
  • Customizable filters: Configurable through the filters.toml file.
  • Multi-threading Support: Process large files faster with parallel processing.
  • Support for downscaling and sharpening: Image manipulation options before dithering.

Installation

  1. Clone the repository:
git clone https://github.com/madmattp/Bayer-Dithering.git
  1. Install dependencies:
pip install -r requirements.txt

Usage:

Command Line Options:

  • -i, --input: Specifies the input file (image or video) to apply dithering to.
  • -m, --matrix: Selects the Bayer matrix size. Options: 2x2, 4x4, 8x8 (default: 4x4).
  • -o, --output: Specifies the output file path. A default name will be used if not provided.
  • -f, --filter: Applies a color filter to the output image.
  • -s, --sharpness: Adjusts the sharpness (default: 1.6).
  • -c, --contrast: Adjusts the contrast (default: 1.5).
  • -d, --downscale: Downscales the image by a factor before dithering (default: 2).
  • -u, --upscale: Upscales the image back to its original size after dithering (default: True). Set -u False to disable.
  • -t, --threads: Specifies the number of threads for processing (default: 1).

⚠️ Note: When processing videos, the output format must be .avi to ensure compatibility with the rawvideo codec used for lossless output. Other formats (e.g., .mp4) may fail to play correctly in common players due to unsupported encoding profiles.

Recommended Settings

For more visually pleasing results before applying dithering, it is recommended to use the following settings:

  • Contrast: 1.5
  • Sharpness: 1.6
  • Downscaling: >2

Examples:

  1. Dithering an Image with Recommended Settings:
python dither.py -i input_image.png -o output_image.png -m 4x4 -c 1.5 -s 1.6 -d 6

Silly Cat Dithered Image

  1. Dithering a Video with Multiple Threads:
python dither.py -i input_video.mp4 -o output_video.avi -m 4x4 -t 4 -c 1.5 -s 1.6 -d 2

cat_huh.mp4
dithered_video.mp4

Configuration

Fine-tune the dithering effect by adjusting matrix size, sharpness, contrast, and downscaling factors. Use multi-threading for faster video processing.

Contributions

Feel free to open issues or contribute via pull requests. Contributions are welcome!