📄 graycurrencematrix.pas
字号:
Pattern[LiverType].FeatrueValue[k][i][j]:=StrToFloat(Item[j+1]);
end;
end;
end;
end;
end;
CloseFile(PatternFile);//关闭模板文件
Finally
end;
end;
////////////////////////////////////////////////////////////////////////////////
function GetSubStr(var aString:String;SepChar:String):String;
var//得到分隔字符的子程序
SingleChar:String;
StrLen:Integer;
SepCharPos:Integer;
begin
StrLen:=Length(aString);
SepCharPos:=Pos(SepChar,aString); //计算分割符在子串中的位置
SingleChar:=Copy(aString,1,SepCharPos-1); //将分割符前所有字符放到SingleChar串中
Delete(aString,1,SepCharPos); //除去分割符和分割符前的子串
GetSubStr:=SingleChar; //返回一个字段
end;
///////////////////////////////////////////////////////////////////////////////////////
function GetSubStrNum(aString:String;SepChar:String):integer;
var//得到一行中分隔字符个数的子程序
i:Integer;
StrLen:Integer;
Num:Integer;
begin
StrLen:=Length(aString);
Num:=0;
For i:=1 to StrLen do
If Copy(aString,i,1) = SepChar then
Num:=Num+1;
result:=Num;
end;
////////////////////////////////////////////////////////////////////////////////
function NormalizeTexture():double;///////////只对O度的特征值进行了比较/////
var //特征归一化函数
i,k,LiverType,TotalNum:integer;
temp,temp1,t:double;
begin
for i:=0 to 2 do
for k:=0 to 4 do
begin
M[i][k]:=0.0;
Sgm1[i][k]:=0.0;
end;
for k:=0 to 4 do
begin
t1[k]:=0.0;
t2[k]:=0.0;
end;
temp:=0.0;TotalNum:=0;temp1:=0.0;Sgm:=0.0;
for LiverType:=0 to 2 do
for i:=0 to 4 do
begin
if pattern[LiverType].num <> 0 then
begin
// temp:=0.0;
for k:=1 to Pattern[LiverType].num do
temp:=temp+Pattern[LiverType].FeatrueValue[k][0][i];
end;
M[LiverType][i]:=temp;///Pattern[LiverType].num;
end;
for i:=0 to 4 do
for k:=0 to 2 do
t1[i]:=t1[i]+M[k][i];
for LiverType:=0 to 2 do
TotalNum:=TotalNum+Pattern[LiverType].num;
for i:=0 to 4 do
t1[i]:=t1[i]/TotalNum;
for LiverType:=0 to 2 do
for i:=0 to 4 do
begin
if pattern[LiverType].num <> 0 then
begin
// temp1:=0.0;
for k:=1 to Pattern[LiverType].num do
t:=(Pattern[LiverType].FeatrueValue[k][0][i]-t1[i])*
(Pattern[LiverType].FeatrueValue[k][0][i]-t1[i]);
temp1:=temp1+t;
end;
Sgm1[LiverType][i]:=temp1;
end;
for i:=0 to 4 do
for k:=0 to 2 do
t2[i]:=t2[i]+Sgm1[k][i];
//for LiverType:=0 to 2 do
// TotalNum:=TotalNum+Pattern[LiverType].num;
for i:=0 to 4 do
Sgm:=Sgm+t2[i];
Sgm:=Sqrt(Sgm/TotalNum);
end;
function FeatureCompareResult():double;
var
i,j,LiverType:integer;
b1,b2,b3,b4,b5,temp:double;
y1,y2,y3,y4,y5:double;
t11,t22,t33,t44,t55:double;
max:double;
LiverClass,PatternId:integer;
begin
max:=1000000;
for LiverType:=0 to 2 do
begin
for i:=1 to Pattern[LiverType].num do
begin
begin
y1:=(Pattern[LiverType].FeatrueValue[i][0][0]- t1[i])/(Sgm+0.000001);
b1:=(FeatureEnergy- t1[i])/(Sgm+0.000001);
y2:=(Pattern[LiverType].FeatrueValue[i][0][1]- t1[i])/(Sgm+0.000001);
b2:=(FeatureEntropy- t1[i])/(Sgm+0.000001);
y3:=(Pattern[LiverType].FeatrueValue[i][0][2]- t1[i])/(Sgm+0.000001);
b3:=(FeatureCorrelation- t1[i])/(Sgm+0.000001);
y4:=(Pattern[LiverType].FeatrueValue[i][0][3]- t1[i])/(Sgm+0.000001);
b4:=(FeatureInertiaQuadrature- t1[i])/(Sgm+0.000001);
y5:=(Pattern[LiverType].FeatrueValue[i][0][4]- t1[i])/(Sgm+0.000001);
b5:=(FeatureLocalCalm- t1[i])/(Sgm+0.000001);
t11:=(y1-b1)*(y1-b1);
t22:=(y2-b2)*(y2-b2);
t33:=(y3-b3)*(y3-b3);
t44:=(y4-b4)*(y4-b4);
t55:=(y5-b5)*(y5-b5);
temp:=Sqrt(t11+t22+t33+t44+t55);
end;
if temp<max then
begin
max:=temp;
LiverClass:=LiverType;
PatternId:=i;
end;
end;
end;
LiverTextureRecForm.RecLiverKindEdit.Text:= inttostr(LiverClass);
LiverTextureRecForm.RecLiverKindIdEdit.Text:= inttostr(PatternId);
if LiverTextureRecForm.RecLiverKindEdit.Text='0' then
LiverTextureRecForm.HealthLiverRadioButton.Checked:=true;
if LiverTextureRecForm.RecLiverKindEdit.Text='1' then
LiverTextureRecForm.FattyLiverRadioButton.Checked:=true;
if LiverTextureRecForm.RecLiverKindEdit.Text='2' then
LiverTextureRecForm.CirrhosisRadioButton.Checked:=true;
end;
///////////////////////////////////////////////////////
function LMSE():integer;
Var //LMSE肝脏组织分类算法程序
d:array [0..2] of double;
X_Property:array [1..21] of double;
hx:array [0..2] of double;
w:array [0..2,1..21] of double;
PropertyOfInputDigital:array [1..21] of double;
TempMaxValue,rX:double;
HaveError_Flag,Dmax_Flag:bool;
LiverType,i,j,k,l,RecogNumber:Integer;
TatalPatternNum,IteriationTime,jj,ii:integer;
begin
for LiverType:=0 to 2 do //设权值初值
for i:=1 to 21 do
w[LiverType][i]:=0;
TatalPatternNum:=1;
for IteriationTime:=0 to 1000 do//最多迭代次数
begin //得到线性判别函数权的各矢量
HaveError_Flag:=true;
for LiverType:=0 to 2 do //肝脏类别0-2 的各模板的特征
begin
for i:=1 to Pattern[LiverType].Num do //每种类别的各模板
begin //取4*5特征
for l:=1 to 4 do
for k:=1 to 5 do
X_Property[5*(l-1)+k]:=abs(Pattern[LiverType].FeatrueValue[i][L-1][k-1]);
X_Property[21]:=1;//矩阵行末位设为1
for j:=0 to 2 do //计算新的权矢量
d[j]:=0;
for j:=0 to 2 do
for k:=1 to 21 do
d[j]:=d[j]+w[j][k]*X_Property[k];
Dmax_Flag:=true;
for j:=0 to 2 do
begin
if(j<>LiverType) then
begin
if (d[LiverType]>d[j]) then Dmax_Flag:=true
else Dmax_Flag:=false;
end;
end;
if(Dmax_Flag=true) then //如果d[n]为最大值
HaveError_Flag:=true
else
HaveError_Flag:=false;
for j:=0 to 2 do //修改三种肝脏的新的权值
begin
if(j=LiverType) then //属于当前类别的情况
rX:=1.0
else //不属于当前类别的情况
rX:=0.0;
for k:=1 to 21 do //每类用21个样本
w[j][k]:=w[j][k]+X_Property[k]*(rX-d[j])/TatalPatternNum;
end;
TatalPatternNum:=TatalPatternNum+1;
end; // 对应于每个数字的各模板特征循环
end;// 对应于每个数字的循环
if HaveError_Flag=false then break;//达到拟合精度要求
end; //对应于迭代过程
PropertyOfInputDigital[1]:=strtofloat(LiverTextureRecForm.EnergyEdit.text);
PropertyOfInputDigital[2]:=strtofloat(LiverTextureRecForm.EntropyEdit.text);
PropertyOfInputDigital[3]:=abs(strtofloat(LiverTextureRecForm.CorrelationEdit.text));
PropertyOfInputDigital[4]:=strtofloat(LiverTextureRecForm.InertiaQuadratureEdit.text);
PropertyOfInputDigital[5]:=strtofloat(LiverTextureRecForm.LocalCalmEdit.text);
PropertyOfInputDigital[6]:=strtofloat(LiverTextureRecForm.EnergyVEdit.text);
PropertyOfInputDigital[7]:=strtofloat(LiverTextureRecForm.EntropyVEdit.text);
PropertyOfInputDigital[8]:=abs(strtofloat(LiverTextureRecForm.CorrelationVEdit.text));
PropertyOfInputDigital[9]:=strtofloat(LiverTextureRecForm.InertiaQuadratureVEdit.text);
PropertyOfInputDigital[10]:=strtofloat(LiverTextureRecForm.LocalCalmVEdit.text);
PropertyOfInputDigital[11]:=strtofloat(LiverTextureRecForm.EnergyRDEdit.text);
PropertyOfInputDigital[12]:=strtofloat(LiverTextureRecForm.EntropyRDEdit.text);
PropertyOfInputDigital[13]:=abs(strtofloat(LiverTextureRecForm.CorrelationRDEdit.text));
PropertyOfInputDigital[14]:=strtofloat(LiverTextureRecForm.InertiaQuadratureRDEdit.text);
PropertyOfInputDigital[15]:=strtofloat(LiverTextureRecForm.LocalCalmLDEdit.text);
PropertyOfInputDigital[16]:=strtofloat(LiverTextureRecForm.EnergyLDEdit.text);
PropertyOfInputDigital[17]:=strtofloat(LiverTextureRecForm.EntropyLDEdit.text);
PropertyOfInputDigital[18]:=abs(strtofloat(LiverTextureRecForm.CorrelationLDEdit.text));
PropertyOfInputDigital[19]:=strtofloat(LiverTextureRecForm.InertiaQuadratureLDEdit.text);
PropertyOfInputDigital[20]:=strtofloat(LiverTextureRecForm.LocalCalmRDEdit.text);
PropertyOfInputDigital[21]:=1;//矩阵行末位设为1
for LiverType:=0 to 2 do
begin
hx[LiverType]:=0.0;
for i:=1 to 21 do
hx[LiverType]:=hx[LiverType]
+w[LiverType][i]*PropertyOfInputDigital[i];
end; //取判别函数最大值所对应的类为识别结果
TempMaxValue:=hx[0];
RecogNumber:=0;
for LiverType:=0 to 2 do
begin
if(hx[LiverType]>TempMaxValue) then
begin
TempMaxValue:=hx[LiverType];
RecogNumber:=LiverType;
end;
end;
LiverTextureRecForm.RecLiverKindEdit.Text:= IntToStr(RecogNumber);
LiverTextureRecForm.RecLiverKindIdEdit.Text:='';
if LiverTextureRecForm.RecLiverKindEdit.Text='0' then //分类为正常肝
LiverTextureRecForm.HealthLiverRadioButton.Checked:=true;
if LiverTextureRecForm.RecLiverKindEdit.Text='1' then //分类为脂肪肝
LiverTextureRecForm.FattyLiverRadioButton.Checked:=true;
if LiverTextureRecForm.RecLiverKindEdit.Text='2' then //分类为肝硬化
LiverTextureRecForm.CirrhosisRadioButton.Checked:=true;
result:=RecogNumber;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -