I = imread('C:\Users\shou\Desktop\061tongtai.jpg');
tic;
R = I(:, :, 1);
G = I(:, :, 2);
B = I(:, :, 3);
R0 = double(R);
G0 = double(G);
B0 = double(B);
[N1, M1] = size(R);
Rlog = log(R0+1);%增强原理第一步取对数
Rfft2 = fft2(R0);%进行二维傅里叶变换,将R通道分量由空间域变为频率域
%sigma1 = 128;
sigma1 = 2800;
F1 = fspecial('gaussian', [N1,M1], sigma1);%高斯低通滤波,有两个参数,hsize表示模板尺寸,默认值为【3 3】,sigma为滤波器的标准值,单位为像素,默认值为0.5.
%F1 = fspecial('unsharp', 0.2); F1为一个二维滤波器
Efft1 = fft2(double(F1));%进行傅里叶变换,将滤波器F1由空间域变为频率域
%第二步高斯模板对原图像作卷积,即相当于对原图像作低通滤波,得到低通滤波后的图像D(x,y)
DR0 = Rfft2.* Efft1; %R分量和滤波器进行点乘
DR = ifft2(DR0);%进行傅里叶反变换,将频率域变为空间域
%第三步在对数域中,用原图像减去低通滤波后的图像,得到高频增强的图像G(x,y)=S’(x,y)-log(D(x,y))
DRlog = log(DR +1);
Rr1 = Rlog - DRlog;
sigma2 = 256;
%sigma2 = 2500;
F2 = fspecial('gaussian', [N1,M1], sigma2);
Efft2 = fft2(double(F2));
DR0 = Rfft2.* Efft2;
DR = ifft2(DR0);
DRlog = log(DR +1);
Rr2 = Rlog - DRlog;
sigma3 = 512;
%sigma3 = 5100;
F3 = fspecial('gaussian', [N1,M1], sigma3);
Efft3 = fft2(double(F3));
DR0 = Rfft2.* Efft3;
DR = ifft2(DR0);
DRlog = log(DR +1);
Rr3 = Rlog - DRlog;
Rr = (Rr1 + Rr2 +Rr3)/3;
%a = 125;
a = 15;
II = imadd(R0, G0);
II = imadd(II, B0);
Ir = immultiply(R0, a);
%定义彩色恢复因子C
C = imdivide(Ir, II);
C = log(C+1);
% 将增强的分量乘以色彩恢复因子
Rr = immultiply(C, Rr);
%第四步对G(x,y)取反对数,得到增强后的图像R(x,y)=exp(G(x,y))
EXPRr = exp(Rr);
%第五步对R(x,y)作对比度增强,得到最终的结果图像。
MIN = min(min(EXPRr));
MAX = max(max(EXPRr));
EXPRr = (EXPRr - MIN)/(MAX - MIN);
EXPRr = adapthisteq(EXPRr);
% G通道处理
Glog = log(G0+1);
Gfft2 = fft2(G0);
DG0 = Gfft2.* Efft1;
DG = ifft2(DG0);
DGlog = log(DG +1);
Gg1 = Glog - DGlog;
DG0 = Gfft2.* Efft2;
DG = ifft2(DG0);
DGlog = log(DG +1);
Gg2 = Glog - DGlog;
DG0 = Gfft2.* Efft3;
DG = ifft2(DG0);
DGlog = log(DG +1);
Gg3 = Glog - DGlog;
Gg = (Gg1 + Gg2 +Gg3)/3;
Ig = immultiply(G0, a);
C = imdivide(Ig, II);
C = log(C+1);
Gg = immultiply(C, Gg);
EXPGg = exp(Gg);
MIN = min(min(EXPGg));
MAX = max(max(EXPGg));
EXPGg = (EXPGg - MIN)/(MAX - MIN);
EXPGg = adapthisteq(EXPGg);
%B通道处理
Blog = log(B0+1);
Bfft2 = fft2(B0);
DB0 = Bfft2.* Efft1;
DB = ifft2(DB0);
DBlog = log(DB +1);
Bb1 = Blog - DBlog;
DB0 = Bfft2.* Efft2;
DB = ifft2(DB0);
DBlog = log(DB +1);
Bb2 = Blog - DBlog;
DB0 = Bfft2.* Efft3;
DB = ifft2(DB0);
DBlog = log(DB +1);
Bb3 = Blog - DBlog;
Bb = (Bb1 + Bb2 +Bb3)/3;
Ib = immultiply(B0, a);
C = imdivide(Ib, II);
C = log(C+1);
Bb = immultiply(C, Bb);
EXPBb = exp(Bb);
MIN = min(min(EXPBb));
MAX = max(max(EXPBb));
EXPBb = (EXPBb - MIN)/(MAX - MIN);
EXPBb = adapthisteq(EXPBb);
result = cat(3, EXPRr, EXPGg, EXPBb);
toc;
figure();
imshow(I),title('原图');
figure();
imshow(result),title('增强图');
imwrite(result,'C:\Users\shou\Desktop\061to.jpg')
*文*
- 粉丝: 6
- 资源: 5
最新资源
- 发那科系统整套梯形图设计 FANUC全套PMC设计 发那科标 准PLC 完美解决方案 ##带中文解释## 内容很全 请仔细看完: 1.刀库程序设计(斗笠 圆盘 夹臂 机械手 伞型 都包
- stm32 gd32爱玛电动车控制器资料 电动车控制器原理图、PCB和程序 大厂成熟电机foc控制 送eg89m52的原理图和pcb
- 基于Go语言的现代化开源K8s面板——1Panel官方出品KubePi设计源码
- 基于JavaScript的Sewise Player网页HTML5视频播放器设计源码
- 小神农V7(修复眼镜).zip
- 基于Vue框架的银行科技岗AI云账户系统前端设计源码
- Screenshot_2025-01-15-00-13-41-471_com.tencent.mtt.jpg
- Screenshot_2025-01-15-00-08-47-906_com.tencent.mobileqq.jpg
- 250467c518b0a66217a647d11a6a9c831736870765675.jpg
- 基于Tcl语言的GNU TeXmacs插件集合设计源码
- Screenshot_2025-01-15-00-04-33-283_com.kuaishou.nebula.jpg
- 基于Vue框架的easy-send局域网文本文件共享小工具设计源码
- 基于JavaScript和微信小程序技术的钓场信息预约与管理小程序设计源码
- PSO-RBF和RBF粒子群优化径向基神经网络多输入多输出预测(Matlab完整源码和数据)
- 三菱fx3u+485ADP-MB与3台台达变频器modbus通讯程序 功能:通过三菱fx3u 485ADP-MB板对3台台达变频器进行modbus通讯,实现频率设定,启停控制,输出频率读取,输出电压读
- 除尘程序 写的FB块了,可以直接调用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