|
-
May 19th, 2013, 09:43 AM
#1
Thread Starter
New Member
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
-
May 19th, 2013, 12:56 PM
#2
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.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 19th, 2013, 02:07 PM
#3
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.
-
May 19th, 2013, 03:13 PM
#4
Thread Starter
New Member
Re: Get Grayscale Value of grayscale image
 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.
-
May 20th, 2013, 11:58 AM
#5
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
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|