我正在研究阿拉伯字符的 OCR。我想尝试 glcm 作为特征提取方法。我在这里有代码:http: //www.mathworks.com/matlabcentral/fileexchange/22187-glcm-texture-features
输入图像(字符图像)示例:
我已经编写了一个代码来根据需要的功能获取 GLCM 输出。这里是:
function features = EkstraksiFitur_GLCM(x)
glcm = graycomatrix(x,'offset',[0 1; -1 1; -1 0; -1 -1], 'NumLevels', 2);
stats = GLCM_Features1(glcm, 0);
autocorrelation = double(mean (stats.autoc));
if isnan(autocorrelation)
autocorrelation=0;
else
autocorrelation=autocorrelation;
end
contrast = double(mean(stats.contr));
if isnan(contrast)
contrast=0;
else
contrast=contrast;
end
Correlation = double(mean (stats.corrm));
if isnan(Correlation)
Correlation=0;
else
Correlation=Correlation;
end
ClusterProminence = double(mean (stats.cprom));
if isnan(ClusterProminence)
ClusterProminence=0;
else
ClusterProminence=ClusterProminence;
end
ClusterShade = double(mean (stats.cshad));
if isnan(ClusterShade)
ClusterShade=0;
else
ClusterShade=ClusterShade;
end
Dissimilarity = double(mean (stats.dissi));
if isnan(Dissimilarity)
Dissimilarity=0;
else
Dissimilarity=Dissimilarity;
end
Energy = double(mean (stats.energ));
if isnan(Energy)
Energy=0;
else
Energy=Energy;
end
.
.
.
features=[autocorrelation, contrast, Correlation, Dissimilarity, Energy, Entropy, Homogeneity, MaximumProbability, SumAverage, SumVariance, SumEntropy, DifferenceVariance, DifferenceEntropy, InverseDifferenceMomentNormalized];
使用循环获取所有图像的特征(数据训练):
srcFile = dir('D:\1. Thesis FINISH!!!\Data set\0 Well Segmented Character\Advertising Bold 24\datatrain\*.png');
fetrain = [];
for a = 1:length(srcFile)
file_name = strcat('D:\1. Thesis FINISH!!!\Data set\0 Well Segmented Character\Advertising Bold 24\datatrain\',srcFile(b).name);
A = imread(file_name);
[gl] = EkstraksiFitur_GLCM2 (A);
[fiturtrain] = reshape (gl, [56,1]) ;
fetrain = [fetrain fiturtrain];
% vectorname = strcat(file_name,'_array.mat');
end
save ('fetrain.mat','fetrain');
我有这些功能。
然后使用神经网络运行训练过程,但我得到的准确率非常低。这是代码:
% clc;clear;close all;
% function net1 = pelatihan (input, target)
net = newff(fetrain,target,[10 2],{'tansig','tansig'},'trainscg');
% net.trainParam.mem_reduc = 2;
net.performFcn = 'mse';
net.divideFcn = 'dividetrain';
% [trainInd,valInd,testInd] = dividetrain(601);
net.trainParam.show = 10; % Frequency of progress displays (in epochs).
net.trainParam.epochs = 1000; %default 1000
net.trainParam.goal = 1e-6;
net = train(net,fetrain,target);
output = round(sim(net,fetrain));
save net1.mat net
% net2 = output;
data = fetest;
[target; output];
prediksi = round(sim (net, data));
[targetx; prediksi];
%% Calculate the accuracy %
y = 1;
j = size (prediksi, 2);
% x = size (targetx, 2);
for i = 1:j
if prediksi (i) == targetx (i)
y =y+1;
else
y;
end
end
% y all correct data
% j all data
s = 'The accuracy is %.2f%%';
acc = 100 *(y/j);
sprintf (s,acc)
我试了几次,但准确率(NN测试结果)没有提高。它持续提供 1.96% 的输出。流程是否有问题,或者我制作的代码有问题?
任何帮助都会非常有帮助和感激