Get Grayscale Value of grayscale image
I'm making application for image recognition using grayscale image format. the problem is how to get the values from the gray image.
I have a sample program but I might not be able to use this code to VB.net, because the code for vb.6. Can someone convert this code to vb.net?or do you have another solution?
I was more expecting another solution to this problem in VB.net code.
thank you very much
Code:
For Y = 1 to Picture1.scaleheight
For x = 1 to Picture1.ScaleWidht
p = Get pixel (picture1.hdc, X,Y)
r= p and &HFF
g = (p\&H100)and &HFF
b = (p\&H10000)and &HFF
grtotr=grtotr + r
grratr = Round(gtotr/(picture1.ScaleHeight*Picture1.Scalewidht),2)
grtotg=grtotg + g
grratg = Round(gtotg/(picture1.ScaleHeight*Picture1.Scalewidht),2)
grtotb=grtotb + b
grratb = Round(gtotb/(picture1.ScaleHeight*Picture1.Scalewidht),2)
Next
Next
Text1.text = grratr
Text2.text = ggratg
Text3.text = ggratb
Re: Get Grayscale Value of grayscale image
Perhaps you should elucidate for us exactly what value(s) you are attempting to obtain here. As it stands it looks to be almost entirely arbitrary.
Re: Get Grayscale Value of grayscale image
I think he wants to be able to read the image pixel values.
@Op
Read this. It shows how to use LockBits to read and write to pixels in an image.
Re: Get Grayscale Value of grayscale image
Quote:
Originally Posted by
dunfiddlin
Perhaps you should elucidate for us exactly what value(s) you are attempting to obtain here. As it stands it looks to be almost entirely arbitrary.
calculate the RGB values of the image will then be averaged.
Re: Get Grayscale Value of grayscale image
vb.net Code:
Dim r, g, b As Integer
Dim bmp As New Bitmap("C:\a.png") ' bitmap format has native GetPixel function
For i = 0 To bmp.Width - 1
For j = 0 To bmp.Height - 1
Dim col = bmp.GetPixel(i, j)
r += col.R
g += col.G
b += col.B
Next
Next
r = r \ (bmp.Width * bmp.Height)
g = g \ (bmp.Width * bmp.Height)
b = b \ (bmp.Width * bmp.Height)
Me.Text = r & " " & g & " " & b