This repository contains an implementation of a variation of the Feature-Based Image Metamorphosis algorithm, inspired by the research paper "Feature-Based Image Metamorphosis" by Thaddeus Beier and Shawn Neely (1992). The variation is designed for use with a single image and a set of coupled vectors, enabling creative and unique image transformations.
Feature-based image metamorphosis is a geometric warping technique that uses a set of line pairs (corresponding features) to guide the transformation of an image. The transformation involves two main steps:
- Warping the image based on feature lines.
- Interpolating between source and target images using a blend factor.
Given:
- A source image
$I_s$ . - A target image
$I_t$ . - A set of feature lines in the source image
${(P_i, Q_i)}$ . - Corresponding feature lines in the target image
${(P'_i, Q'_i)}$ . - A blending factor
$t \in [0, 1]$ .
Each pixel
Where:
-
$\text{displacement}_i = \frac{\overrightarrow{X'P'_i} \cdot \overrightarrow{Q'_iP'_i}}{|\overrightarrow{Q'_iP'_i}|^2} \cdot \overrightarrow{Q_iP_i} + \frac{\overrightarrow{X'Q'_i} \cdot \overrightarrow{Q'_iP'_i}}{|\overrightarrow{Q'_iP'_i}|^2} \cdot \overrightarrow{P_iQ_i}$ . -
$\text{weight}_i = \frac{|Q'_iP'_i|^p}{(a + \text{distance}(X', L'_i))^b}$ , where:-
$L'_i$ is the line defined by$P'_i, Q'_i$ . -
$p$ ,$a$ , and$b$ are user-defined constants controlling the smoothness and influence of the transformation.
-
The pixel intensities in the final output image are computed as a linear interpolation between the source and target images:
Where
Refer to the How to Use Notebook for detailed instructions on applying the Feature-Based Image Metamorphosis algorithm with a single image and coupled vectors.
ImageMorphism.py
: Core implementation of the Feature-Based Image Metamorphosis algorithm variation.Line.py
: Definition of a class later needed in the algorithm.How_to_Use.ipynb
: Jupyter Notebook providing a step-by-step guide to using the algorithm.
Ensure you have the following dependencies installed:
- Python 3.x
- Required Python packages (listed in
requirements.txt
).
-
Clone this repository:
git clone https://github.com/achrefbenammar404/FeatureBasedImageMetamorpohosis.git cd FeatureBasedImageMetamorphosis
-
Install the required dependencies:
pip install -r requirements.txt
-
Refer to the
How_to_Use.ipynb
notebook for instructions on using the algorithm.
-
Line Pair Influence: The parameters
$p$ ,$a$ , and$b$ allow fine-tuning of how much each line pair affects the pixels. Increasing$p$ reduces the influence of distant lines, while larger$b$ sharpens the transformation near the line. -
Blending Factor
$t$ : Controls the interpolation between the source and target image. A value of$t = 0$ results in the source image, while$t = 1$ gives the target image.
The algorithm handles smooth warping by adjusting weights dynamically for every pixel. However, the computational complexity grows with the number of feature lines and image resolution.
If you encounter issues or have suggestions, feel free to:
- Open an issue.
- Submit a pull request.
This implementation is inspired by the following paper:
- Thaddeus Beier and Shawn Neely, "Feature-Based Image Metamorphosis", Proceedings of SIGGRAPH '92, ACM, 1992.
The algorithm adapts concepts from the original research to support single images and coupled vector transformations for enhanced creative flexibility.