• Stars
    star
    464
  • Rank 93,818 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Embed any image into a prime number.

Primify

Transform any image into a prime number that looks like the image if glanced upon from far away.

result Build Status PyPI

How does it work

We proceed in 5 steps:

  1. We resize the image to contain at most a --max-digits amount of pixels.

  2. Run various image processing steps like edge enhancement and smoothing before converting the image into grey-scale.

  3. We then quantise the image into just having 5 to 10 greyness levels.

  4. Now we map each greyness level to a digit, et voila, we have embedded the picture into a number.

  5. It now remains to tweak some of the digits until we find a prime number that still looks like the image.

Note: According to the prime number theorem, the density of prime numbers is asymptotically of order 1/log(n). Hence, if we have some number n with m digits, the number of primality tests that we expect to do until we hit a prime number is roughly proportional to m. Since we use the Baillie–PSW primality test, the overall expected computational complexity of our prime searching procedure is O(n*log(n)³).

How to use

Simply get the primify command line tool via pip install primify. You can also import the PrimeImage class from primify.base or use cli.py as a command-line script.

Command-line tool

usage: primify [-h] [--image IMAGE_PATH] [--max-digits MAX_DIGITS]
               [--output-file OUTPUT_FILE]

Command-line tool for converting images to primes

optional arguments:
  -h, --help            show this help message and exit
  --image IMAGE_PATH, -i IMAGE_PATH
                        Source image to be converted
  --max-digits MAX_DIGITS, -d MAX_DIGITS
                        Maximal number of digits the prime can have
  --output-file OUTPUT_FILE, -o OUTPUT_FILE
                        File name of the file containing the prime.

Thus, if you have the source image at ./source.png and you want to convert it into a prime contained in ./prime.txt which has at most 5000 digits. Then you should run:

primify --image ./source.png --max-digits 5000 --output-file prime.txt

Importing the PrimeImage class

You can also simply import the PrimeImage class from primify.base and use that class in your own code. Check the documentation for details on how to interact with the underlying API.

Additional Material

Daniel Temkin wrote a lovely article on his blog esoteric.codes giving some interesting insight and background for this tool. You can read it here.

More Repositories

1

spectrographic

Turn an image into sound whose spectrogram looks like the image.
Python
260
star
2

lancer

Turn your python code into a hideous mess. Ever heard of Black? This is the opposite.
Python
255
star
3

Logation

Analyse your NGINX access logs and create beautiful maps of the locations from which people access your service.
Python
115
star
4

motionblur

Generate authentic motion blur kernels (point spread functions) and apply them to images. Fast and Simple.
Python
105
star
5

non-api-fb-scraper

Scrape public FaceBook posts from any group or user into a .csv file without needing to register for any API access
Python
47
star
6

garnn

TensorFlow implementation of Graphical Attention Recurrent Neural Networks based on work by Cirstea et al., 2019.
Python
27
star
7

dgcnn

Clean & Documented TF2 implementation of "An end-to-end deep learning architecture for graph classification" (M. Zhang et al., 2018).
Python
24
star
8

img2rag

Convert any image into a Region Adjacency Graph (RAG)
Python
12
star
9

StackData

Data set containing the key techologies used by ~1000 top tech companies.
8
star
10

rateyourcircle

Draw a circle and see how close you got to drawing a perfect circle.
JavaScript
7
star
11

gtraceroute

gtraceroute is a sophisticated network diagnostic tool, combining the utility of traditional traceroute with a user-friendly UI similar to PingPlotter.
Python
3
star
12

dortmund2array

Tool to convert datasets from "Benchmark Data Sets for Graph Kernels" (K. Kersting et al., 2016) into a format suitable for deep learning research.
Python
2
star
13

RedditLiveChart

The Back- and Frontend behind my popular /r/dataisbeautiful post.
JavaScript
1
star
14

adadelta_py

Clean & dependency-free implementation of the ADADELTA algorithm in python.
Python
1
star
15

hybrid-face

See one face up close and another from far away!
Python
1
star
16

LinAlg-NumberTheory

Just some maths modules for linear algebra and number theory.
Python
1
star