Results 1 to 5 of 5

Thread: Get Grayscale Value of grayscale image

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    8

    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

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    8

    Re: Get Grayscale Value of grayscale image

    Quote Originally Posted by dunfiddlin View Post
    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.

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Get Grayscale Value of grayscale image

    vb.net Code:
    1. Dim r, g, b As Integer
    2.         Dim bmp As New Bitmap("C:\a.png") ' bitmap format has native GetPixel function
    3.         For i = 0 To bmp.Width - 1
    4.             For j = 0 To bmp.Height - 1
    5.                 Dim col = bmp.GetPixel(i, j)
    6.                 r += col.R
    7.                 g += col.G
    8.                 b += col.B
    9.             Next
    10.         Next
    11.         r = r \ (bmp.Width * bmp.Height)
    12.         g = g \ (bmp.Width * bmp.Height)
    13.         b = b \ (bmp.Width * bmp.Height)
    14.  
    15.         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
  •  



Click Here to Expand Forum to Full Width