Coder Social home page Coder Social logo

image-comparison's Introduction

Image Comparison with CNN-based Encoding

Overview

This code demonstrates a method for comparing images based on their image encodings using a Convolutional Neural Network (CNN) backbone. The process involves extracting image embeddings from a pretrained CNN model and then calculating the cosine similarity between these embeddings to quantify the visual similarity between images. The code then visualizes image pairs along with their computed similarity scores.

Requirements

  • Python
  • PyTorch
  • Fastai
  • Matplotlib
  • NumPy

How to Use

  1. Make sure you have the required libraries installed in your Python environment.
  2. Place the images you want to compare in a folder and set the folder_path variable to the path of that folder.
  3. Run the code to perform image comparison.
  4. The code will display image pairs along with their similarity scores.

Output

The output will be a visual representation of how similar the images in the specified folder are to each other. The similarity scores range from 0 (dissimilar) to 1 (identical), where a higher score indicates greater visual similarity.

Example

The code includes a function called plot_image_pairs, which plots image pairs and their similarity scores. An example of the output can be seen in the code above.

Note

  • The code uses a pretrained "convnext_tiny" model for feature extraction, but you can replace it with other pretrained models as needed.
  • You can adjust the image size, which is currently set to 192x192 pixels, by modifying the resizing step in the get_embedding function.

This code provides a simple yet effective way to compare images based on their visual content, making it useful for various applications such as image retrieval, duplicate detection, and content analysis.

image-comparison's People

Contributors

ippen avatar

Stargazers

Max Pfister avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.