您的当前位置:首页正文

sobeL 算子

2020-09-30 来源:好走旅游网


计算机图形学 课程设计报告

班 级: 计算机科学与技术 学 号: 姓 名: 成 绩:

电子与信息工程学院计算机系

一.设计目的与要求 使用Sobel算子实现图像边缘提取,选题同学自己拍摄一副图片,进行处理。 二.软件功能模块图 三.软件各模块功能介绍 四.程序代码清单(部分) 1、Robert算子 procedure TImageProcessForm.RobertClick(Sender: TObject); var//Robert边缘检测程序 x,y:integer; P,p1,p2:pbytearray; begin TestBMP.Assign(WillbeChangedBmp); ProcessedBmp.Assign(WillbeChangedBmp); for y:=0 to TestBMP.Height-2 do begin p:=ProcessedBmp.ScanLine[y]; p1:=TestBMP.ScanLine[y]; p2:=TestBMP.ScanLine[y+1]; for x:=0 to TestBMP.Width-2 do begin p[3*x]:=max(0,max(-p1[3*(x+1)]+p2[3*x], p1[3*x]-p2[3*(x+1)])); p[3*x+1]:=max(0,max(-p1[3*(x+1)+1]+p2[3*x+1], p1[3*x+1]-p2[3*(x+1)+1])); p[3*x+2]:=max(0,max(-p1[3*(x+1)+2]+p2[3*x+2], p1[3*x+2]-p2[3*(x+1)+2])); end; end; ChangedBmp.Assign(ProcessedBmp); ShowChangedBmp; end; 2、Kirsch 算子 procedure TImageProcessForm.KirschClick(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];

— 1 —

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)] -3*pd[3*(x-1)]-3*pu[3*x]-3*pd[3*(x+1)]))); p1[x*3+1]:=min(255,max(0,(-3*pu[3*(x-1)+1]+5*pu[3*x+1]+5*pu[3*(x+1)+1] -3*pm[3*(x-1)+1]+5*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,(-3*pu[3*(x-1)+2]+5*pu[3*x+2]+5*pu[3*(x+1)+2] -3*pm[3*(x-1)+2]+5*pm[3*(x+1)+2] -3*pd[3*(x-1)+2]-3*pu[3*x]-3*pd[3*(x+1)+2]))); // 3 方向最大值 p1[x*3]:=min(255,max(0,(-3*pu[3*(x-1)]-3*pu[3*x]+5*pu[3*(x+1)] -3*pm[3*(x-1)]+5*pm[3*(x+1)] -3*pd[3*(x-1)]-3*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]+5*pu[3*(x+1)+1] -3*pm[3*(x-1)+1]+5*pm[3*(x+1)+1] -3*pd[3*(x-1)+1]-3*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]+5*pu[3*(x+1)+2] -3*pm[3*(x-1)+2]+5*pm[3*(x+1)+2] -3*pd[3*(x-1)+2]-3*pu[3*x]+5*pd[3*(x+1)+2]))); // 4 方向最大值 p1[x*3]:=min(255,max(0,(-pu[3*(x-1)]-pu[3*x]-pu[3*(x+1)] +pd[3*(x-1)]+pu[3*x]+pd[3*(x+1)]))); p1[x*3+1]:=min(255,max(0,(-pu[3*(x-1)+1]-pu[3*x+1]-pu[3*(x+1)+1] +pd[3*(x-1)+1]+pu[3*x]+pd[3*(x+1)]+1))); p1[x*3+2]:=min(255,max(0,(-pu[3*(x-1)+2]-pu[3*x+2]-pu[3*(x+1)+2] +pd[3*(x-1)+2]+pu[3*x]+pd[3*(x+1)+2])));

— 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*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))); 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

— 3 —

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 end; end; ChangedBmp.Assign(ProcessedBmp); ShowChangedBmp; end; 五.程序生成界面图形(部分) Roberts边缘算子效果图: Sobel边缘检测算子 Prewitt边缘检测算子

— 4 —

Kirsch边缘检测算子 拉普拉斯算子 高斯拉普拉斯算子

— 5 —

六.参考文献

— 6 —

因篇幅问题不能全部显示,请点此查看更多更全内容