复现《基于直方图分布特性的水下图像颜色校正方法》含源码

        今天带大家手把手复现一篇水下图像增强的论文,可以去知网能检索得到。引用:[1]雷小燕,张卫东,潘细朋.基于直方图分布特性的水下图像颜色校正方法[J].计算机工程与设计,2022,43(08):2284-2293.DOI:10.16208/j.issn1000-7024.2022.08.025.以下是我论文复现的图片

        我们可以从流程图看出,本文只是做了一个颜色校正的方法,而且颜色校正的方法(大部分都是改进基于直方图、通道补偿、Retinex)也比较容易实现。接下来每个小的步骤,小的点都一一带大家写。以下是作者考虑的出发点:直方图从上到下看:RGB通道,大家可以看到偏绿的图像在G通道是靠近255的,图像偏什么颜色直方图就往往哪里靠,但是可以看出自然图像上颜色都是均匀分布的,那我们的目的就是要把RGB通道都拉伸(补偿)道均匀的0-255范围内。

clear mean
image = imread('1.jpg');

r = image(:, :, 1);
g = image(:, :, 2); 
b = image(:, :, 3);

hist_r = imhist(r);
hist_g = imhist(g);
hist_b = imhist(b);

figure;
subplot(1,3,1);imhist(r);title('hr');
subplot(1,3,2);imhist(g);title('hg');
subplot(1,3,3);imhist(b);title('hb');

avg_r=0;
for i=1:255
    avg_r=avg_r+ (hist_r(i)/sum(hist_r))*i; 
end
avg_r=round(avg_r);

avg_g=0;
for i=1:255
    avg_g=avg_g+ (hist_g(i)/sum(hist_g))*i; 
end
avg_g=round(avg_g);

avg_b=0;
for i=1:255
    avg_b=avg_b+ (hist_b(i)/sum(hist_b))*i; 
end
avg_b=round(avg_b);

disp(['avg_r:',num2str(avg_r)]);
disp(['avg_g:',num2str(avg_g)]);
disp(['avg_b:',num2str(avg_b)]);

% 创建包含 a、b、c 的向量
vec = [avg_r, avg_g, avg_b];

% 使用 sort 函数对向量进行排序
sorted_vec = sort(vec);

% 找出最小值、中间值和最大值
min_value = sorted_vec(1);
mid_value = sorted_vec(2);
max_value = sorted_vec(3);

disp('三个数的大小(按照顺序):');
disp(['最小值: ', num2str(min_value)]);
disp(['中间值: ', num2str(mid_value)]);
disp(['最大值: ', num2str(max_value)]);

if avg_r > avg_g && avg_r > avg_b
    first = hist_r;
elseif avg_r < avg_g && avg_r < avg_b
    third = hist_r;
else
    second = hist_r;
end

if avg_g > avg_r && avg_g > avg_b
    first = hist_g;
elseif avg_g < avg_r && avg_g < avg_b
    third = hist_g;
else
    second = hist_g;
end

if avg_b > avg_r && avg_b > avg_g
    first = hist_b;
elseif avg_b < avg_r && avg_b < avg_g
    third = hist_b;
else
    second = hist_b;
end

m = (max_value - min_value) / (max_value + min_value);

n = (max_value - mid_value) / (max_value + mid_value);

disp(['m: ', num2str(m)]);
disp(['n: ', num2str(n)]);

second = second + n * first;

third = third + m * first;

figure;
subplot(2,3,1);  
bar(hist_r);
subplot(2,3,2);  
bar(hist_g);
subplot(2,3,3); 
bar(hist_b);
subplot(2,3,4);  
bar(first);
subplot(2,3,5);  
bar(second);
subplot(2,3,6);  
bar(third);

first_mean = mean(first);
first_std =std(first);

second_mean = mean(second);
second_std =std(second);

third_mean = mean(third);
third_std =std(third);

l=3;
first_min = first_mean - l*first_std;
first_max = first_mean + l*first_std;

second_min = second_mean - l*second_std;
second_max = second_mean + l*second_std;

third_min = third_mean - l*third_std;
third_max = third_mean + l*third_std;

first_new = ((first - first_min)/(first_max - first_min))*255;
second_new = ((second - second_min)/(second_max - second_min))*255;
third_new = ((third - third_min)/(third_max - third_min))*255;

figure;
subplot(2,3,1);  
bar(first_new);
subplot(2,3,2);  
bar(second_new);
subplot(2,3,3); 
bar(third_new);

% 合成三通道直方图
hist_eq = first_new + second_new + third_new;

% 对原始图像的RGB三个通道分别进行直方图均衡化,使用hist_eq_R、hist_eq_G、hist_eq_B作为输入参数
enhanced_r1 = histeq(image(:,:,1), hist_eq);
enhanced_g1 = histeq(image(:,:,2), hist_eq);
enhanced_b1 = histeq(image(:,:,3), hist_eq);

% 将增强后的RGB通道合并为一张彩色图像
enhanced_img1 = cat(3, enhanced_r1, enhanced_g1, enhanced_b1);

figure;
subplot(2,2,1);  
imshow(image);
title('Orginal Image');
subplot(2,2,2);  
imshow(enhanced_img1);
title('OUR');
subplot(2,2,3); 
imhist(image);
title('原始直方图');
subplot(2,2,4);  
imhist(enhanced_img1);
title('增强直方图');

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值