资源描述:
《Sobel边缘检测算法.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.Sobel边缘检测算法:procedureTImageProcessForm.SobelClick(Sender:TObject);varp1,p3,p2,p4:pByteArray;I,J:integer;R,G,B:Byte;beginself.DoubleBuffered:=true;//采用双缓冲模式TestBMP.Assign(WillbeChangedBmp);ProcessedBmp.Assign(WillbeChangedBmp);forJ:=1toTestBMP.Height-2dobeginp1:=TestB
2、MP.ScanLine[j];p2:=ProcessedBmp.ScanLine[j-1];p3:=ProcessedBmp.ScanLine[j];p4:=ProcessedBmp.ScanLine[j+1];forI:=1toTestBMP.Width-2dobeginR:=min(255,max(0,((-p2[3*(i-1)+2]-2*p2[3*i+2]-p2[3*(i+1)+2]-0*p3[3*(i-1)+2]+0*p3[3*i+2]-0*p3[3*(i+1)+2]+p4[3*(i-1)+2]+2*p4[3*i+2]+p4
3、[3*(i+1)+2]))));G:=min(255,max(0,((-p2[3*(i-1)+1]-2*p2[3*i+1]-p2[3*(i+1)+1]-0*p3[3*(i-1)+1]+0*p3[3*i+1]-0*p3[3*(i+1)+1]+p4[3*(i-1)+1]+2*p4[3*i+1]+p4[3*(i+1)+1]))));B:=min(255,max(0,((-p2[3*(i-1)]-2*p2[3*i]-p2[3*(i+1)]-0*p3[3*(i-1)]+0*p3[3*i]-0*p3[3*(i+1)]+p4[3*(i-1)]+2
4、*p4[3*i+2]+p4[3*(i+1)]))));//采用检测水平边缘的sobel算子[-1,-2,1,0,0,0,1,2,1]p1[3*i+2]:=min(255,max(0,((-p2[3*(i-1)+2]+0*p2[3*i+2]+P2[3*(i+1)+2]-2*p3[3*(i-1)+2]+0*p3[3*i+2]+2*p3[3*(i+1)+2]-p4[3*(i-1)+2]-0*p4[3*i+2]+p4[3*(i+1)+2]))));p1[3*i+1]:=min(255,max(0,((-p2[3*(i-1)+1]+0*p2[
5、3*i+1]+p2[3*(i+1)+1]-2*p3[3*(i-1)+1]+0*p3[3*i+1]+2*p3[3*(i+1)+1]-p4[3*(i-1)+1]-0*p4[3*i+1]+p4[3*(i+1)+1]))));p1[3*i]:=min(255,max(0,((-p2[3*(i-1)]+0*p2[3*i]+p2[3*(i+1)]-2*p3[3*(i-1)]+0*p3[3*i]+2*p3[3*(i+1)]-p4[3*(i-1)]-0*p4[3*i]+p4[3*(i+1)]))));//采用检测水平边缘的sobel算子[-1,0,
6、1,-2,0,2,-1,0,1]p1[3*i+2]:=(Max(R,p1[3*i+2]));p1[3*i+1]:=(Max(G,p1[3*i+1]));p1[3*i]:=(Max(B,p1[3*i]));end;end;ChangedBmp.Assign(TestBMP);ShowChangedBmp;end;