'open file
opendio.ShowDialog() 'open file
Label1.Text = opendio.FileName 'print path on label
Picture.Image = Image.FromFile(opendio.FileName) 'show image in box
'initalize varables
Dim photo As New Bitmap(opendio.FileName) 'save image as varable
Dim white As Integer = Color.White.ToArgb
Dim totalmesure As Integer 'total amount of area mesuring
Dim pixel As Integer
Dim black As Integer = Color.Black.ToArgb
Dim countwhite As Integer ' number of white pixels
Dim countgrayb As Integer ' the number of gray and black pixels
Dim countgray As Integer 'number of gray
Dim countblack As Integer ' number of black
Dim totalpix As Integer 'total pixels
Dim y As Integer 'y pixel
Dim x As Integer 'x pixel
Dim photomaxX As Integer = photo.Size.Width 'how many pixels on X axes
Dim photomaxY As Integer = photo.Size.Height 'how many pixels on Y axes
For y = 0 To photomaxY - 1 'go though the y axis
For x = 0 To photomaxX - 1 'go though the x axis
If photo.GetPixel(x, y).ToArgb = white Then 'test for white pixel
countwhite = countwhite + 1 'add one
End If
ProgressBar1.Maximum = photomaxX * photomaxY
pixel = pixel + 1 'add one for every pixel tested
ProgressBar1.Value = pixel 'move bar
Next
Next
'find gray and black
For y = 0 To photomaxY - 1 'go though the y axis
For x = 0 To photomaxX - 1 'go though the x axis
If photo.GetPixel(x, y).ToArgb <> white Then 'test for non white pixel
countgrayb = countgrayb + 1 'add one
End If
pixel = 0 'reset
pixel = pixel + 1 'add one for every pixel tested
ProgressBar1.Value = pixel
Next
Next
'find black
For y = 0 To photomaxY - 1 'go though the y axis
For x = 0 To photomaxX - 1 'go though the x axis
If photo.GetPixel(x, y).ToArgb = black Then 'test for black pixel
countblack = countblack + 1 'add one
End If
pixel = 0 'reset
pixel = pixel + 1 'add one pixle
ProgressBar1.Value = pixel
Next
Next
For y = 0 To photomaxY - 1 'go though the y axis
For x = 0 To photomaxX - 1 'go though the x axis
If photo.GetPixel(x, y).ToArgb = white Then 'test for white pixel
photo.SetPixel(x, y, Color.Blue)
End If
Next
Next
Picture.Image = photo
'calulate data
countgray = countgrayb - countblack 'finds number of gray pixels
totalpix = photomaxX * photomaxY 'finds total pixels
totalmesure = totalpix - countgray 'finds how much pixels are in the area we want to mesure
MsgBox("total bactera pixels: " & countwhite & vbNewLine & _
"Total null pixles: " & countblack & vbNewLine & _
"Total Area: " & totalmesure & vbNewLine & _
"Percent: " & (countwhite / totalmesure) * 100) ' show all data
End Sub