Skip to main content

tinyfilter

Screenshot 2023-08-05 at 4 52 21 PM

link to PyPi link to license link to license

tinyfilter 1 is the computer vision equivalent to Andrej Karpathy's micrograd. It converts images into ASCII art using the principles of CNNs (convolutional neural networks).

Unlike other tools of its type, which map pixel darkness to an ASCII character, tinyfilter uses filters and convolution to detect features in an image and prints ASCII characters that correspond to them. This leads to much better results compared to other libraries, especially for smaller images.

Installation

To install tinyfilter locally run the command below. When installing python packages such as tinyfilter, I recommend using a virtual environment, but this is optional.

pip install tinyfilter

How to use tinyfilter

To print an image as ASCII characters using tinyfilter run the following command in your terminal. (Replace "image.png" with the name of your image.)

 tinyfilter image.png

You can also import tinyfilter inside a python file or interpreter to do the same thing:

from tinyfilter import tiny_print
tiny_print('image.png')

NOTE: You do not need to specify how many columns wide you want your image to be. tinyfilter automatically prints the image with the exact amount of columns wide your terminal window was at the time the function was called.

Why tinyfilter wins

Screenshot 2023-08-05 at 7 53 28 PM

While other python packages have features that tinyfilter doesn't yet support, tinyfilter clearly does win at one thing: recognizing the important features in an image and focusing on those. In the example above tinyfilter and Ascii-magic bother print images that are 80 columns wide. The difference is that tinyfilter's output is based on where there are edges in the image while Ascii-magic only focuses on where the image is dark and where is it bright.

Examples of tinyfilter

Screenshot 2023-08-05 at 9 53 08 PM

The numbers at the top of the images show how many columns the output is in ASCII characters. The example shows how despite losing large amounts of detail as the image gets smaller, tinyfilter is able to retain important elements of the original.

Balloon dog (110 columns):

Screenshot 2023-08-05 at 10 02 38 PM

The balloon dog is a good example of edge detection (notice tinyfilter doesn't print anything when the balloon is solid purple but prints a line when the image transfers to white).

Einstein (271 columns):

Screenshot 2023-08-05 at 10 14 57 PM

The Einstein image is a good example of how tinyfilter can scale to large images.

How tinyfilter works (it's simpler than you think)

To make sense of the terms in this section you will need a little background on CNNs (convolutional neural networks). The design of tinyfilter is based on the technique these networks use called convolution. Reading the first half of this source from IBM should get you up to speed.

The most important part of an image is the lines. Thats what tinyfilter detects using only 5 filters which I hard coded as numpy arrays (shown below). When the filters are applied to an image, tinyfiler calculates if the feature the filter is detecting for is present. If it is, tinyfilter prints the ASCII character that corresponds to the feature.

BACKSLASH_FILTER = np.array([[3, -1, -1], [-1, 3, -1], [-1, -1, 3]], dtype="int32")
FORWARDSLASH_FILTER = np.array([[-1, -1, 3], [-1, 3, -1], [3, -1, -1]], dtype="int32")
VERTICAL_BAR_FILTER = np.array([[-1, 3, -1], [-1, 3, -1], [-1, 3, -1]], dtype="int32")
HYPEN_FILTER = np.array([[-1, -1, -1], [3, 4, 3], [-1, -1, -1]], dtype="int32")
UNDERSCORE_FILTER = np.array([[-1, -1, -1], [-1, -1, -1], [3, 4, 3]], dtype="int32")

Resources and sources

For more information about resources and their licenses, visit THANKS.txt under this repository.

  • Pillow is a dependency for tinyfilter
  • numpy is a dependency for tinyfilter
  • mypy was used for type checking
  • Black was used for python code formatting
  • This MIT lecture is a great resource for learning about CNNs and filters. I learned a lot from it and this project would not have been possible without it.
  1. For consistency, the first letter in "tinyfilter" is always lowercase, even when it begins a sentence. ↩

Metadata

Release files for tinyfilter 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tinyfilter 1.0.2
File Size Uploaded
tinyfilter-1.0.2.tar.gz 9.9 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for tinyfilter 1.0.2
File Interpreter ABI Platform
tinyfilter-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.9 MB

Release files / tinyfilter-1.0.2.tar.gz

Download URL tinyfilter-1.0.2.tar.gz
Size 9.9 MB
Tags Source
SHA-256 checksum
How to use checksums
0db45894d7af876d7fd667f14c1536fda6d1e79393c16c7fa0ce38dc9784e312
BLAKE2b-256 checksum
How to use checksums
c6dfc09a8e989edeaec156b18f6df018460c71aeac28eb12b8836cd3cf52eb99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.1

Release files / tinyfilter-1.0.2-py3-none-any.whl

Download URL tinyfilter-1.0.2-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2684577b86c53325e7f59883fb071ca25eee9f147c5f17b6c9c4397cabd2d75b
BLAKE2b-256 checksum
How to use checksums
947fcbe4aac1ffec60299f1a63a3bac5cd2421160f06d34148e69fd88d4a37db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.1

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page