Skip to content

AthosExarchou/Digital-Image-Processing-and-Applications-Project_2

Repository files navigation

Digital Image Processing and Applications Project_2

Overview

Developed as a project for the Digital Image Processing and Applications course at Harokopio University of Athens – Dept. of Informatics and Telematics, this project focuses on advanced topics in image processing, compression, and feature extraction. It is divided into four exercises, each tackling a different aspect of computer vision and multimedia systems, including edge detection, lossless compression, image classification, and content-based image retrieval (CBIR).

All implementations are done in Python using libraries such as NumPy, OpenCV, scikit-image, and scikit-learn.


Exercises

Exercise 1: Edge Detection

Objective: Detect the main edges of grayscale images (leaf.jpg, X-ray.jpeg, parking-lot.jpg) using three different methods.

Tasks:

  • Design, describe, and apply three edge detection methods (e.g., Sobel, Canny, Laplacian of Gaussian).
  • For each image:
    • Display the original grayscale version.
    • Generate the best binary edge masks from each method.
  • Provide a detailed explanation of:
    • Method choice
    • Parameter selection
    • Result interpretation and comparison

Exercise 2: Shannon-Fano Image Compression

Objective: Implement the Shannon-Fano compression algorithm from scratch and compare it with Huffman coding.

Tasks:

  • Apply Shannon-Fano encoding to airplane.jpg and bridge.jpg.
  • For each image, compute and present:
    1. The codewords (mapping grayscale values to binary codes).
    2. The average codeword length.
    3. The entropy of the image.
    4. The achieved compression ratio.
  • Compute the compression ratio using Huffman coding as well.
  • Compare and comment on the performance of Shannon-Fano vs. Huffman.

Exercise 3: Feature Extraction for Image Classification

Dataset: Animal Image for Recognition (4 classes: Nilgai, Horse, Cow, Water Buffalos).

Tasks:

  1. Convert images from chcek\\chcek and test\\test folders to grayscale.
  2. Extract global features:
    • Co-occurrence matrix (GLCM)
    • Local Binary Pattern (LBP)
    • Histogram of Oriented Gradients (HoG)
  3. Transform each 2D feature into a 1D vector by concatenating rows.
  4. Use the following representative prototype images for classification:
    • cow_1001.jpg
    • horse_1001.jpeg
    • nilgai_1001.jpeg
    • buffelo_1001.jpeg
  5. Define similarity between images as the Euclidean distance between feature vectors.
  6. Classify each image from the test\\test set based on minimum distance to prototypes.
  7. Compute classification accuracy for each feature type.
  8. Provide example classification results with similarity metrics.

Exercise 4: Feature Extraction for Image Retrieval (CBIR System)

Dataset: Chess Pieces Detection Images Dataset (5 classes: Queen, Rook, Bishop, Knight, Pawn).

Tasks:

  • Task A: Convert all dataset images to grayscale and extract local SIFT (Scale-Invariant Feature Transform) features.
  • Task B: Implement a Bag of Visual Words (BoVW) model to create a global feature vector for each image.
  • Task C: For a set of representative query images, retrieve the top-10 most similar images from the dataset by computing the Euclidean distance between their BoVW feature vectors.
  • Task D: Compute the retrieval accuracy and provide a qualitative analysis of the retrieval results for 2-3 queries.

Technologies & Libraries Used

  • Python 3
  • NumPy and SciPy – Matrix and numerical operations
  • Matplotlib – Visualization of images and results
  • scikit-image – Edge detection, LBP, and GLCM utilities
  • scikit-learn – K-means for BoVW vocabulary creation
  • OpenCV – Feature extraction (SIFT, HoG) and image processing
  • Pillow – Image loading and manipulation

Results and Discussion

  • Edge Detection demonstrates the trade-offs between different operators. The Canny detector proved most robust for general-purpose edge finding, while methods like Sobel were simpler but more sensitive to noise.
  • Image Compression analysis shows that while both Shannon-Fano and Huffman are effective lossless algorithms, Huffman coding consistently provides a slightly better or equal compression ratio due to its more optimal codeword assignment strategy.
  • Image Classification results highlight how different features capture distinct image properties. HoG was effective at describing shape, LBP excelled at texture, and GLCM captured spatial texture relationships, leading to varying classification accuracies across the animal dataset.
  • The CBIR System successfully retrieved visually similar images using the BoVW model. This approach effectively summarizes complex local features (SIFT) into a global histogram, enabling efficient content-based similarity search, with accuracy dependent on vocabulary size and feature distinctiveness.

Datasets

The majority of the images used in this project were sourced from publicly available datasets on Kaggle:


How to Run

  1. Clone this repository:

    git clone <https://github.com/AthosExarchou/Digital-Image-Processing-and-Applications-Project_2.git>
    cd <Digital-Image-Processing-and-Applications-Project_2>
  2. Install dependencies:

    pip install -r requirements.txt
  3. Run each exercise script individually (examples):

    python exercise_1_edge_detection.py
    python exercise_2a_shannon_fano.py
    python exercise_2b_huffman_comparison.py
    python exercise_3a_extract_features.py
    python exercise_3b_classify_images.py
    python exercise_3c_evaluate_accuracy.py
    python exercise_4_cbir_bovw.py

Author

License

This project is licensed under the MIT License.

About

This project focuses on advanced topics in image processing, compression, and feature extraction. It is divided into four exercises, each tackling a different aspect of computer vision and multimedia systems, including edge detection, lossless compression, image classification, and content-based image retrieval (CBIR).

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages