Skip to main content

No project description provided

Project description

Image Math

What if you could do math on an image?

I was inspired by 3Blue1Brown's video on converting a droste image into an escher-style image by taking its logarithm.

Every point on an image is corresponded with a complex number in the complex plane. Applying a function on every point on an initial image gives a new image.

I was able to recreate Escher's effect and more!


Jump forward to:

  1. Applying your own function
  2. Creating Escher-style images

Some cool effects I got:

Inv-Function 3B1B's image My Droste Image Rings
Original
Click any image
for higher quality
Escher Effect
Rotate
$f(z)=iz$
Zoom to corner
$f(z)=\frac{z+2+2i}{3}$
Kaleidoscope
$f(z)=z^6$
Kaleidoscope
(Try any polynomial :D)
$f(z) = z^3 + 3z^2$
Logarithm
$f(z) = e^z$
Inverse
$f(z) = 1/z$
Weierstrass Elliptical function

Applying your own functions:

  1. Create the inverse of your function. e.g. if $f(x) = e^x$, the inverse function is $g(x) = log(x)$
  2. Create the function in using numpy. e.g.
    def f(z):
        return np.log(x) # i.e. log(x)
    
  3. Add the @image_function decorator.
    @image_function
    def my_image_function(z):
        return np.log(x)
    
  4. Done! Use your function like this:
    my_image_function("input.png", "output.png", zoom = 1.0, output_scale = 1.0)
    
    • zoom: Change this to zoom-in/out the output.
    • output_scale: Output resolution w.r.t input image. Smaller number makes much rendering faster, but loses quality.

Creating an Escher-style Image:

  1. Start with a Droste image.
  2. Find the singularity of the image, (where all the recursive images meet), generally the center of the image. Find the position w.r.t the center of the image [(0,0) = center; (1,1) = top right corner]
  3. Create the escher function:
    scale = 16 #Size of smaller image wrt the larger one.
    center = (0,0) #Center point, (0,0) by default
    subject = (-0.8,-0.8) #Subject of drawing, cannot be center
    esch = escher_function(scale, center,subject)```
    
  4. Create the final image:
    input_filename = "droste.png" # Input filename
    output_filename = "escher.png" # Output
    zoom = 1.8 # Used to zoom-in/out the output image.
    res = 1.0 # Set to a low number (e.g. 0.2) for faster render and testing, but lower output quality. 1.0 is the maximum quality.
    
    esch(input_filename, output_filename, zoom, res)
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

image_math-1.0.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

image_math-1.0.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file image_math-1.0.1.tar.gz.

File metadata

  • Download URL: image_math-1.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for image_math-1.0.1.tar.gz
Algorithm Hash digest
SHA256 68b09f93bb58ce0a7a6db33773bc2cb4e84e88cf40d17a305d254867e0a526b8
MD5 00e632bc8710fb577fe9f1026169f80c
BLAKE2b-256 c0698a92aaf32ff583623d13c640e8cfad5f87d2ebdac6b8b92e1c06d98e2543

See more details on using hashes here.

File details

Details for the file image_math-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: image_math-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for image_math-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b47c35a658999b89710b96ad255bf903ea72622ca3d6b0c0fcbbf4b866d6d12
MD5 29ab22f5abfa5faa8635a2634bcc16c6
BLAKE2b-256 3baba94048105274582ee8c79d14d43ff3169d30ce46b2a254fb036ff5240ebd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page