Reputation: 17
So I want the RGB values of an image placed into an histogram and then that histogram will be compared to other image's histogram. Currently this is the code:
if (size(cimg, 3) ~= 3)
error('rgbhist:numberOfSamples', 'Input image must be RGB.')
end
nBins = 256;
rHist = imhist(cimg(:,:,1), nBins);
gHist = imhist(cimg(:,:,2), nBins);
bHist = imhist(cimg(:,:,3), nBins);
hFig = figure;
%figure
subplot(1,2,1);imshow(cimg)
subplot(1,2,2);
hold on
h(1) = stem(1:256, rHist); %hold on
h(2) = stem(1:256 + 1/3, gHist, 'g');
h(3) = stem(1:256 + 2/3, bHist, 'b');
hold off
set(h, 'marker', 'none')
set(h(1), 'color', [1 0 0])
set(h(2), 'color', [0 1 0])
set(h(3), 'color', [0 0 1])
axis square
The code outputs the image along with its RGB histogram value, how can I use that histogram to compare it with other histograms so that I could potentially classify the image as having nearly the same colors as that of another image?
Upvotes: 0
Views: 468
Reputation: 4953
You could use Kullback Leibler Divergence to calculate the distance between 2 histograms.
This is easy as you can treat the Histogram as a distribution.
Since the KL Divergence isn't symmetric one could compute it twice (Namely [X, Y] and [Y, X]) and take the average.
Upvotes: 1