Click here to Skip to main content
15,868,030 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello all. Please I am working on a bitmap project. This bitmap file has black and white boxes and it is loaded to the picturebox. I want to be able to identify the pixels in the black box on the bitmap and save them to an array for use in further processing of the project. Please can I get help with the codes that does this in VB.net (preferably) or C#. Thanks

sorry guys it's my first time here and am relatively new to Graphics programming. This is what I have done, it can only display the x, y cordinates and pixels on a richtextbox. Sub Getcoordinates()
On Error GoTo Refresh
CheckForIllegalCrossThreadCalls = False
Dim Bild As Bitmap = CType(Me.PictureBox1.Image.Clone, Bitmap)
Dim width As Integer = Bild.Width - 1
Dim height As Integer = Bild.Height - 1
For x = 0 To width
For y = 0 To height

Dim R, G, B, A As Integer
R = Bild.GetPixel(x, y).R
G = Bild.GetPixel(x, y).G
B = Bild.GetPixel(x, y).B
A = Bild.GetPixel(x, y).A
RichTextBox1.AppendText(R & "-" & G & "-" & B & "-" & A & " Cordinates " & x & "," & y & vbNewLine)
Next
Next
RichTextBox1.Text = RichTextBox1.Text.Substring(0, RichTextBox1.Text.Length - 1)
RichTextBox1.AppendText("|" & width & "*" & height)


Refresh:
Refresh()
End Sub
Posted
Updated 16-Jul-14 8:59am
v3
Comments
[no name] 16-Jul-14 14:04pm    
We don't write code to order here. You need to at least attempt this yourself and if you run into a specific problem, then we could help you.
Naija Coding 16-Jul-14 14:19pm    
I have something but not close to it. should I post it?
[no name] 16-Jul-14 14:37pm    
And how would I know that? Do you have a specific problem or a question? Does your code demonstrate your specific problem or question?
Naija Coding 16-Jul-14 15:01pm    
I have posted my codes on the question. sorry am new here. My codes tries too but I dont think am close

1 solution

Not only using GetPixel is prohibitively slow, it's just no serious. If you don't know how to develop image recognition by yourself (this is not easy at all), you can use one of the open-source libraries. I would recommend native .NET library AForge.NET:
http://en.wikipedia.org/wiki/AForge.NET[^],
http://www.aforgenet.com/[^].

What you need is the blob recognition. This is the basic AForge.NET manual with source code sample which you can use to find all the documentation pages: http://www.aforgenet.com/articles/shape_checker[^].

The robustness and especially performance of this software is wonderful. For a recognized object, it can give you the convex hull of it, which is the most characteristic object describing major properties of your blob.

[EDIT]

To find black and white blobs, you need to find the white blobs, then invert the image and find… white blobs again, which will be inverted blacks. See also my comment below: you may need to contrast your source first, using other AForge.NET transformations (always keep your original image).

Please see my past answers with related advise:
How to filter out the unwanted blobs in AForge.net ?[^],
Convex "Hull" 2d.................................[^],
blob detection in c#[^],
Simple BLOB detection algorithm[^],
image processing using Aforge.net >> I need the help[^],

(Sorry for some redundancy in answer; I hope you understand that I answered to different people.)

See also: http://en.wikipedia.org/wiki/Blob_detection[^].

—SA
 
Share this answer
 
v2
Comments
Naija Coding 16-Jul-14 15:48pm    
Ok Thanks I will look at it. and yes GetPixel is very slow, takes several seconds to display on the Rich textbox
Sergey Alexandrovich Kryukov 16-Jul-14 19:46pm    
Certainly. Instead, Bitmap.LockBits should be used.
But I gave you much more realistic solution which worked brilliantly for me. Will you accept the answer formally (green "Accept" button)?
—SA
Naija Coding 16-Jul-14 22:36pm    
Yes I will soon and thanks. But I visited Aforge and couldn't understand a thing there. I may need some tutorials or something
Sergey Alexandrovich Kryukov 16-Jul-14 23:04pm    
Wow! not a thing? Sorry, but I cannot pass to you my manual reading skills. Actually AForge.NET manual and documentation is good enough; and the article I referenced is the manual. if this is beyond your skills, you have to develop those skills; there is no an easier way. The However, you may simply need to take your time and move slower.

By the way, do the following: look at Andrew's articles on the topic here at CodeProject. Andrew Kirillov, AForge.NET author, is our member:
http://www.codeproject.com/Members/Andrew-Kirillov.

—SA
Naija Coding 18-Jul-14 20:38pm    
I've accepted. However if you have further help, I will appreciate. I'm now studying the Aforge algorithm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900