Private Sub Button28_Click(sender As System.Object, e As System.EventArgs) Handles Button28.Click
'Dim aa = Math.Sin(30 / 57.17)
'Dim bb = Math.Asin(aa) * 57.17
'Dim RGB_center(2, 1) As Integer
'-------選取來源檔視窗-------------------
OpenFileDialog1.Filter = ".raw|*.*"
Dim path1 As String
MsgBox("請選擇 背景圖")
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
path1 = OpenFileDialog1.FileName
Else
MsgBox("no select Pic")
Exit Sub
End If
'-----------------------------------------------------------------
Dim filename = path1.Split(".")(0)
Dim pic_xy As New Bitmap(path1)
Dim R_max As Integer = Math.Sqrt((pic_xy.Width / 2) ^ 2 + (pic_xy.Height / 2) ^ 2) + 1
Dim theda_max = 360
Dim pic_polar As New Bitmap(R_max, theda_max) '
Dim x_center = pic_xy.Width / 2
Dim y_center = pic_xy.Height / 2
Dim wt_R As New IO.StreamWriter(filename + "_R.txt", False)
' Dim wt_theda As New IO.StreamWriter("c:/theda.txt")
For j = 1 To pic_xy.Height - 1
For i = 1 To pic_xy.Width - 1
Dim R As Integer = Math.Sqrt((i - x_center) ^ 2 + (j - y_center) ^ 2)
Dim theda As Integer = Math.Atan((j - y_center) / (i - x_center + 0.001)) * 57.1745 '轉為單位 >> 度
If i
theda = theda + 180
End If
If i y_center Then
theda = theda + 180
End If
If i > x_center And j
theda = theda + 360
End If
If i > x_center And j > y_center Then
theda = theda + 0
End If
Dim v = pic_xy.GetPixel(i, j)
pic_polar.SetPixel(R, theda, v)
Dim xy_str = i.ToString + "_" + j.ToString
wt_R.WriteLine(R.ToString + "," + theda.ToString + "," + xy_str)
Next
Next
Dim histR As New List(Of Integer)
Dim wt_histR As New IO.StreamWriter(filename + "_histR.csv")
For i = 0 To pic_polar.Width - 1 ' R
Dim sum_rowofR = 0
For j = 0 To pic_polar.Height - 1 'theda
Dim vv = pic_polar.GetPixel(i, j).R
sum_rowofR = sum_rowofR + vv
Next
histR.Add(sum_rowofR)
' wt_histR.WriteLine(sum_rowofR.ToString)
wt_histR.WriteLine(histR.Max.ToString)
Next
wt_R.Flush()
wt_R.Close()
wt_histR.Flush()
wt_histR.Close()
pic_polar.Save(filename + "_polar_pic.jpg", Imaging.ImageFormat.Jpeg)
MsgBox("over" + histR(0).ToString)
End Sub
- Mar 04 Sun 2012 19:57
vbnet~直角坐標轉極座標~
全站熱搜
留言列表
禁止留言