Zhang快速并行細化算法_第1頁
Zhang快速并行細化算法_第2頁
Zhang快速并行細化算法_第3頁
Zhang快速并行細化算法_第4頁
Zhang快速并行細化算法_第5頁
已閱讀5頁,還剩1頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、Zhang快速并行細化算法最近的研究涉及獲取二值圖像骨架(圖象的中軸線),網上找到許多方法,Zhang快速并行細化算法是出現次數最多的算法,看了幾篇博客,又下載了提出這個算法的文獻,感覺這個方法很容易理解,編程也容易,其實最后也沒花多少時間就成功了,VB6.0編寫的程序,用到了函數庫MatrixVB,這里分享一下心得。1. 算法簡介圖1 8鄰域系統圖1表示以P1為中心的8鄰域系統,P2P9代表與P1相鄰的8個像素點,1.1 細化步驟1刪除同時滿足下列條件的邊界點: 2N(P1)6; S(P1)=1; P2×P4×P6=0; P4×P6×P8=0;其中:N

2、(P1)是P1的非零鄰點的個數,S(P1)是以P2,P3,P9,P2為序時這些點的值從0到1變化的次數。1.2 細化步驟2刪除同時滿足下列條件的邊界點: 2N(P1)6; S(P1)=1; P2×P4×P8=0; P2×P6×P8=0;以上兩步操作構成一次迭代,直至沒有點再滿足標記條件,這時剩下的點組成區域即為細化后骨架。2. 程序及細化結果用VB6.0編寫的程序,用到了函數庫MatrixVB(需要的話可以到網上去搜,很老的東西了)。2.1 模塊部分這部分包括自定義數據類型(相當于C語言里的結構體),定義了一些函數。Option ExplicitType

3、 necessary_conditions '4個條件 N_P1 As Integer S_P1 As Integer Mult_P2P4P6 As Integer Mult_P4P6P8 As Integer Mult_P2P4P8 As Integer Mult_P2P6P8 As IntegerEnd TypeType position x As Integer y As IntegerEnd Type'*'計算4個條件的值'輸入:P1點的坐標,待處理的二值圖binary_image'輸出:4個條件的值'*Function obtain_n

4、ecessary_conditions_value(x%, y%, binary_image) As necessary_conditionsDim i%, cnt1%, cnt2%, neighbor8%(9)'-條件1-If binary_image(x - 1, y) = 1 Then neighbor8(2) = 1If binary_image(x - 1, y + 1) = 1 Then neighbor8(3) = 1If binary_image(x, y + 1) = 1 Then neighbor8(4) = 1If binary_image(x + 1, y +

5、1) = 1 Then neighbor8(5) = 1If binary_image(x + 1, y) = 1 Then neighbor8(6) = 1If binary_image(x + 1, y - 1) = 1 Then neighbor8(7) = 1If binary_image(x, y - 1) = 1 Then neighbor8(8) = 1If binary_image(x - 1, y - 1) = 1 Then neighbor8(9) = 1cnt1 = 0cnt2 = 0'-條件2-For i = 2 To 9 If neighbor8(i) = 1

6、 Then cnt1 = cnt1 + 1Next i'-條件3-For i = 2 To 9 - 1 If neighbor8(i) - neighbor8(i + 1) = -1 Then cnt2 = cnt2 + 1Next i If neighbor8(9) - neighbor8(2) = -1 Then cnt2 = cnt2 + 1'-條件4-obtain_necessary_conditions_value.N_P1 = cnt1obtain_necessary_conditions_value.S_P1 = cnt2obtain_necessary_cond

7、itions_value.Mult_P2P4P6 = neighbor8(2) * neighbor8(4) * neighbor8(6)obtain_necessary_conditions_value.Mult_P2P4P8 = neighbor8(2) * neighbor8(4) * neighbor8(8)obtain_necessary_conditions_value.Mult_P2P6P8 = neighbor8(2) * neighbor8(6) * neighbor8(8)obtain_necessary_conditions_value.Mult_P4P6P8 = nei

