📋1 概述
在彩色图像处理中,彩色图像压缩存储和传输是研究的热点之一。量化技术是24位或更高位真彩色图像压缩处理的关键技术之一,而借鉴模式识别中的聚类分析是一类较好的的量化方法,即用聚类算法将相近的颜色值分为一组,再使用一个颜色值替换它们。迄今为止,人们已经提出了许多聚类量化算法,有K-均值算法、LBG算法、模糊C均值算法、FORGY 算法、ISODATA 算法等[1-2],其目标是使量化前后两者之间的差异尽可能小,换言之就是以最小失真减小图像颜色数目。从结果上看,尽管这些方法均能得到满意的量化效果,但由于它们对初始聚类中心的选择比较敏感,不同的初始聚类中心往往会得到不同的聚类结果,继而在重建彩色图像时很可能会导致严重的失真。
本文基于文化优化算法图像量化,用Matlab代码实现。
📝2 运行结果
部分代码:
I = imread('eva.jpg');
% Convert To Gray
I=rgb2gray(I);
% Basic Multilevel Image Thresholds Using Otsu鐥� Method
Data = multithresh(I,thresholdlvl);
Data=Data';
Data=double(Data);
% Creating Inputs and Targets
Delays = [1];
[Inputs, Targets] = MakeTheTimeSeries(Data',Delays);
data.Inputs=Inputs;
data.Targets=Targets;
% Making Data
Inputs=data.Inputs';
Targets=data.Targets';
Targets=Targets(:,1);
nSample=size(Inputs,1);
% Creating Train Vector
pTrain=1.0;
nTrain=round(pTrain*nSample);
TrainInputs=Inputs(1:nTrain,:);
TrainTargets=Targets(1:nTrain,:);
TestInputs=Inputs(nTrain+1:end,:);
TestTargets=Targets(nTrain+1:end,:);
% Making Final Data Struct
data.TrainInputs=TrainInputs;
data.TrainTargets=TrainTargets;
data.TestInputs=TestInputs;
data.TestTargets=TestTargets;
%% Basic Fuzzy Model Creation
% Number of Clusters in FCM
ClusNum=2;
%
% Creating FIS
fis=GenerateFuzzy(data,ClusNum);
%% Tarining Cultural Algorithm
CulturalAlgorithmFis = CulturalFCN(fis,data);
%% Train Output Extraction
TrTar=data.TrainTargets;
TrainOutputs=evalfis(data.TrainInputs,CulturalAlgorithmFis);
% Train calculation
Errors=data.TrainTargets-TrainOutputs;
r0 = -1 ;
r1 = +1 ;
range = max(Errors) - min(Errors);
Errors = (Errors - min(Errors)) / range;
range2 = r1-r0;
Errors = (Errors * range2) + r0;
MSE=mean(Errors.^2);
RMSE=sqrt(MSE);
error_mean=mean(Errors);
error_std=std(Errors);
%% Results
% Basic Image Quantization
seg_I = imquantize(I,Data);
RGB = label2rgb(seg_I);
% Cultural Algorithm Image Quantization
TrainOutputs(thresholdlvl)=TrainOutputs(end)+1;
TrainOutputs=sort(TrainOutputs);
seg_I2 = imquantize(I,TrainOutputs);
RGB2 = label2rgb(seg_I2);
% Plot Results
figure('units','normalized','outerposition',[0 0 1 1])
subplot(2,2,1)
subimage(I); title('Original Eva');
subplot(2,2,2)
subimage(RGB);title('Basic Quantization');
subplot(2,2,3)
subimage(RGB2);title('Cultural Algorithm Quantization');
subplot(2,2,4)
imhist(rgb2gray(RGB2));title('Cultural Algorithm Image Histogram');
%% Cultural Algorithm Image Quantization Performance Statistics
fprintf('Cultural Algorithm MSE Is = %0.4f.\n',MSE)
fprintf('Cultural Algorithm RMSE Is = %0.4f.\n',RMSE)
fprintf('Cultural Algorithm Train Error Mean Is = %0.4f.\n',error_mean)
fprintf('Cultural Algorithm Train Error STD Is = %0.4f.\n',error_std)
📃3 参考文献
[1]许永峰,姜振益.一种基于粒子群优化的K-均值彩色图像量化算法[J].西北大学学报:自然科学版,2012,42(3):351-354
[2]Seyed Muhammad Hossein Mousavi (2022). Cultural Algorithm Image Quantization