matlab 输入图像 分别生成输入图像的R、G、B三通道直方图 对上一步每个通道的直方图,使用经过m值限定后的直方图分布范围来计算新的曝光值 利用曝光值计算分割点X_a,将每个直方图分割成两个子直方图
时间: 2024-05-29 07:11:56 浏览: 75
以下是实现该功能的MATLAB代码:
% 读取输入图像
I = imread('input_image.jpg');
% 分离R、G、B三个通道
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
% 计算每个通道的直方图
R_hist = imhist(R);
G_hist = imhist(G);
B_hist = imhist(B);
% 设置m值
m = 0.05;
% 计算经过m值限定后的直方图分布范围
R_range = range_limit(R_hist, m);
G_range = range_limit(G_hist, m);
B_range = range_limit(B_hist, m);
% 计算新的曝光值
R_exp = exp_value(R_range);
G_exp = exp_value(G_range);
B_exp = exp_value(B_range);
% 计算分割点X_a
R_Xa = calc_Xa(R_hist, R_exp);
G_Xa = calc_Xa(G_hist, G_exp);
B_Xa = calc_Xa(B_hist, B_exp);
% 将每个直方图分割成两个子直方图
R_subhist = sub_histogram(R_hist, R_Xa);
G_subhist = sub_histogram(G_hist, G_Xa);
B_subhist = sub_histogram(B_hist, B_Xa);
% 显示原始图像和每个通道的直方图
figure;
subplot(2,2,1); imshow(I); title('原始图像');
subplot(2,2,2); imhist(R); title('R通道直方图');
subplot(2,2,3); imhist(G); title('G通道直方图');
subplot(2,2,4); imhist(B); title('B通道直方图');
% 显示经过限定和计算后的结果
figure;
subplot(2,3,1); bar(R_hist); title('R原始直方图');
subplot(2,3,2); bar(G_hist); title('G原始直方图');
subplot(2,3,3); bar(B_hist); title('B原始直方图');
subplot(2,3,4); bar(R_range); title('R限定后直方图');
subplot(2,3,5); bar(G_range); title('G限定后直方图');
subplot(2,3,6); bar(B_range); title('B限定后直方图');
figure;
subplot(2,3,1); bar(R_hist); title('R原始直方图');
subplot(2,3,2); bar(G_hist); title('G原始直方图');
subplot(2,3,3); bar(B_hist); title('B原始直方图');
subplot(2,3,4); bar(R_subhist{1}); title('R分割后子直方图1');
subplot(2,3,5); bar(G_subhist{1}); title('G分割后子直方图1');
subplot(2,3,6); bar(B_subhist{1}); title('B分割后子直方图1');
figure;
subplot(2,3,1); bar(R_hist); title('R原始直方图');
subplot(2,3,2); bar(G_hist); title('G原始直方图');
subplot(2,3,3); bar(B_hist); title('B原始直方图');
subplot(2,3,4); bar(R_subhist{2}); title('R分割后子直方图2');
subplot(2,3,5); bar(G_subhist{2}); title('G分割后子直方图2');
subplot(2,3,6); bar(B_subhist{2}); title('B分割后子直方图2');
阅读全文
相关推荐















