There is no error in the following code which convert the gray image to binary image but it doesn't work... I need help to determine why the code doesn't work...I,m using vb,net 2012
Dim mp3 As Double
mp2 = 0
Dim i, j As Integer
Dim img As New Bitmap(600, 600)
' PictureBox2.Cls()
For i = 0 To w
For j = 0 To h
ab(i, j) = 0
zxc(i, j) = 0
zxc1(i, j) = 0
ssc(i, j) = 0
Next j
Next i
For i = 0 To w - 17 Step 16
For j = 0 To h - 17 Step 16
mp1 = 0
For k = i To i + 15
For l = j To j + 15
mp1 = mp1 + imageArray(k, l)
Next l, k
mp1 = mp1 / (16 ^ 2)
For k = i To i + 15
For l = j To j + 15
If imageArray(k, l) >= mp1 Then
ssc(k, l) = 255
Else
ssc(k, l) = 0
End If
img.SetPixel(k, l, Color.FromArgb(ssc(k, l), ssc(k, l), ssc(k, l)))
Next l, k
Next j
PictureBox2.Refresh()
Next i
mp3 = 0 : nd = 1
For k = 0 To w
For l = j To h
mp3 = mp3 + imageArray(k, l)
nd = nd + 1
Next l, k
mp3 = mp3 / nd
For k = 0 To w
For l = j To h
If imageArray(k, l) >= mp3 Then ssc(k, l) = 255 Else ssc(k, l) = 0
img.SetPixel(k, l, Color.FromArgb(ssc(k, l), ssc(k, l), ssc(k, l)))
Next l, k
mp3 = 0 : nd = 0
For k = i To w
For l = 0 To h
mp3 = mp3 + imageArray(k, l)
nd = nd + 1
Next l, k
mp3 = mp3 / nd
For k = i To w
For l = 0 To h
If imageArray(k, l) >= mp3 Then ssc(k, l) = 255 Else ssc(k, l) = 0
img.SetPixel(k, l, Color.FromArgb(ssc(k, l), ssc(k, l), ssc(k, l)))
Next l, k
hpp = 0
PictureBox2.Image = img
End Sub
....... THE code of loading the image is working ,but Idont know if it store the values of the array properly or not ,and it is as following
Dim ofd As New OpenFileDialog
ofd.Filter = "Bitmap files (*.bmp)|*.bmp"
If ofd.ShowDialog = DialogResult.OK Then
If ofd.FileName <> String.Empty Then
Me.PictureBox1.Image = Bitmap.FromFile(ofd.FileName)
End If
End If
Dim img As New Bitmap(ofd.FileName)
Dim imageArray(img.Width, img.Height) As Integer
Dim i, j As Integer
Dim k As Double
For i = 0 To img.Width - 1
For j = 0 To img.Height - 1
Dim pixel As Color = img.GetPixel(i, j)
imageArray(i, j) = pixel.ToArgb()
z(i, j) = imageArray(i, j)
k = k + imageArray(i, j)
Next j
Next i
End Sub