Giter Club home page Giter Club logo

primify's Introduction

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.

primify's People

Contributors

borea17 avatar leviborodenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

primify's Issues

Installation fails step fails due to missing C header

Hardware: 2020 Macbook Pro M1
OS: Big Sur
primify-install-output.txt

The command python3 -m pip install primify fails with the attached output.

It looks like the install script is invoking clang to build some C code, but there is a missing header: gmp.h. I double checked the the gmp lib is installed on my system. I have the header on disk but clang is not being passed the correct include path so it is not found at compile time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.