|
From: | Terry Duell |
Subject: | Re: histogram matching of colour images |
Date: | Mon, 31 Aug 2015 17:01:32 +1000 |
User-agent: | Opera Mail/12.16 (Linux) |
Hello Andreas,On Mon, 31 Aug 2015 16:53:54 +1000, Andreas Weber <address@hidden> wrote:
Am 31.08.2015 um 04:33 schrieb Terry Duell:Hello All, I am looking for a method of matching the histogram of a subject image to that of a reference image, both r,g,b. I don't see any functions in the image package that appear to do that, but may be suffering domestic blindness. Anyone have any ideas how to do this?I don't know a function in octave-forge image which would do this but it should be easy to do it yourself. ## get octave logo img = ind2rgb (get (0, "defaultimagecdata"), colormap); bins = 10; n = zeros (3, bins); n(1,:) = hist (img (:, :, 1)(:), bins); n(2,:) = hist (img (:, :, 2)(:), bins); n(3,:) = hist (img (:, :, 3)(:), bins); Then you'll have the counts of red, green, blue pixels per bin which I would normalize to 0..1 and then feed to a "cost" function, perhaps sumsq (n_ref - n) to calculate how "similar" the two images are. HTH, Andy
I only just found this function, which looks like it might do what I want...not really tested it yet.
function I = histmatch(I1, I2) %% Histogram Matching from image I1 to image I2 % I1: reference image % I2: target image cdf1 = cal_cdf(I1); % cdf of image I1 cdf2 = cal_cdf(I2); % cdf of image I2 %% mapping function Fk() Fk = zeros(1, 256); for k = 1:256 tt = abs(cdf2(k) - cdf1); [~, idx] = min(tt); Fk(k) = idx - 1; end % mapping [r, c] = size(I2); I2 = I2(:); I = I2; for k = 0:255 I(I2 == k) = Fk(k+1); end I = reshape(I, r, c); end function t_cdf = cal_cdf(I) %% calculate cumulative distribution function (CDF) of image I [hist, ~] = imhist(I); hist = hist / numel(I); % normalize hist t_cdf = cumsum(hist); % cdf end Thanks for your help. Cheers, -- Regards, Terry Duell
[Prev in Thread] | Current Thread | [Next in Thread] |