【图像增强】HSV空间双边滤波图像去雾【含Matlab源码 067期】

⛄一、图像增强技术简介

图像增强
图像增强是对图像的某些特征,如边缘、轮廓、对比度等进行强调或锐化,以便于显示、观察或进一步分析与处理。通过对图像的特定加工,将被处理的图像转化为对具体应用来说视觉质量和效果更“好”或更“有用”的图像。
图像增强是最基本最常用的图像处理技术,常用于其他图像处理的预处理阶段。
在这里插入图片描述
(1)高通平滑、低通锐化;平滑模糊、锐化突出图像细节
(2)滤波器还有带通、带阻等形式
(3)根据噪声(椒盐噪声、高斯噪声…)的不同,选用不同的滤波
(4)邻域有4-邻域、对角邻域、8-邻域,相对应的有邻接,即空间上相邻、像素灰度相似
(5)图像边缘处理:忽略不处理、补充、循环使用
(6)目前尚未图像处理大多基于灰度图像

传统的Retinex算法采用高斯函数作为其环绕函数,将MSR算法中的高斯函数用双边滤波函数代替,双边滤波与高斯滤波相比,可以同时增强空域和时域的平滑性,避免了高斯滤波的误判问题,可以更好地保持图像的边缘信息,使得处理后的图像边缘更加光滑连续,还能在一定程度上解决图像的光晕问题。其中sigma_s取值为[15 70 110],其中sigma_r取值为[0.05 0.10 0.15]。
为了使图像的色彩更加自然,对经过双边滤波处理后的入射分量进行伽马变换,其中C =0.77;Gamma =[0.05 0.1 0.3]。

⛄二、部分源代码

clear all;%clear the values
clc;%clear the command window
tic
strhead = ‘5’;%the name of file
strtail = ‘.bmp’ ;% the format of the file
str = strcat(strhead,strtail);
img = im2double(imread(str));%read the image and convert to double.
N = 15;%the size of filter
sigma = [100 , 0.3];%the parameters of bilateral filter
retimg = bialteral(img , N , sigma );%get the illumination image

subplot(1,3,1);imshow(img);title(‘the original image’);
subplot(1,3,2);imshow(retimg);title(‘the illumination image’);

%% s-l
img_copy = rgb2hsv(img);
img_copy3 = log(img_copy(:,:,3));
retimg_copy = rgb2hsv(retimg);
retimg_copy3 = log(retimg_copy(:,:,3));%only to v layer
r_img = img_copy3 - retimg_copy3;
r_img = exp(r_img);
N = 4;
sigma = [100,0.3];
retinex_img(:,:,3) = bialteral2(r_img,N,sigma);%get reflect image

dim = size(img);
for i = 1:dim(1)
for j = 1:dim(2)
img_copy(i,j,3) = img_copy(i,j,3)^(1/3);
end
end
retinex_img(:,:,3) = retinex_img(:,:,3).*(img_copy(:,:,3));

retinex_img(:,:,1) = img_copy(:,:,1);
retinex_img(:,:,2) = img_copy(:,:,2);
retinex_img = hsv2rgb(retinex_img);
function retimg = bialteral(img ,N ,sigma)
%% colorspace transformation
img = rgb2hsv(img);%convert rgb to hsv colorspace in order to process

%% pre-computer domain filtering
sigma_d = sigma(1);
sigma_r = sigma(2);
[X,Y] = meshgrid(-N:N,-N:N);%generate two matrix
D = exp(-(X.2+Y.2)/(2*sigma_d^2));%domain weights with Euclidean distance

%% create waitbar
h = waitbar(0,‘illumination retinex algorithm……’);
set(h,‘Name’,‘Illumination Retinex’);

%% rang filtering in v layer
dim = size(img);%dim=[height,length,3]
B = zeros(dim);%create an image B with the same size and dimension with the zero value.
for i = 1:dim(1)
for j = 1:dim(2)
iMin = max(i-N,1);
iMax = min(i+N,dim(1));
jMin = max(j-N,1);
jMax = min(j+N,dim(2));
L = img(iMin:iMax,jMin:jMax,3);%extract the local region

    d = L-img(i,j,3);%the dissimilarity between the surroud and center
      
    R = exp(-(d.^2)/(2*sigma_r^2));%range filter weights
            
    F = R.*D((iMin:iMax)-i+N+1,(jMin:jMax)-j+N+1);%its row is from iMin-i+N+1 to iMax-i+N+1,and so as line
    for m = 1:iMax-iMin+1
        for n = 1:jMax-jMin+1
            if d(m,n) < 0
                F(m,n) = 0;
            end
        end
    end
    norm_F = sum(F(:));
    B(i,j,3) = sum(sum(F.*L))/norm_F;

    retimg(i,j,1) = img(i,j,1);
    retimg(i,j,2) = img(i,j,2);
    retimg(i,j,3) = B(i,j,3);
end
waitbar(i/dim(1));

end
close(h);%close the bar

⛄三、运行结果

【图像增强】HSV空间双边滤波图像去雾【含Matlab源码 067期】_第1张图片

⛄四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1]陈龙,郭宝龙,毕娟,朱娟娟.基于联合双边滤波的单幅图像去雾算法[J].北京邮电大学学报. 2012,35(04)

3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除

你可能感兴趣的:(Matlab图像处理(进阶版),matlab,图像处理,计算机视觉)