Package: hybrid-face
Hybrid FaceSee one face up close and another from far away!DescriptionTake 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 byA. 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:First we need to understand the concept of theFourier Transformapplied to images.1.1 Simple (but not easy) explanation: We interpret an image as atempered distributionobtained as the sum ofdelta distributionsshifted by pixel location and multiplied by greyscale value. The Fourier transform of that image is then simply theFourier transformof the aforementioned distribution. Well, technical theperiodically extensionof 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.It is acurious observationthat 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. Readherefor more details.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?InstallationSimply install via pippip install hybrid-face.Should you have trouble with thedlibdependency during installation, simply runpip install cmake dlib.Using the CLIAfter installing the tool, you can use thehybrid-facecommand line interface to create your own hybrid facesusage: 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 imagegauss.pngandfourier.pngand you want to display the hybrid image, you simply runhybrid-face --near gauss.png --far fourier.png --show.Setting up the projectNavigate into your fork and do the remaining setup.# Setup a python virtual environment:python3.8-mvenvvenv# update pippipinstall--upgradepip# ... and activate it..venv/bin/activateThis project uses pre-commits, so please make sure to install them:# install pre-commit in your venvpipinstallpre-commit# set up pre-commitspre-commitinstall# It is a good idea to update the hooks to the latest versionpre-commitautoupdate# Run before committing to check all filespre-commitrun--all-filesNote: 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 dependenciesDependencies are categorized and managed usingsetup.cfg.# install default dependenciespipinstall-e.# to further install testing dependencies runpipinstall-e.[testing]# to further install dev dependencies like pre-commit, black, flake8 runpipinstall-e.[dev]