Skip to main content

See one face up close and another from far away!

Project description

Hybrid Face

See one face up close and another from far away!

Description

banner

Take any two faces and combine them into a so-called 'hybrid face'. That is, this tool will create an image that looks like the first face from nearby and like the seconds face from far away!

How does it work?

The core concept comes from research conducted by A. Oliva et al. that utilised the multiscale processing of images by the human visual system to generate static images with two interpretations.

This tool is an application of the above to faces. This is (roughly) how it works:

  1. First we need to understand the concept of the Fourier Transform applied to images.

    1.1 Simple (but not easy) explanation: We interpret an image as a tempered distribution obtained as the sum of delta distributions shifted by pixel location and multiplied by greyscale value. The Fourier transform of that image is then simply the Fourier transform of the aforementioned distribution. Well, technical the periodically extension of it.

    1.2 Easy (but not simple) explanation: The Fourier transform of a sound sample gives you the audio frequencies contained in that sample. Similarly, the Fourier transform of an image give you the spatial frequencies that make up that image. A spatial frequency can be interpreted as a periodic wave (i.e. sinusoidal) pattern such that adding up all these waves returns back the (greyscale) image. In particular, high spatial frequencies correspond to rapidly oscillating waves and low spatial frequencies are slowly oscillating waves.

  2. It is a curious observation that the human visual system is able to prioritize information coming from particular spatial frequency bands for object or scene recognition. This is precisely what we use in this application. We utilise that fact that from up close, we prioritize high spatial frequencies for object recognition and from further away, we prioritize lower spatial frequencies. Read here for more details.

  3. Finally, with all the above, this tool's functionality can be simply described as: We take the two images, crop them to only have the faces, then in one face we only keep the high spatial frequencies (via convolution with a high-pass filter) and in the other we only keep the low spatial frequencies (via convolution with a low-pass filter) and then we alpha-blend the two faces together.

How do I use it?

Installation

Simply install via pip pip install hybrid-face.

Should you have trouble with the dlib dependency during installation, simply run pip install cmake dlib.

Using the CLI

After installing the tool, you can use the hybrid-face command line interface to create your own hybrid faces

usage: hybrid-face [-h] [--version] -n NEAR_IMAGE -f FAR_IMAGE [--emphasis {near,far,balanced}] [-o OUTPUT] [-s]

Command-line tool for creating hybrid images

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -n NEAR_IMAGE, --near NEAR_IMAGE
                        Path to the image that should be seen from anear
  -f FAR_IMAGE, --far FAR_IMAGE
                        Path to the image that should be seen from afar
  --emphasis {near,far,balanced}
                        Choose whether the near or far image should be emphasized
  -o OUTPUT, --output OUTPUT
                        Output file for the resulting image (e.g. "result.png")
  -s, --show            Set this flag if you want to display the image (and not necessarily save it)

That is, if you have an image gauss.png and fourier.png and you want to display the hybrid image, you simply run hybrid-face --near gauss.png --far fourier.png --show.

cli-demo

Setting up the project

Navigate into your fork and do the remaining setup.

# Setup a python virtual environment:
python3.8 -m venv venv

# update pip
pip install --upgrade pip

# ... and activate it.
. venv/bin/activate

This project uses pre-commits, so please make sure to install them:

# install pre-commit in your venv
pip install pre-commit

# set up pre-commits
pre-commit install

# It is a good idea to update the hooks to the latest version
pre-commit autoupdate

# Run before committing to check all files
pre-commit run --all-files

Note: pre-commit hooks run on git commits and if they fix or make you fix some file, then you'll have to commit again.

pre-commit: http://pre-commit.com/

Installing dependencies

Dependencies are categorized and managed using setup.cfg.

# install default dependencies
pip install -e .

# to further install testing dependencies run
pip install -e .[testing]

# to further install dev dependencies like pre-commit, black, flake8 run
pip install -e .[dev]

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

hybrid_face-0.1.3.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

hybrid_face-0.1.3-py2.py3-none-any.whl (10.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file hybrid_face-0.1.3.tar.gz.

File metadata

  • Download URL: hybrid_face-0.1.3.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for hybrid_face-0.1.3.tar.gz
Algorithm Hash digest
SHA256 370e4a1bb41c1b05991991de577f43cb4b6621863139ec39bfdaf5fe45452f8b
MD5 23dcb96b5d7713fac8a55738288d2a8d
BLAKE2b-256 bbf2ca376f159aa19d8311c4845082720a4dc61ece93179cabea69712e19d7ab

See more details on using hashes here.

File details

Details for the file hybrid_face-0.1.3-py2.py3-none-any.whl.

File metadata

  • Download URL: hybrid_face-0.1.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for hybrid_face-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 95702f3f0c4209f197072f998ba27e5cea003c5fc0d8a29893a634957d01d5d0
MD5 7bdef5b2dc9886d190f7728ad4589cb5
BLAKE2b-256 54a8ca2b4e30ee4870bd680b847e0f81f75ee201be885fc3b5364d710701675b

See more details on using hashes here.

Supported by

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