📄 imageprocessmainunit.~pas
字号:
end;
end;
ChangedBmp.Assign(ProcessedBmp);
ShowChangedBmp;
end;
//////////////////////////////////////////////////////////////
procedure TImageProcessForm.KirshClick(Sender: TObject);
var pu,pm,pd ,p1,p2,p3,p4,p5,p6,p7,p8,p:pbytearray;
x,y:integer;
begin
TestBMP.Assign(WillbeChangedBmp);
ProcessedBmp.Assign(WillbeChangedBmp);
for y:=1 to TestBMP.Height-2 do
begin
p:= ProcessedBmp.ScanLine[y];
p1:= ProcessedBmp.ScanLine[y];
p2:= ProcessedBmp.ScanLine[y];
p3:= ProcessedBmp.ScanLine[y];
p4:= ProcessedBmp.ScanLine[y];
p5:= ProcessedBmp.ScanLine[y];
p6:= ProcessedBmp.ScanLine[y];
p7:= ProcessedBmp.ScanLine[y];
p8:= ProcessedBmp.ScanLine[y];
pu:=TestBMP.ScanLine[y-1];
pm:=TestBMP.ScanLine[y];
pd:=TestBMP.ScanLine[y+1];
for x:=1 to TestBMP.Width-2 do
begin // 1 方向最大值
p1[x*3]:=min(255,max(0,(5*pu[3*(x-1)]+5*pu[3*x]+5*pu[3*(x+1)]
-3*pm[3*(x-1)]-3*pm[3*(x+1)]
-3*pd[3*(x-1)]-3*pu[3*x]-3*pd[3*(x+1)])));
p1[x*3+1]:=min(255,max(0,(5*pu[3*(x-1)+1]+5*pu[3*x+1]+5*pu[3*(x+1)+1]
-3*pm[3*(x-1)+1]-3*pm[3*(x+1)+1]
-3*pd[3*(x-1)+1]-3*pu[3*x]-3*pd[3*(x+1)]+1)));
p1[x*3+2]:=min(255,max(0,(5*pu[3*(x-1)+2]+5*pu[3*x+2]+5*pu[3*(x+1)+2]
-3*pm[3*(x-1)+2]-3*pm[3*(x+1)+2]
-3*pd[3*(x-1)+2]-3*pu[3*x]-3*pd[3*(x+1)+2])));
// 2 方向最大值
p1[x*3]:=min(255,max(0,(-3*pu[3*(x-1)]+5*pu[3*x]+5*pu[3*(x+1)]
-3*pm[3*(x-1)]+5*pm[3*(x+1)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d[3*(x+1)+2])));
// 5 方向最大值
p1[x*3]:=min(255,max(0,(-3*pu[3*(x-1)]-3*pu[3*x]-3*pu[3*(x+1)]
-3*pm[3*(x-1)]-3*pm[3*(x+1)]
+5*pd[3*(x-1)]+5*pu[3*x]+5*pd[3*(x+1)])));
p1[x*3+1]:=min(255,max(0,(-3*pu[3*(x-1)+1]-3*pu[3*x+1]-3*pu[3*(x+1)+1]
-3*pm[3*(x-1)+1]-3*pm[3*(x+1)+1]
+5*pd[3*(x-1)+1]+5*pu[3*x]+5*pd[3*(x+1)]+1)));
p1[x*3+2]:=min(255,max(0,(-3*pu[3*(x-1)+2]-3*pu[3*x+2]-3*pu[3*(x+1)+2]
-3*pm[3*(x-1)+2]-3*pm[3*(x+1)+2]
+5*pd[3*(x-1)+2]+5*pu[3*x]+5*pd[3*(x+1)+2])));
//6 方向最大值
p1[x*3]:=min(255,max(0,(-3*pu[3*(x-1)]-3*pu[3*x]-3*pu[3*(x+1)]
+5*pm[3*(x-1)]-3*pm[3*(x+1)]
+5*pd[3*(x-1)]+5*pu[3*x]-3*pd[3*(x+1)])));
p1[x*3+1]:=min(255,max(0,(-3*pu[3*(x-1)+1]-3*pu[3*x+1]-3*pu[3*(x+1)+1]
+5*pm[3*(x-1)+1]-3*pm[3*(x+1)+1]
+5*pd[3*(x-1)+1]+5*pu[3*x]-3*pd[3*(x+1)]+1)));
p1[x*3+2]:=min(255,max(0,(-3*pu[3*(x-1)+2]-3*pu[3*x+2]-3*pu[3*(x+1)+2]
+5*pm[3*(x-1)+2]-3*pm[3*(x+1)+2]
+5*pd[3*(x-1)+2]+5*pu[3*x]-3*pd[3*(x+1)+2])));
// 7方向最大值
p1[x*3]:=min(255,max(0,(5*pu[3*(x-1)]-3*pu[3*x]-3*pu[3*(x+1)]
+5*pm[3*(x-1)]-3*pm[3*(x+1)]
+5*pd[3*(x-1)]-3*pu[3*x]-3*pd[3*(x+1)])));
p1[x*3+1]:=min(255,max(0,(5*pu[3*(x-1)+1]-3*pu[3*x+1]-3*pu[3*(x+1)+1]
+5*pm[3*(x-1)+1]-3*pm[3*(x+1)+1]
+5*pd[3*(x-1)+1]-3*pu[3*x]-3*pd[3*(x+1)]+1)));
p1[x*3+2]:=min(255,max(0,(5*pu[3*(x-1)+2]-3*pu[3*x+2]-3*pu[3*(x+1)+2]
+5*pm[3*(x-1)+2]-3*pm[3*(x+1)+2]
+5*pd[3*(x-1)+2]-3*pu[3*x]-3*pd[3*(x+1)+2])));
// 8方向最大值
p1[x*3]:=min(255,max(0,(5*pu[3*(x-1)]+5*pu[3*x]-3*pu[3*(x+1)]
+5*pm[3*(x-1)]-3*pm[3*(x+1)]
-3*pd[3*(x-1)]-3*pu[3*x]-3*pd[3*(x+1)])));
p1[x*3+1]:=min(255,max(0,(5*pu[3*(x-1)+1]+5*pu[3*x+1]-3*pu[3*(x+1)+1]
+5*pm[3*(x-1)+1]-3*pm[3*(x+1)+1]
-3*pd[3*(x-1)+1]-3*pu[3*x]-3*pd[3*(x+1)]+1)));
p1[x*3+2]:=min(255,max(0,(5*pu[3*(x-1)+2]+5*pu[3*x+2]-3*pu[3*(x+1)+2]
+5*pm[3*(x-1)+2]-3*pm[3*(x+1)+2]
-3*pd[3*(x-1)+2]-3*pu[3*x]-3*pd[3*(x+1)+2])));
p[x*3]:=max(max(max(max(max(max(max(p1[3*x],p2[3*x]),p3[3*x]),p4[3*x]),p5[3*x]),p6[3*x]),p7[3*x]),p8[3*x]);
p[x*3+1]:=max(max(max(max(max(max(max(p1[3*x+1],p2[3*x+1]),p3[3*x+1]),p4[3*x+1]),p5[3*x+1]),p6[3*x+1]),p7[3*x+1]),p8[3*x+1]);
p[x*3+2]:=max(max(max(max(max(max(max(p1[3*x+2],p2[3*x+2]),p3[3*x+2]),p4[3*x+2]),p5[3*x+2]),p6[3*x+2]),p7[3*x+2]),p8[3*x+2]);
end;
end;
ChangedBmp.Assign(ProcessedBmp);
ShowChangedBmp;
end;
procedure TImageProcessForm.HelpClick(Sender: TObject);
begin
AboutBox.ShowModal;
end;
procedure TImageProcessForm.ToolButton8Click(Sender: TObject);
begin
AboutBox.ShowModal;
end;
procedure TImageProcessForm.AboutClick(Sender: TObject);
begin
AboutBox.ShowModal;
end;
////////////////////////////////////////////////////////////
procedure TImageProcessForm.GaborFilterClick(Sender: TObject);
var//Gabor八方向滤波及综合效果显示
u,v,i,j,p,w,h,d,k,t1:integer;
result,plus,temp5,costemp,sintemp:double;
wwidth,hheight,temp:integer;
angle:array[0..255] of double;
RvalueArray,GvalueArray,BvalueArray:array[0..8]of Integer;
II:array[0..300,0..300] of integer; //图像像素点的灰度值
IX,IY:array [0..300,0..300] of integer;
pline:pbytearray;
begin
progressbar1.Visible:=true;
progressbar1.Max:=256*10;
progressbar1.Min:=0;
progressbar1.Position:=0;
ProcessedBmp.assign(WillbeChangedBmp);
TestBMP.Assign(WillbeChangedBmp);
//确定每个小块的方向
t1:=0;
result:=0;
wwidth:=ProcessedBmp.Width;hheight:=ProcessedBmp.height;
for h:=0 to ProcessedBmp.Width-1
do
begin
pline:=TestBMP.ScanLine[h];
progressbar1.Position:=progressbar1.Position+1;
for w:=0 to ProcessedBmp.Height-1
do
begin
if (w=0)then II[w,h+1]:= pline[3*w];
if (h=0)then II[w+1,h]:=pline[3*w];
if(w=ProcessedBmp.Width-1) then II[w+2,h]:=pline[3*w];
if(h=ProcessedBmp.Height-1) then II[w,h+2]:=pline[3*w];;
II[w+1,h+1]:=pline[3*w];;
end;
II[0,0]:=GetRvalue(ProcessedBmp.Canvas.Pixels[0,0]);
II[0,hheight+1]:=GetRvalue(ProcessedBmp.Canvas.Pixels[0,hheight-1]);
II[wwidth+1,0]:=GetRvalue(ProcessedBmp.canvas.Pixels[wwidth-1,0]);
II[wwidth+1,hheight+1]:=GetRvalue(ProcessedBmp.Canvas.Pixels[wwidth-1,hheight-1]);
end; //对边缘进行扩充
//不同角度Gabor滤波
temp5:=0;costemp:=cos(temp5); sintemp:=sin(temp5);
for h:=0 to ProcessedBmp.height-1 do
begin
progressbar1.Position:=progressbar1.Position+1;
pline:=TestBMP.ScanLine[h];
for w:=0 to ProcessedBmp.width-1 do
begin
if(w>=5) and(h>=5) and(w<=ProcessedBmp.Width-6)
and(h<=ProcessedBmp.Height-6) then
begin
for i:=-5 to 5 do
begin
for j:=-5 to 5 do
begin
plus:=power(i*costemp+j*sin(temp5),2)/9+
power(-i*sin(temp5)+j*costemp,2);
result:=result+(exp(-0.5*plus)*cos(1.0*
(i*costemp +j* sin(temp5) )))*II[w+1-i,h+1-j];
end;
end;
end else
result:=Getrvalue(ProcessedBmp.Canvas.Pixels[w,h]);
if(result>=255) then result:=255;
if(result<0) then result:=0;
pline[3*w+2]:=round(result);
pline[3*w+1]:=round(result);
pline[3*w+0]:=round(result);
result:=0;
GaborShowForm.image1.Picture.Bitmap.Assign(TestBMP);
GaborShowForm.Label1.Caption:='0度滤波图像';
end;
end;
temp5:=(1/8)*pi;costemp:=cos(temp5);sintemp:=sin(temp5);
for h:=0 to ProcessedBmp.height-1 do
begin
progressbar1.Position:=progressbar1.Position+1;
pline:=TestBMP.ScanLine[h];
for w:=0 to ProcessedBmp.Width-1 do
begin
if(w>=5) and(h>=5) and(w<=ProcessedBmp.Width-6) and
(h<=ProcessedBmp.Height-6) then
begin
for i:=-5 to 5 do
begin
for j:=-5 to 5 do
begin
plus:=power(i*costemp+j*sin(temp5),2)/9+
power(-i*sin(temp5)+j*costemp,2);
result:=result+(exp(-0.5*plus)*cos(1.0*(i*costemp +j* sin(temp5) )))
*II[w+1-i,h+1-j];
end;
end;
end else
result:=getrvalue(TestBMP.Canvas.Pixels[w,h]);
if(result>=255) then result:=255;
if(result<0) then result:=0;
pline[3*w+2]:=round(result);
pline[3*w+1]:=round(result);
pline[3*w+0]:=round(result);
GaborShowForm.image2.Picture.Bitmap.Assign(TestBMP);
GaborShowForm.Label2.Caption:='22.5度滤波图像';
end;
end;
temp5:=(1/8)*2*pi;costemp:=cos(temp5);sintemp:=sin(temp5);
for h:=0 to ProcessedBmp.height-1 do
begin
progressbar1.Position:=progressbar1.Position+1;
pline:=TestBMP.ScanLine[h];
for w:=0 to ProcessedBmp.Width-1 do
begin
if(w>=5) and(h>=5) and(w<=ProcessedBmp.Width-6)
and(h<=ProcessedBmp.Height-6) then
begin
for i:=-5 to 5 do
begin
for j:=-5 to 5 do
begin
plus:=power(i*costemp+j*sin(temp5),2)/9+
power(-i*sin(temp5)+j*costemp,2);
result:=result+(exp(-0.5*plus)*cos(1.0*(i*costemp +j* sin(temp5) )))
*II[w+1-i,h+1-j];
end;
end;
end else
result:=getrvalue(TestBMP.Canvas.Pixels[w,h]);
if(result>=255) then result:=255;
if(result<0) then result:=0;
pline[3*w+2]:=round(result);
pline[3*w+1]:=round(result);
pline[3*w+0]:=round(result);
result:=0;
GaborShowForm.image3.Picture.Bitmap.Assign(TestBMP);
GaborShowForm.Label3.Caption:='45度滤波图像';
end;
end;
temp5:=(1/8)*3*pi;costemp:=cos(temp5);sintemp:=sin(temp5);
for h:=0 to ProcessedBmp.height-1 do
begin
progressbar1.Position:=progressbar1.Position+1;
pline:=TestBMP.ScanLine[h];
for w:=0 to ProcessedBmp.Width-1 do
begin
if(w>=5) and(h>=5) and(w<=ProcessedBmp.Width-6)
and(h<=ProcessedBmp.Height-6) then
begin
for i:=-5 to 5 do
begin
for j:=-5 to 5 do
begin
plus:=power(i*costemp+j*sin(temp5),2)/9+
power(-i*sin(temp5)+j*costemp,2);
result:=result+(exp(-0.5*plus)*cos(1.0*(i*costemp +j* sin(temp5) )))*II[w+1-i,h+1-j];
end;
end;
end else
result:=getrvalue(TestBMP.Canvas.Pixels[w,h]);
if(result>=255) then result:=255;
if(result<0) then result:=0;
pline[3*w+2]:=round(result);
pline[3*w+1]:=round(result);
pline[3*w+0]:=round(result);
result:=0;
GaborShowForm.image4.Picture.Bitmap.Assign(TestBMP);
GaborShowForm.Label4.Caption:='67.5度滤波图像';
end;
end;
temp5:=(1/8)*4*pi;costemp:=cos(temp5);sintemp:=sin(temp5);
for h:=0 to ProcessedBmp.height-1 do
begin
progressbar1.Position:=progressbar1.Position+1;
pline:=TestBMP.ScanLine[h];
for w:=0 to ProcessedBmp.Width-1 do
begin
if(w>=5) and(h>=5) and(w<=ProcessedBmp.Width-6)
and(h<=ProcessedBmp.Height-6) then
begin
for i:=-5 to 5 do
begin
for j:=-5 to 5 do
begin
plus:=power(i*costemp+j*sin(temp5),2)/9+
power(-i*sin(temp5)+j*costemp,2);
result:=result+(exp(-0.5*plus)*cos(1.0*
(i*costemp +j* sin(temp5) )))*II[w+1-i,h+1-j];
end;
end;
end else
result:=getrvalue(TestBMP.Canvas.Pixels[w,h]);
if(result>=255) then result:=255;
if(result<0) then result:=0;
pline[3*w+2]:=round(result);
pline[3*w+1]:=round(result);
pline[3*w+0]:=round(result);
result:=0;
GaborShowForm.image5.Picture.Bitmap.Assign(TestBMP);
GaborShowForm.Label5.Caption:='90度滤波图像';
end;
end;
temp5:=(1/8)*5*pi;costemp:=cos(temp5); sintemp:=sin(temp5);
for h:=0 to ProcessedBmp.height-1 do
begin
progressbar1.Position:=progressbar1.Position+1;
pline:=TestBMP.ScanLine[h];
for w:=0 to ProcessedBmp.Width-1 do
begin
if(w>=5) and(h>=5) and(w<=ProcessedBmp.Width-6)
and(h<=ProcessedBmp.Height-6) then
begin
for i:=-5 to 5 do
begin
for j:=-5 to 5 do
begin
plus:=power(i*costemp+j*sin(temp5),2)/9+
power(-i*sin(temp5)+j*costemp,2);
result:=result+(exp(-0.5*plus)*cos(1.0*
(i*costemp +j* sin(temp5) )))*II[w+1-i,h+1-j];
end;
end;
end else
result:=getrvalue(TestBMP.Canvas.Pixels[w,h]);
if(result>=255) then result:=255;
if(result<0) then result:=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -