dcsimg
Results 1 to 10 of 10

Thread: Image processing (math) question

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    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?

    Name:  binary image.png
Views: 138
Size:  2.1 KB

    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)

  2. #2

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    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:

    Name:  binary image 2.png
Views: 115
Size:  2.0 KB

    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)

  3. #3
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    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.

  4. #4
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: Image processing (math) question

    Have a look at "morphological image processing"

    http://www.dspguide.com/ch25/4.htm

  5. #5

  6. #6
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    557

    Re: Image processing (math) question

    Quote Originally Posted by namrekka View Post
    Have a look at "morphological image processing"

    http://www.dspguide.com/ch25/4.htm
    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.

  7. #7

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Image processing (math) question

    Quote Originally Posted by namrekka View Post
    Have a look at "morphological image processing"

    http://www.dspguide.com/ch25/4.htm
    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)

  8. #8
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,891

    Re: Image processing (math) question

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

  9. #9
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    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.

  10. #10
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    557

    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
  •  



Featured


Click Here to Expand Forum to Full Width