图像直方图匹配

本文探讨了直方图匹配的概念及其在不同光照条件下的应用,通过MATLAB函数实现图像直方图的调整,以模拟真实素描效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

直方图匹配又叫直方图规定化(Histogram Normalization/Matching)是指对一副图像进行变换,使其直方图与另一幅图像的直方图或特定函数形式的直方图进行匹配。应用场景如不同光照条件下的两幅图像。

function Iadjusted = histogram_matching(I, type)
% Histogram match the image I against a theoretically natural histogram
% which is believed to mimic real pencil drawings
%
% I must be a grayscale image within 0 and 255

% Prepare the histogram of image 'I', which is 'ho'
if ~isa(I,'uint8')
    I = im2uint8(I);
end

po = imhist(I)/ numel(I);
ho = cumsum(po);


% Prepare the 'natural' histogram which is 'histo'
p1 = @(x) 1 / 9 * exp(-(256-x)/9) * heaviside(256-x);
p2 = @(x) 1 / (256 - 105) * (heaviside(x-105) - heaviside(x-256));
% p2 = @(x) 1 / (225 - 105) * (heaviside(x-105) - heaviside(x-225));
p3 = @(x) 1 / sqrt(2*pi*11)*exp(-((x-90)^2)/(2*121));

if strcmp(type,'colour')
    %p = @(x) (52*p1(x) + 37*p2(x) + 11*p3(x));
    p = @(x) (62*p1(x) + 30*p2(x) + 5*p3(x));
else
    %p = @(x) (62*p1(x) + 30*p2(x) + 5*p3(x));
    p = @(x) (76*p1(x) + 22*p2(x) + 2*p3(x));
end

prob = zeros(1, 256); histo = zeros(1, 256);

for i=1:256
    prob(i) = p(i);
end
prob = prob/ sum(prob);
histo = cumsum(prob);


% Do the histogram matching
Iadjusted = zeros(size(I,1), size(I,2));
for y=1:size(I,1)
    for x=1:size(I,2)
        histogram_value = ho(I(y,x)+1);
        [v,i] = min(abs(histo - histogram_value));
        Iadjusted(y,x) = i;
    end
end
Iadjusted = Iadjusted / 255;

另外,matlab自身提供了histeq(I,hgram)函数可以实现直方图规定化.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值