/cbir

Content Based Image Retrieval system based on color, texture, and shape.

Primary LanguagePythonMIT LicenseMIT

Content Based Image Retrival (CBIR)

License Python Version Project Version

Introduction

CBIR is a computer vision technique for retrieving images from a database based on the similarity of their content. The content of an image is usually described by a set of features. The features are extracted from the image and then compared to the features of the images in the database. The images with the most similar features are returned as the result of the search. The features can be color, texture, shape, etc. The most common features are color, texture, and shape. The features are extracted from the image and then compared to the features of the images in the database. The images with the most similar features are returned as the result of the search. The features can be color, texture, and shape.

Features Extraction

For each image in the database, we extract the features and store them in a JSON file features.json. The features are extracted using the following methods:

by color space

  • RGB: Red, Green, Blue.
  • HSV: Hue, Saturation, Value.
  • YCrCb: Luminance, Chrominance Red, Chrominance Blue.

by texture

  • LBP: Local Binary Pattern.
  • GLCM: Gray Level Co-occurrence Matrix.
  • LPQ: Local Phase Quantization.

by shape

  • LOG: Laplacian of Gaussian.
  • SOBEL: Sobel operator.
  • HU: Hu moments.

Query Image

The query image is the image that we want to search for in the database. The query image is also extracted using the same methods as the database images. The query image is then compared to the images in the database using the features and a metric is calculated for each image in the database. The images are then sorted based on the metric and the images with the lowest distance are returned as the result of the search.

Metrics for Features Comparison

The features are matched using the following metrics:

  • Euclidean distance.
  • Chebyshev distance.
  • Cosine similarity.
  • Manhattan distance.

The similarity score is calculated for each image in the database and the images are sorted based on the similarity score. The images with the highest similarity score are returned as the result of the search.

Authors

  • @FilaliHicham, Applied Mathematics & AI engineering student at ENSIAS.
  • @HamzaBamohammed, Applied Mathematics & AI engineering student at ENSIAS
  • @BouchraSahri, Applied Mathematics & AI engineering student at ENSIAS

Instructions

  1. Clone the repository to your local machine
git clone https://github.com/HamzaBamohammed/cbir
  1. Install the required dependencies
pip install -r requirements.txt
  1. Change the images in the database folder database with your own images if needed.
  2. Run the indexation script, this will extract the features of the images in the database and store them in a JSON file features.json
python index.py
  1. Run the main script, that will open the GUI and you can load the query image and search for similar images in the database.
python main.py

Example

  1. When the main script is run, the following GUI will open. GUI

  2. Load the query image by clicking on the Load Query Image button, then select the image from the file explorer (not necessarily from the database). Load Query

  3. Select the combination of the color space, texture, and shape descriptors that you want to use for the search, and then click the search button. Search

  4. The result of the search will be displayed in the GUI. Result