Image Retrieval Using Color Histogram Features with MATLAB Implementation

Color Features

Color represents one of the most fundamental visual attributes in digital images, effectively characterizing image content and distinguishing objects. Color histogram-based retrieval leverages the distribution of color values across an image to establish similarity between images. A color histogram is a multi-dimensional array where each dimension corresponds to a color channel (such as RGB, HSV, or Lab), and each bin stores the frequency of occurrence for specific color ranges.

Retrieval Methodology

The typical pipeline for color-based image retrieval consists of four stages:

  1. Feature Extraction: Compute color histograms from both query and database images using uniform quantization across each color channel.

  2. Distance Computation: Measure the dissimilarity between the query histogram and each database image histogram. Common distance metrics include Euclidean distance, Manhattan distance, and Chi-squared distance.

  3. Ranking: Sort database images according to their computed distances, where smaller distances indicate higher similarity.

  4. Result Presentation: Return the top-K most similar images based on the ranked distances.

Advantages

  • Computational Efficiency: Color histograms require minimal processing overhead, making them suitable for large-scale datasets.
  • Robustness to Geometric Transformations: Color features remain invariant under rotation, scaling, and minor viewpoint changes.
  • Simplicity: The feature extraction process is straightforward and does not require complex preprocessing.

Limitations

  • Semantic Gap: Color histograsm fail to capture high-level semantic information, potentially returning visually similar but semantically unrelated images.
  • Sensitivity to Noise: Illuminasion variations and image noise can significantly alter color distributions.
  • High Dimensionality: Quantized color histograms may contain hundreds or thousands of bins, impacting indexing performance.

Enhancement Techniques

Researchers have developed several strategies to address these limitations:

  • Color Space Transformation: Converting images from RGB to HSV or CIELab color spaces improves color discrimination under varying lighting conditions.

  • Spatial Color Features: Dividing images into grid cells and extracting histograms from each region preserves spatial information, reducing the semantic gap.

  • Weighted Histogram Bins: Assigning higher weights to perceptually significant color bins enhances retrieval precision.

  • Dimensionality Reduction: Applying PCA or autoencoders compresses histogram features while preserving discriminative power.

  • Machine Learning Integration: Training SVM classifiers or neural networks on color features enables semantic-aware retrieval.

Practical Applications

  • Digital Asset Management: Organizing and searching through large photo collections.
  • Visual Search Engines: Finding images containing specific color palettes or patterns.
  • Medical Imaging: Assisting in diagnostic procedures through color-based lesion detection.
  • Content-Based Recommendation: Suggesting visually similar products in e-commerce platforms.

MATLAB Implementation

function imageRetrieval(queryPath, databasePath, imageCount)
    
    fprintf('Loading query image: %s\n', queryPath);
    queryFeatures = computeColorHistogram(queryPath);
    
    distances = zeros(1, imageCount);
    
    fprintf('Computing distances from %d images...\n', imageCount);
    for idx = 1:imageCount
        imagePath = fullfile(databasePath, sprintf('image_%02d.jpg', idx));
        dbFeatures = computeColorHistogram(imagePath);
        
        channelDist = zeros(3, 1);
        for c = 1:3
            diff = queryFeatures((c-1)*4 + 1:c*4) - dbFeatures((c-1)*4 + 1:c*4);
            channelDist(c) = sqrt(sum(diff.^2));
        end
        
        distances(idx) = mean(channelDist);
    end
    
    [sortedDist, rankOrder] = sort(distances, 'ascend');
    
    figure;
    subplot(2, 2, 1);
    queryImg = imread(queryPath);
    imshow(queryImg);
    title('Query Image');
    
    for i = 1:3
        matchedIdx = rankOrder(i);
        matchedPath = fullfile(databasePath, sprintf('image_%02d.jpg', matchedIdx));
        matchedImg = imread(matchedPath);
        
        subplot(2, 2, i + 1);
        imshow(matchedImg);
        title(sprintf('Rank %d (Distance: %.4f)', i, sortedDist(i)));
    end
end

function hist = computeColorHistogram(imagePath)
    img = imread(imagePath);
    imgDouble = im2double(img);
    
    numBins = 4;
    hist = zeros(12, 1);
    
    for c = 1:3
        channel = imgDouble(:, :, c);
        channelFlat = channel(:);
        quantized = floor(channelFlat * numBins) + 1;
        quantized = min(quantized, numBins);
        
        binCounts = histcounts(quantized, 1:numBins+1);
        hist((c-1)*numBins + 1:c*numBins) = binCounts(:);
    end
    
    hist = hist / sum(hist);
end

The implementation demonstrates a complete retrieval pipeline with configurable parameters for database size and histogram quantization levels. The distance calculation aggregates Euclidean distances across color channels, providing a balanced measure of color similarity.

Tags: image retrieval color histogram content-based search Computer Vision MATLAB

Posted on Sat, 11 Jul 2026 16:52:40 +0000 by fourteen00