⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diedai.txt

📁 迭代法是基于逼近的思想
💻 TXT
字号:
迭代法
迭代法是基于逼近的思想,其步骤如下:
1. 求出图象的最大灰度值和最小灰度值,分别记为ZMAX和ZMIN,令初始阈值T0=(ZMAX+ZMIN)/2;
2. 根据阈值TK将图象分割为前景和背景,分别求出两者的平均灰度值ZO和ZB;
3. 求出新阈值TK+1=(ZO+Z/2;
4. 若TK=TK+1,则所得即为阈值;否则转2,迭代计算。
以下给出迭代求阈值的部分实现:
//阈值初始为0
intThresholdVal:=0;
  intThresholdVal2:=0;

//总灰度值
intTotalGrayLevel:=0;
for intLoop:=0 to 255 do
if intGrayLevel[intLoop]<>0 then
intTotalGrayLevel:=intTotalGrayLevel+intLoop*intGrayLevel[intLoop];

//求出初始最大灰度值
for intLoop:=0 to 255 do
if intGrayLevel[intLoop]>0 then
begin
intLGrayLevel:=intLoop;
intThresholdVal:=intLoop;
break;
end;

//求出初始最小灰度值和初始阈值
for intLoop:=255 downto 0 do
if intGrayLevel[intLoop]>0 then
begin
intRGrayLevel:=intLoop;
intThresholdVal:=(intThresholdVal+intLoop)div 2;
break;
end;

//迭代求解
while intThresholdVal<>intThresholdVal2 do
begin
intThresholdVal2:=intThresholdVal;
intCount:=0;
intLGrayLevel:=0;
for intLoop:=0 to intThresholdVal do
if intGrayLevel[intLoop]<>0 then
begin
intCount:=intCount+intGrayLevel[intLoop];
intLGrayLevel:=intLGrayLevel+intLoop*intGrayLevel[intLoop];
end;
intRGrayLevel:=intTotalGrayLevel-intLGrayLevel;
intLGrayLevel:=intLGrayLevel div intCount;
intRGrayLevel:=intRGrayLevel div (intSize-intCount);
intThresholdVal:=(intLGrayLevel+intRGrayLevel)div 2;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -