|
-
Apr 1st, 2016, 03:29 PM
#1
Image processing (math) question
Given a binary image such as the attached figure, how can I split the white pixels into 2 subsets, the inner and the outer ones? In other words, how do I determine if a white pixel is entirely surrounded by red pixels?

Rather than code what I need is the guidelines, a method or algorithm.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Apr 1st, 2016, 03:42 PM
#2
Re: Image processing (math) question
Well, I think I could examine the pixels in a row to the right and left.
But now a related question that seems to be more difficult.
The image could be like the one above or like this one:

How can I find out (by code) if the red area closes on itself forming a central white "lake"?
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Apr 2nd, 2016, 06:49 AM
#3
Re: Image processing (math) question
Hmm, the only thing that comes to mind is using the
ExtFloodFill call set a color different from White or Red
and then testing, say, the upper left corner and the
center of the circle for the flooded color.
-
Apr 2nd, 2016, 08:31 AM
#4
Re: Image processing (math) question
Have a look at "morphological image processing"
http://www.dspguide.com/ch25/4.htm
-
Apr 2nd, 2016, 08:58 AM
#5
Re: Image processing (math) question
Pratically identical to my question
http://www.vbforums.com/showthread.p...e+pixel+inside
LooK at post 21 and 23
-
Apr 2nd, 2016, 06:20 PM
#6
Re: Image processing (math) question
 Originally Posted by namrekka
Thanks for this link. The book is incredible. I came across it quite a while ago but had forgotten about it. I may have done the same this time around, but the chapter section you linked to gave me some great ideas for something I am working on.
Now complex algorithms take a lot of time to write, debug, maintain and so forth. This would not be what I would do in the case of the OP requirements. Instead I favor the idea in post #3, which is exactly what I suggested in the thread reexre referred to in post #5.
-
Apr 5th, 2016, 12:48 PM
#7
Re: Image processing (math) question
 Originally Posted by namrekka
Interesting book but I don't see how this chapter is going to help me.
The question is, given an image like either of the above, how can I detect whether it has an inner group of white pixels? It could be a lake or a bay.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Apr 6th, 2016, 12:23 AM
#8
Re: Image processing (math) question
 Originally Posted by krtxmrtz
Interesting book but I don't see how this chapter is going to help me.
The question is, given an image like either of the above, how can I detect whether it has an inner group of white pixels? It could be a lake or a bay.
So, you don't need any Pixel-Manipulation on the Input-Image - right?
Still I'm wondering what you're really after ...
- is it just a function, which only returns a Boolean, when there's "some outer thing which encloses some inner thing"
- or is it a function, which determines whether the Image contains something that either encloses "a Lake" OR "a Bay" (e.g. returning an Enum-Value).
In other words:
- do you need to determine only, whether something is "quite curved"
- or do you need to determine between "something is quite curved and open" (like a C) OR "curved and closed" (like an O)
Olaf
-
Apr 6th, 2016, 08:26 AM
#9
Re: Image processing (math) question
"Morphological Image Processing" will be not a single layer solution for you.
Suppose you make a mask of 3*3 pixels:
123
456
789
You put this some where on your image on a point where a pixel exists with 5 as center of the mask.
Suppose the mask is filled with "1" on all positions. You compare (AND) the positions (except 5) with the underlaying image and count the hits.
As the counter returns 0 there are no connecting pixels. This can be used for removing single unwanted pixels. If the counter returns 1 its a end of a line.
In this case you can grow your image2 till its closed. Also if you change the mask you can detect directions and grow in certain directions.
Erosion, dilation, opening and closing are common algo's depending the mask.
https://en.wikipedia.org/wiki/Mathematical_morphology
In your case you need some layers after each other.
-
Apr 6th, 2016, 10:10 AM
#10
Re: Image processing (math) question
Let's make it so we have on a form an array of 4 vertically stacked command buttons and a picturebox on the right side of those buttons.
Let's say also we have those same picture samples as posted above, but saved as BMP instead of PNG.
Finally, let's assume the center of the picture box is a white pixel. This condition is included here for code simplicity, the alternative being that you would have to scan the pixels of the whole picture to find a white one for the test to be positive.
Code:
Private Declare Function ExtFloodFill Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal bcolor As Long, ByVal bstyle As Long) As Long
Private Sub Form_Load()
Picture1.Appearance = 0
Picture1.BorderStyle = 0
Picture1.AutoSize = True
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = True
Picture1.FillStyle = vbFSSolid
Picture1.FillColor = vbYellow
Command1(0).Caption = "Load Lake"
Command1(1).Caption = "Load Bay"
Command1(2).Caption = "Floodfill"
Command1(3).Caption = "Test"
End Sub
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0: Picture1.Picture = LoadPicture(App.Path & "\lake.bmp")
Case 1: Picture1.Picture = LoadPicture(App.Path & "\bay.bmp")
Case 2: ExtFloodFill Picture1.hdc, 3, 3, vbWhite, 1: Picture1.Refresh
Case 3: pcolor = Picture1.Point(Picture1.ScaleWidth / 2, Picture1.ScaleHeight / 2)
MsgBox IIf(pcolor = vbWhite, "Lake", "Bay")
End Select
End Sub
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
|