{"id":14958639,"url":"https://github.com/savinrazvan/image_similarity","last_synced_at":"2025-03-26T03:13:40.735Z","repository":{"id":251214240,"uuid":"836747946","full_name":"SavinRazvan/image_similarity","owner":"SavinRazvan","description":"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.","archived":false,"fork":false,"pushed_at":"2024-08-01T13:37:55.000Z","size":1572,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T03:13:36.894Z","etag":null,"topics":["computer-vision","convolutional-neural-networks","cosine-similarity","deep-learning","feature-extraction","image-comparison","image-processing","image-similarity","keras","pre-trained-models","python","vgg16"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SavinRazvan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-01T13:28:06.000Z","updated_at":"2024-12-11T08:17:51.000Z","dependencies_parsed_at":"2024-08-01T15:12:21.797Z","dependency_job_id":null,"html_url":"https://github.com/SavinRazvan/image_similarity","commit_stats":null,"previous_names":["savinrazvan/image_similarity"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SavinRazvan%2Fimage_similarity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SavinRazvan%2Fimage_similarity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SavinRazvan%2Fimage_similarity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SavinRazvan%2Fimage_similarity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SavinRazvan","download_url":"https://codeload.github.com/SavinRazvan/image_similarity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245579675,"owners_count":20638679,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","convolutional-neural-networks","cosine-similarity","deep-learning","feature-extraction","image-comparison","image-processing","image-similarity","keras","pre-trained-models","python","vgg16"],"created_at":"2024-09-24T13:17:38.622Z","updated_at":"2025-03-26T03:13:40.714Z","avatar_url":"https://github.com/SavinRazvan.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Image Similarity Comparison using VGG16\n\nThis 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.\n\n## Project Structure\n\n```bash\n📦image_similarity\n ┣ 📂data\n ┃ ┗ 📂images\n ┃ ┃ ┣ 📜cat1.jpg\n ┃ ┃ ┣ 📜cat2.jpg\n ┃ ┃ ┣ 📜dog1.jpg\n ┃ ┃ ┗ 📜dog2.jpg\n ┣ 📜LICENSE.txt\n ┣ 📜README.md\n ┣ 📜image_similarity.ipynb\n ┗ 📜requirements.txt\n```\n\n## Requirements\n\nTo install the necessary libraries, use the following command:\n\n```bash\npip install -r requirements.txt\n```\n\n### requirements.txt\n\n```plaintext\nopencv-python\nnumpy\nmatplotlib\nscikit-image\nscikit-learn\nkeras\ntensorflow\n```\n\n## How to Run the Project\n\n1. Clone the repository to your local machine.\n2. Ensure you have Python installed.\n3. Install the required libraries using the `requirements.txt` file:\n    ```bash\n    pip install -r requirements.txt\n    ```\n4. Place your images in the `data/images/` directory.\n5. Open and run the `image_similarity.ipynb` notebook to compare the images.\n\n## image_similarity.ipynb\n\nThe `image_similarity.ipynb` notebook contains the following sections:\n\n### Section 1: Import Libraries\n\n**Description**: This cell imports all the necessary libraries for image processing, feature extraction, and similarity calculation. These include:\n- `opencv-python` for image processing.\n- `numpy` for numerical operations.\n- `matplotlib` for plotting.\n- `scikit-image` for additional image processing functions.\n- `scikit-learn` for similarity calculations.\n- `keras` and `tensorflow` for using the pre-trained VGG16 model and deep learning operations.\n\n**Purpose**: To ensure that all required libraries are imported and available for use in subsequent cells.\n\n### Section 2: Load and Preprocess Image Function\n\n**Description**: This cell defines a function `load_and_preprocess_image` that:\n- Loads an image from the specified path.\n- Resizes the image to a target size (224x224) required for VGG16.\n- Applies necessary preprocessing steps like scaling pixel values using `keras`'s `preprocess_input`.\n\n**Purpose**: To handle the loading and preprocessing of images, preparing them for input into the VGG16 model.\n\n### Section 3: Extract Features Using VGG16\n\n**Description**: This cell defines a function `extract_vgg16_features` that:\n- Loads the pre-trained VGG16 model with weights trained on ImageNet.\n- Creates a new model that outputs features from the 'fc1' layer of VGG16.\n- Extracts and flattens the features from the preprocessed image.\n\n**Purpose**: To use the pre-trained VGG16 model to extract deep features from the preprocessed image, which are used for comparing the images.\n\n### Section 4: Calculate Similarity Function\n\n**Description**: This cell defines a function `calculate_similarity` that:\n- Computes the cosine similarity between two given feature vectors using `scikit-learn`'s `cosine_similarity` function.\n\n**Purpose**: To calculate the cosine similarity between two feature vectors, providing a measure of similarity that ranges between -1 and 1.\n\n### Section 5: Display Images Function\n\n**Description**: This cell defines a function `display_images` that:\n- Displays a list of images along with their titles in a single figure using `matplotlib`.\n\n**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.\n\n### Section 6: Plot Similarities Function\n\n**Description**: This cell defines a function `plot_similarities` that:\n- Creates a bar plot to visualize the pairwise similarity scores between the images using `matplotlib`.\n\n**Purpose**: To provide an intuitive visual representation of the similarity scores, showing how similar each pair of images is based on the extracted features.\n\n### Section 7: Compare Images Function\n\n**Description**: This cell defines a function `compare_images` that:\n- Loads and preprocesses each image.\n- Extracts features from each image using the VGG16 model.\n- Calculates pairwise similarities between the images.\n- Displays the images.\n- Plots the similarity scores.\n- Prints the similarity results.\n\n**Purpose**: To orchestrate the complete image comparison process by integrating all the previously defined functions, from loading and preprocessing images to displaying results.\n\n### Section 8: Main Function\n\n**Description**: This cell defines the `main` function that:\n- Specifies the list of image paths to be compared.\n- Calls the `compare_images` function to execute the comparison.\n\n**Purpose**: To act as the entry point for the script, specifying the images to compare and initiating the comparison process.\n\n### Section 9: Run the Main Function\n\n**Description**: This cell runs the `main` function.\n\n**Purpose**: To start the image comparison process when the notebook is executed.\n\n## Contributing\n\nIf you would like to contribute to this project, please fork the repository and submit a pull request with your improvements.\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsavinrazvan%2Fimage_similarity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsavinrazvan%2Fimage_similarity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsavinrazvan%2Fimage_similarity/lists"}