[源码是甚么]MATLAB代码 求剖析 何的去雾算法外面的暗通道算法 每句都是甚么意思啊?又辨别对应论文里的甚么道理?

  • A+
所属分类:it
摘要

function小白源码资源站dark=darkChannel(imRGB)r=imRGB(:,:,1);g=imRGB(:,:,2);b=imRGB(:,:,3);辨别提取三色的灰度图[mn]=size(r);提取单色图矩阵的宽度和长度a=zeros(m,n);创立m*n的零矩阵afori=

function小白源码资源站http://www.526bt.com/account?__preferral=41b2453033.2042n dark=darkChannel(imRGB)

r=imRGB(:,:,1);
g=imRGB(:,:,2);
b=imRGB(:,:,3); 辨别提取三色的灰度图

[m n]=size(r); 提取单色图矩阵的宽度和长度
a=zeros(m,n); 创立m*n的零矩阵a
for i=1: m
fo小白源码资源站http://www.526bt.com/account?__preferral=41b2453033.2042or j=1: n
a(i,j)=min(r(i,j), g(i,j));
a(i,j)=min(a(i,j), b(i,j)); 依次比拟三色重量的最小值提取为暗通道图

end
end

d=ones(15,15); 创立15*15的单位矩阵
fun=@(block_struct)min(min(block_struct.data))*d;
dark=blockproc(a, [15 15], fun); 将图片分红15*15的小块并将每块酿成个中的最小值

dark=dark(1:m, 1:n);
我也是新手啊兄弟只能帮你到这儿了

这个哈处理的,要哀通知我

%%%%暗原色去雾算法是建立在户外天然场景暗通道优先规律的基础上的去雾方法,其实就是解一个方程
%%I(x)=J(x)t(x)+A(1-t(x));个中I(x)是遭到雾气污染的图象。J(x)是我们需求求的去雾后的图象
%%t(x)是天空中云层的透射散布率,A是天空的亮度
%阴影去雾算法
% 原始图象
img_name=imread('C:\Users\Administrator\Desktop\桌面文件\专业课\设计\2.bmp');
I=double(img_name) / 255;
% 获得图象大年夜小
[h,w,c]=size(I);
%去雾系数
w0=0.95;
img_size=w * h;
%初始化结果图象
dehaze=zeros(h,w,c);
%初始化阴影通道图象
win_dark=zeros(h,w);
for i=1:h
for j=1:w
win_dark(i,j)=min(I(i,j,:));%将三个通道中最暗的值赋给dark_I(i,j),明显,三维图酿成了二维图
end
end
win_dark=ordfilt2(win_dark,1,ones(9,9),'symmetric');
%计算大年夜气亮度A,相干道理详见论文“Single Image Haze Removal Using Dark Channel Prior”
dark_channel=win_dark;
A=max(max(dark_channel));
[i,j]=find(dark_channel==A);
i=i(1);
j=j(1);
A=mean(I(i,j,:));
%计算初始的transmission map
transmission=1 - w0 * win_dark / A;
%用guided filter对trasmission map做soft matting
gray_I=I(:,:,1);%这里gray_I 可所以RGB图象中任何一个通道
p=transmission;
r=80;
eps=10^-3;
transmission_filter=guidedfilter(gray_I, p, r, eps);
t0=0.1;
t1=max(t0,transmission_filter);
for i=1:c
for j=1:h
for l=1:w
dehaze(j,l,i)=(I(j,l,i)-A)/t1(j,l)+A;
end
end
end
figure,
imshow(I);title('去雾前')
figure,
imshow(dehaze);title('去雾后')
%外面用到的两个函数以下:(这两个函数是何凯明guided filter中的,具体道理可以参考博客园中laviewpb的剖析)
function q=guidedfilter(I, p, r, eps)
% GUIDEDFILTER O(1) time implementation of guided filter.
%
% - guidance image: I (should be a gray-scale/single channel image)
% - filtering input image: p (should be a gray-scale/single channel image)
% - local window radius: r
% - regularization parameter: eps
[hei, wid]=size(I);
N=boxfilter(ones(hei, wid), r); % the size of each local patch; N=(2r+1)^2 except for boundary pixels.
mean_I=boxfilter(I, r) N;
mean_p=boxfilter(p, r) N;
mean_Ip=boxfilter(I.*p, r) N;
cov_Ip=mean_Ip - mean_I .* mean_p; % this is the covariance of (I, p) in each local patch.
mean_II=boxfilter(I.*I, r) N;
var_I=mean_II - mean_I .* mean_I;
a=cov_Ip (var_I + eps); % Eqn. (5) in the paper;
b=mean_p - a .* mean_I; % Eqn. (6) in the paper;
mean_a=boxfilter(a, r) N;
mean_b=boxfilter(b, r) N;
q=mean_a .* I + mean_b; % Eqn. (8) in the paper;
end
function imDst=boxfilter(imSrc, r)
% BOXFILTER O(1) time box filtering using cumulative sum
%
% - Definition imDst(x, y)=sum(sum(imSrc(x-r:x+r,y-r:y+r)));
% - Running time independent of r;
% - Equivalent to the function: colfilt(imSrc, [2*r+1, 2*r+1], 'sliding', @sum);
% - But much faster.
[hei, wid]=size(imSrc);
imDst=zeros(size(imSrc));
%cumulative sum over Y axis
imCum=cumsum(imSrc, 1);
%difference over Y axis
imDst(1:r+1, :)=imCum(1+r:2*r+1, :);
imDst(r+2:hei-r, :)=imCum(2*r+2:hei, :) - imCum(1:hei-2*r-1, :);
imDst(hei-r+1:hei, :)=repmat(imCum(hei, :), [r, 1]) - imCum(hei-2*r:hei-r-1, :);
%cumulative sum over X axis
imCum=cumsum(imDst, 2);
%difference over Y axis
imDst(:, 1:r+1)=imCum(:, 1+r:2*r+1);
imDst(:, r+2:wid-r)=imCum(:, 2*r+2:wid) - imCum(:, 1:wid-2*r-1);
imDst(:, wid-r+1:wid)=repmat(imCum(:, wid), [1, r]) - imCum(:, wid-2*r:wid-r-1);
end

分享当前页面将至少获得10%佣金,点此获取推广链接(规则说明)。

本站VIP源码资源永久免费下载!持续更新!www.526bt.com

加入999永久VIP会员带做项目包赚钱!教引流包搭建,社群资源共享!

新项目更新通知QQ群:767688774 站长技术交流QQ群:552760713

点击这里给我发消息

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
月入30万的在家创业开淘宝的教程!收徒!一对一指导!包赚钱!
网站漏洞修复 网站木马清理 漏洞修复 漏洞检测 服务器安全维护
SLL证书配置支持https网站
全网最低价建设各种网站 | 网站修改 | 网站开发 | 模板开发

发表评论

您必须才能发表评论!