rbulph Posted July 30, 2007 Posted July 30, 2007 How can I calculate the green area in the attachment? Or simply the number of green pixels it contains would be enough to get me there. Quote
mandelbrot Posted July 31, 2007 Posted July 31, 2007 Are we talking pure green (i.e. 0,255,0) or shades of green? If we're also looking at shades, then what's your tolerance? What about the areas of white, if it's the interior of the building you're looking at?... Quote
rbulph Posted July 31, 2007 Author Posted July 31, 2007 Are we talking pure green (i.e. 0,255,0) or shades of green? If we're also looking at shades, then what's your tolerance? What about the areas of white, if it's the interior of the building you're looking at?... The image has been produced by scanning a diagram, maximising the contrast, and then using the fill function in MS Paint to fill in all the internal areas in green. So I'm simply interested in the area that MS Paint has filled in. So the answer to your question is simply "whatever green MS Paint has provided." I've found that it doesn't take my computer more than a minute to check each pixel in the diagram, and it's easy to code, so that's what I've now done in fact. Quote
mandelbrot Posted July 31, 2007 Posted July 31, 2007 LOL! That's what I was going to recommend. Another option, especially in larger images, would be to allow the user to set crop regions... Quote
Leaders snarfblam Posted July 31, 2007 Leaders Posted July 31, 2007 How are you examining the pixels? Quote [sIGPIC]e[/sIGPIC]
rbulph Posted July 31, 2007 Author Posted July 31, 2007 How are you examining the pixels? Like this Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With Me.PictureBox1 Dim b As New Bitmap(.Image.Width, .Image.Height) b = .Image Dim s As Integer For n As Integer = 1 To .Image.Width For m As Integer = 1 To .Image.Height Dim q As Color = b.GetPixel(n - 1, m - 1) If q.G = 0 And q.R > 250 Then s = s + 1 'plan had red infill. Check for no green as well so white is excluded. Next Next MsgBox(s) End With End Sub Quote
Leaders snarfblam Posted August 1, 2007 Leaders Posted August 1, 2007 You could make this much, much faster by examining the raw image data rather than using the GetPixel method. I'll see if I can find the tutorial I wrote on the topic. Quote [sIGPIC]e[/sIGPIC]
Leaders snarfblam Posted August 1, 2007 Leaders Posted August 1, 2007 Link (this is padding to shut up vB). Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.