All Projects → LeviBorodenko → Primify

LeviBorodenko / Primify

Licence: mit
Embed any image into a prime number.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Primify

Imagegonord
A tool that can convert your rgb images to nordtheme palette
Stars: ✭ 105 (-60.53%)
Mutual labels:  image-processing, pillow
Colorgram.py
A Python module for extracting colors from images. Get a palette of any picture!
Stars: ✭ 289 (+8.65%)
Mutual labels:  image-processing, pillow
Pyemd
Fast EMD for Python: a wrapper for Pele and Werman's C++ implementation of the Earth Mover's Distance metric
Stars: ✭ 361 (+35.71%)
Mutual labels:  mathematics, image-processing
Pillow
The friendly PIL fork (Python Imaging Library)
Stars: ✭ 9,241 (+3374.06%)
Mutual labels:  image-processing, pillow
Optimize Images
A command-line interface (CLI) utility written in pure Python to help you reduce the file size of images.
Stars: ✭ 141 (-46.99%)
Mutual labels:  image-processing, pillow
Poisson blend
Seamless copy-and-paste of images with Poisson Blending.
Stars: ✭ 277 (+4.14%)
Mutual labels:  mathematics, image-processing
Teaching
Teaching Materials for Dr. Waleed A. Yousef
Stars: ✭ 435 (+63.53%)
Mutual labels:  mathematics, image-processing
tweedle
Generator and supporting evidence for security of the Tweedledum/Tweedledee pair of elliptic curves suitable for Halo
Stars: ✭ 16 (-93.98%)
Mutual labels:  mathematics
Photoflare
Quick, simple but powerful Cross Platform image editor.
Stars: ✭ 260 (-2.26%)
Mutual labels:  image-processing
calcanim
Este es un repositorio donde encontrarás todos los códigos usados para generar las animaciones de la lista de reproducción Calcanim en el canal de YouTube Animathica.
Stars: ✭ 16 (-93.98%)
Mutual labels:  mathematics
euler-fluid-cpp
Euler fluid simulated with CPP and SFML
Stars: ✭ 50 (-81.2%)
Mutual labels:  mathematics
fundamental
Software to look for interrelationships between constants and find formulas for number sequences
Stars: ✭ 14 (-94.74%)
Mutual labels:  mathematics
High Quality Ellipse Detection
A high-quality ellipse detector based on arc-support line segments which can both accurately and efficiently detect ellipses in images.
Stars: ✭ 261 (-1.88%)
Mutual labels:  image-processing
c64-pixel-tools
Some tools to process C64 sprites and tilesets
Stars: ✭ 19 (-92.86%)
Mutual labels:  pillow
Otb
Github mirror of https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb
Stars: ✭ 265 (-0.38%)
Mutual labels:  image-processing
Probability Theory
A quick introduction to all most important concepts of Probability Theory, only freshman level of mathematics needed as prerequisite.
Stars: ✭ 25 (-90.6%)
Mutual labels:  mathematics
Cmathtuts
trying to collect all useful tutorials for famous C math and linear algebra libraries such as CBLAS, CLAPACK, GSL...
Stars: ✭ 266 (+0%)
Mutual labels:  mathematics
Shadesketch
Implementation of "Learning to Shadow Hand-drawn Sketches" CVPR 2020 (Oral)
Stars: ✭ 263 (-1.13%)
Mutual labels:  image-processing
Rawpy
📷 RAW image processing for Python, a wrapper for libraw
Stars: ✭ 256 (-3.76%)
Mutual labels:  image-processing
Noaa Apt
NOAA APT weather satellite image decoder, for Linux, Windows, RPi 2+ and OSX
Stars: ✭ 257 (-3.38%)
Mutual labels:  image-processing

Primify

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

result Build Status

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.

Note: There are multiple different methods for quantising the color levels and some methods will produces better results for some images. Make sure to play around with the --method parameter to get the best result.

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

  2. 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.primify_base or use cli.py as a command-line script.

Requirements

Make sure you meet all the dependencies inside the requirements.txt. I would recommend to use pypy, as it seems to decrease compiling time by about 20%.

Command-line tool

usage: primify [-h] [--image IMAGE_PATH] [--max_digits MAX_DIGITS]
                  [--method {0,1,2}] [--output_dir OUTPUT_DIR]
                  [--output_file OUTPUT_FILE] [-v]

Command-line tool for converting images to primes

optional arguments:
  -h, --help            show this help message and exit
  --image IMAGE_PATH    Source image to be converted.
  --max_digits MAX_DIGITS
                        Maximal number of digits the prime can have.
  --method {0,1,2}      Method for converting image. Tweak 'till happy
  --output_dir OUTPUT_DIR
                        Directory of the output text file
  --output_file OUTPUT_FILE
                        File name of the text file containing the prime.
  -v                    Verbose output (Recommended!)

Thus, if you have the source image at ./source.png and you want to convert it into a prime contained in ./prime/prime.txt which has at most 5000 digits and using conversion method 0 (other options are 1 or 2). Then you should run:

primify -v --image ./source.png --max_digits 5000 --method 0 --output_dir ./prime/ --output_file prime.txt

Importing the PrimeImage class

You can also simply import the PrimeImage class from primify.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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].