%% PSO_ACE % date: 2020_08 % Author: X % function: 图像增强,(1) PSO优化ACE增益因子 (2) 引导滤波降噪 %% 初始化 addpath(genpath(pwd)); clear; clc; close all; warning('off') %% 定义全局变量 global meanimg stdimg I img I = rgb2ycbcr(imread('test2.jpg'));% 将图片转换到ycbcr空间 img = double(I(:,:,1)); % 求局部均值 filter = fspecial('average',3); meanimg = imfilter(img,filter); % figure;imshow(meanimg/255,[]); % 求局部标准差 stdimg = stdfilt(img); % temp = stdfilt(img(:,:,1)); %% PSO 寻优 a_range=[0,1]; % 参数x变化范围(这里寻优的是ACE算法中的增益因子a) range = [a_range]; Max_V = 0.2*(a_range(:,2)-a_range(:,1)); % 最大速度取变化范围的10%~20% n=1; % 待优化函数的维数 psoparams = [10 200 10 2 2 0.8 0.2 1500 1e-25 200 NaN 0 0]; % 参数配置,详细查看pso工具箱使用文档 Bestarray = pso_Trelea_vectorized('obj_func', n, Max_V, range, 1, psoparams); % 调用PSO寻优,返回最优参数以及最优函数值 %% 输出增强后的图像(将获得增益因子代入ACE) D = mean(meanimg(:)); c = Bestarray(1)*D./(stdimg); c(c>10) = 3; result = meanimg + c.*(img - meanimg); MIN = min(min(result)); MAX = max(max(result)); result = (result - MIN)/(MAX - MIN); result = adapthisteq(result); I(:,:,1) = result*255; result_img = ycbcr2rgb(I); figure;imshow(result_img); title('PSO\_ACE'); %% 引导滤波降噪 [r,c,b]=size(I); x = reshape(result_img,[r*c b]); x = compute_mapping(x,'PCA',1); % 对原图进行PCA降维 guidance = reshape(x, r, c)/255; % 获得引导图像 result_img = double(result_img)/255; r = 5; % 滤波半径 eps = 0.005; % 滤波正则化参数 for i = 1:3 result_img_GD(:,:,i) = guidedfilter(guidance, result_img(:,:,i), r, eps); % 引导滤波 end figure;imshow(result_img_GD,[]); title('PSO\_ACE\_GD'); % 显示滤波后的图像