Compare image similarity using features extracted from the pre-trained VGG16 model. This project leverages cosine similarity for accurate visual similarity assessment, making it ideal for image retrieval and duplicate detection.
MIT License
This project compares the similarity between images using features extracted from the VGG16 pre-trained deep learning model. It uses cosine similarity to compute the similarity scores between feature vectors.
๐ฆimage_similarity
โฃ ๐data
โ โ ๐images
โ โ โฃ ๐cat1.jpg
โ โ โฃ ๐cat2.jpg
โ โ โฃ ๐dog1.jpg
โ โ โ ๐dog2.jpg
โฃ ๐LICENSE.txt
โฃ ๐README.md
โฃ ๐image_similarity.ipynb
โ ๐requirements.txt
To install the necessary libraries, use the following command:
pip install -r requirements.txt
opencv-python
numpy
matplotlib
scikit-image
scikit-learn
keras
tensorflow
requirements.txt
file:
pip install -r requirements.txt
data/images/
directory.image_similarity.ipynb
notebook to compare the images.The image_similarity.ipynb
notebook contains the following sections:
Description: This cell imports all the necessary libraries for image processing, feature extraction, and similarity calculation. These include:
opencv-python
for image processing.numpy
for numerical operations.matplotlib
for plotting.scikit-image
for additional image processing functions.scikit-learn
for similarity calculations.keras
and tensorflow
for using the pre-trained VGG16 model and deep learning operations.Purpose: To ensure that all required libraries are imported and available for use in subsequent cells.
Description: This cell defines a function load_and_preprocess_image
that:
keras
's preprocess_input
.Purpose: To handle the loading and preprocessing of images, preparing them for input into the VGG16 model.
Description: This cell defines a function extract_vgg16_features
that:
Purpose: To use the pre-trained VGG16 model to extract deep features from the preprocessed image, which are used for comparing the images.
Description: This cell defines a function calculate_similarity
that:
scikit-learn
's cosine_similarity
function.Purpose: To calculate the cosine similarity between two feature vectors, providing a measure of similarity that ranges between -1 and 1.
Description: This cell defines a function display_images
that:
matplotlib
.Purpose: To visually display the images along with their titles, helping to verify the images being compared and understand the context of the similarity scores.
Description: This cell defines a function plot_similarities
that:
matplotlib
.Purpose: To provide an intuitive visual representation of the similarity scores, showing how similar each pair of images is based on the extracted features.
Description: This cell defines a function compare_images
that:
Purpose: To orchestrate the complete image comparison process by integrating all the previously defined functions, from loading and preprocessing images to displaying results.
Description: This cell defines the main
function that:
compare_images
function to execute the comparison.Purpose: To act as the entry point for the script, specifying the images to compare and initiating the comparison process.
Description: This cell runs the main
function.
Purpose: To start the image comparison process when the notebook is executed.
If you would like to contribute to this project, please fork the repository and submit a pull request with your improvements.
This project is licensed under the MIT License.