8、ghbor8(4) * neighbor8(6) * neighbor8(8)End Function'*'Zhang快速并行細化算法'輸入:待處理的二值圖binary_image_buf'輸出:細化后的二值圖binary_image_buf'*Function Zhang_thinning_method(binary_image_buf)Dim rows%, cols%, delete_cnt%Dim i%, j%, k%Dim sign(5000) As position, n1%, n2%, n3%, n4%, n5%, n6%rows = UBo

9、und(binary_image_buf, 1)cols = UBound(binary_image_buf, 2)For k = 1 To 800'-迭代的前半部分- For i = 1 To rows For j = 1 To cols If binary_image_buf(i, j) = 1 Then n1 = obtain_necessary_conditions_value(i, j, binary_image_buf).N_P1 n2 = obtain_necessary_conditions_value(i, j, binary_image_buf).S_P1 n3 =

10、 obtain_necessary_conditions_value(i, j, binary_image_buf).Mult_P2P4P6 n4 = obtain_necessary_conditions_value(i, j, binary_image_buf).Mult_P4P6P8 If (n1 >= 2 And n1 <= 6) And n2 = 1 And n3 = 0 And n4 = 0 Then delete_cnt = delete_cnt + 1 sign(delete_cnt).x = i sign(delete_cnt).y = j End If End

11、If Next j Next i If delete_cnt = 0 Then GoTo finish For i = 1 To delete_cnt binary_image_buf(sign(i).x, sign(i).y) = 0 Next i delete_cnt = 0'-迭代的后半部分- For i = 1 To rows For j = 1 To cols If binary_image_buf(i, j) = 1 Then n1 = obtain_necessary_conditions_value(i, j, binary_image_buf).N_P1 n2 = o

12、btain_necessary_conditions_value(i, j, binary_image_buf).S_P1 n3 = obtain_necessary_conditions_value(i, j, binary_image_buf).Mult_P2P4P8 n4 = obtain_necessary_conditions_value(i, j, binary_image_buf).Mult_P2P6P8 If (n1 >= 2 And n1 <= 6) And n2 = 1 And n3 = 0 And n4 = 0 Then delete_cnt = delete

13、_cnt + 1 sign(delete_cnt).x = i sign(delete_cnt).y = j End If End If Next j Next i If delete_cnt = 0 Then GoTo finish For i = 1 To delete_cnt binary_image_buf(sign(i).x, sign(i).y) = 0 Next i delete_cnt = 0Next kfinish:End Function2.2 窗體部分Option ExplicitPrivate Sub Command1_Click()Dim bin, x1, y1, x

14、2, y2, cnt1%, cnt2%Dim binary_image_buf%(), rows%, cols%Dim i%, j%Set x1 = zeros(5000, 1)Set y1 = zeros(5000, 1)Set x2 = zeros(5000, 1)Set y2 = zeros(5000, 1)bin = vbload(App.Path & "bin4.txt")導入二值圖rows = Size(bin).r1(1)cols = Size(bin).r1(2)ReDim binary_image_buf(rows, cols), binary_3

15、D_buf(rows, cols, 6)For i = 1 To rows For j = 1 To cols binary_image_buf(i, j) = bin(i, j).r1(1) Next jNext iCall Zhang_thinning_method(binary_image_buf)調用 Zhang快速并行細化算法For i = 1 To rows For j = 1 To cols If binary_image_buf(i, j) = 1 Then找出骨架像素點的坐標 cnt1 = cnt1 + 1 x1(cnt1) = i y1(cnt1) = cols + 1 - j End If If bin(i, j).r1(1) = 1 Then找出原二值圖為1的點的坐標 cnt2 = cnt2 + 1 x2(cnt2) = i y2(cnt2) = cols + 1 - j End If Next jNext ix1 = x1(linspace(1, cnt1, cnt1)y1 = y1(linspace(1, cnt1, cnt1)x2 = x2(

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論