【发布时间】:2017-05-31 16:18:19
【问题描述】:
我正在尝试在 Visual Basic 中进行迟滞阈值处理以进行精明的边缘检测。由于我是这个主题的新手和 vb 的新手(我主要使用 php),我阅读的许多参考资料都指出我需要这样做。由于图像已经是黑白的,我只得到一种强度的颜色。我已经在几秒钟内完成了高斯模糊、灰度、索贝尔蒙版和非最大值抑制。但是在滞后上,执行该功能的时间太长了。我不知道我哪里做错了。如果有帮助,图像是 640 x 480。我尝试将分辨率更改为更小的分辨率,它确实更快,但我想将分辨率保持在 640 x 480。我已经更改了代码,这是我的最终方法
Dim bmp_thres As New Bitmap(pic_nonmaxima)
Dim visited_maps As New List(Of String)
Dim threshold_H As Integer = 100
Dim threshold_L As Integer = 50
Dim Ycount As Integer
For Ycount = 1 To bmp_thres.Height - 2
Dim Xcount As Integer
For Xcount = 1 To bmp_thres.Width - 2
'check current pointer
Dim currPointer As String = Xcount & "," & Ycount
'find if coordinate visited already
Dim find_array As String
If visited_maps IsNot Nothing Then
find_array = visited_maps.Contains(currPointer)
Else
find_array = "False"
End If
If find_array Then
'if existed, do nothing
Else
'if not, do something
Dim currThreshold As Integer
Dim currColor As Color
currColor = bmp_thres.GetPixel(Xcount, Ycount)
currThreshold = currColor.R
'add coordinate into visited maps
Dim visited As String = Xcount & "" & Ycount
visited_maps.Add(visited)
If currThreshold > threshold_H Then
bmp_thres.SetPixel(Xcount, Ycount, Color.FromArgb(255, 255, 255))
Else
bmp_thres.SetPixel(Xcount, Ycount, Color.FromArgb(0, 0, 0))
'check connectedness
Dim coord_N As String = Xcount & "," & Ycount + 1
Dim coord_E As String = Xcount + 1 & "," & Ycount
Dim coord_S As String = Xcount & "," & Ycount - 1
Dim coord_W As String = Xcount - 1 & "," & Ycount
Dim coord_NE As String = Xcount + 1 & "," & Ycount + 1
Dim coord_SE As String = Xcount + 1 & "," & Ycount - 1
Dim coord_SW As String = Xcount - 1 & "," & Ycount - 1
Dim coord_NW As String = Xcount - 1 & "," & Ycount + 1
Dim myCoord As New List(Of String)
myCoord.Add(coord_N)
myCoord.Add(coord_E)
myCoord.Add(coord_S)
myCoord.Add(coord_W)
myCoord.Add(coord_NE)
myCoord.Add(coord_SE)
myCoord.Add(coord_SW)
myCoord.Add(coord_NW)
For Each coord In myCoord
If Not visited_maps.Contains(coord) Then
'Split by ,
Dim split_Coord() As String = Split(coord, ",")
'check thres on coord
Dim coordColor As Color = bmp_thres.GetPixel(split_Coord(0), split_Coord(1))
Dim coordThres As Integer = coordColor.R
If coordThres > threshold_H Then
bmp_thres.SetPixel(split_Coord(0), split_Coord(1), Color.FromArgb(255, 255, 255))
Else
bmp_thres.SetPixel(split_Coord(0), split_Coord(1), Color.FromArgb(0, 0, 0))
End If
End If
visited_maps.Add(coord)
Next 'end if foreach
End If ' end if checking current threshold
End If 'end if find coord in visited maps
Next 'end for xcount
Next 'end for ycount
Return bmp_thres
或者如果您发现我做的一些错误代码,请指出我。
如果我做对了,当我们做滞后阈值时,我们首先检查坐标是否已经访问过,如果已经访问过,我们检查下一个坐标。如果不是,我们将坐标添加到访问过的地图中,如果当前坐标大于阈值高,我们将像素值更改为白色,否则为黑色。然后我们检查连通性,如果它们通过阈值低,我们将像素值更改为白色,否则为黑色。然后我们将所有连通性添加到访问过的地图中。重复。
我可以做些什么来减少时间?或者请指出我的错误。任何帮助将不胜感激。如果你不明白,对不起英语。这将有助于我最后一年的项目T_T
【问题讨论】:
标签: vb.net image-processing edge-detection