文章目录
处理图片:
代码:
clear all clc %参数声明 rH = 1; rL = 0.1; c = 0.2;%介于rH和rL之间 D0 = 0.2; image = imread('3.bmp'); [M, N] = size(image); %取对数 img_log = log(double(image) + 1); %平移到中心,判断语句代替指数计算 img_py = zeros(M, N); for i = 1:M for j= 1:N if mod(i+j, 2) == 0 img_py(i,j) = img_log(i, j); else img_py(i,j) = -1 * img_log(i, j); end end end % 对填充后的图像进行傅里叶变换 img_py_fft = fft2(img_py); %同态滤波函数 img_tt = zeros(M, N); deta_r = rH - rL; D = D0^2; m_mid=floor(M/2);%中心点坐标 n_mid=floor(N/2); for i = 1:M for j =1:N dis = ((i-m_mid)^2+(j-n_mid)^2); img_tt(i, j) = deta_r * (1-exp((-c)*(dis/D))) + rL; end end %滤波 img_temp = img_py_fft.*img_tt; %反变换,取实部,绝对值 img_temp = abs(real(ifft2(img_temp))); %指数化 img_temp = exp(img_temp) - 1; %归一化处理 max_num = max(img_temp(:)); min_num = min(img_temp(:)); range = max_num - min_num; img_after = zeros(M,N,'uint8'); for i = 1 : M for j = 1 : N img_after(i,j) = uint8(255 * (img_temp(i, j)-min_num) / range); end end figure imshow(image), title('原图像'); figure imshow(img_after), title('变换后'); imwrite(img_after,'同态滤波.png');
运行: