Languages: Matlab
Categories: 其他
gistfile1.txt
%改成自己的.m文件名
function test()
%读入图片
f=my_clean( g2,n);
imshow(g2);
f = double(f);
%滤波函数？去雾imguidedfilter() 可以看一下api
b = double( imguidedfilter( uint8( f ) ) ) - f + 128 ;
t = imfilter( b, fspecial( 'gaussian',[5 5]) );
f = ( f*50 + ( f+2*t-256 )*50 )/100;
f = uint8(f);
subplot( 2,1,1 ),imshow( g ),title('原图');
subplot( 2,1,2 ),imshow( f ),title('填充处理后图像');
end

function  f = my_clean( g2,n )
%如果只传入一个参数g2，设置n为1
if( nargin == 1 )
n = 1;
end
%获取图片大小
[ M,N,~ ] = size( g2 );
while( n ~=0 )
n = n - 1;
%roipoly这个函数我不是太清楚，可以看一下api
%看一下immultiply的api，好像是图像的乘法运算？
x1 = immultiply( mask,g2( :,:,1 ) );
x2 = immultiply( mask,g2( :,:,2 ) );
x3 = immultiply( mask,g2( :,:,3 ) );
%cat函数
x = cat( 3,x1,x2,x3 );
f1 = zeros( M,N );
f2 = zeros( M,N );
f3 = zeros( M,N );
flag = 0;
for i = 1:M
for j = 1:N
if( x1( i,j ) ~= 0 )
r = x( i,j,: );
flag = 1;
break
end
if( flag == 1 )
break
end
end
end
y = double(y);
for i = 2:3:M-1
for j = 2:3:N-1
f1( i-1:i+1,j-1:j+1 ) = mask( i-1:i+1,j-1:j+1 ).* y( :,:,1 );
f2( i-1:i+1,j-1:j+1 ) = mask( i-1:i+1,j-1:j+1 ).* y( :,:,2 );
f3( i-1:i+1,j-1:j+1 ) = mask( i-1:i+1,j-1:j+1 ).* y( :,:,3 );
end
end
f = cat( 3,f1,f2,f3 );
f = uint8( f );
a = g2 - x;
f = f + a;
g2 = f;
end
end