Results 1 to 5 of 5

Thread: Find out if a pixel belongs to a region

  1. #1

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

    Find out if a pixel belongs to a region

    I have a black and white image such as the attached one and I want to calculate the area and center of mass of the inner (hole) region.

    The problem I'm facing is for a spcific white pixel how to determine if it belongs or not to the hole i.e. if it's entirely surrounded by the black region.

    I assume the web has a lot of related information but I just don't know what exactly to look for. Any ideas?
    Attached Images Attached Images  
    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
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Find out if a pixel belongs to a region

    What language are you using? do you have any data representing the region (or just the picture)?

    If you only have the picture then what you can do is check pixels in each of 4 directions (up/down/left right) until the edge of the picture. If you find a black pixel before the edge then it might be inside (and is if this is true for all directions), but if you don't find any black pixels then you are outside.

    This method may not work for all shapes (such as if the outside of the black area has a bit of a 'spiral' on it), but it would work in many cases... it depends on what kind of pictures you are using.

  3. #3

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

    Re: Find out if a pixel belongs to a region

    Quote Originally Posted by si_the_geek View Post
    What language are you using? do you have any data representing the region (or just the picture)?...
    This is an old VB6 project I'm working on again. A few months ago I got started in VB.Net but have not yet migrated this project.

    I have a 1D array of integers (values 0 or 255) representing the 2D image.

    The original image has gray values ranging from 0 through 255 and then I convert it to binary applying a threshold. In the testing phase I'm using a scrollbar to change the threshold value and watch how the resulting binary image changes. The inner white region only becomes visible when scrolling down past a certain value. I would like to do this automatically so additionally I should be able to detect for what threshold value there is effectively an inner region. Or if you will, to find out if the black region has any hole in it.
    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)

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Find out if a pixel belongs to a region

    I'm thinking now that you probably wont know the location of the inner region, so checking from a particular point wont work too well.


    Another option would be to read rows (and/or columns) to see how many times you enter a black section within each row (or column), if it is only once then there is no inner region, and more than one implies there is an inner region.

    Unfortunately the irregular edges of the black region mean that in some places you can enter and leave the black region multiple times (such as across the bottom of the example picture), but you could offset that to some degree by making sure that you only count the black area that you cross if it is big enough... or simpler, count how many rows seem to have an inner region, and only treat it as the case if this count is high enough.

  5. #5

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

    Re: Find out if a pixel belongs to a region

    Quote Originally Posted by si_the_geek View Post
    I'm thinking now that you probably wont know the location of the inner region, so checking from a particular point wont work too well.


    Another option would be to read rows (and/or columns) to see how many times you enter a black section within each row (or column), if it is only once then there is no inner region, and more than one implies there is an inner region.

    Unfortunately the irregular edges of the black region mean that in some places you can enter and leave the black region multiple times (such as across the bottom of the example picture), but you could offset that to some degree by making sure that you only count the black area that you cross if it is big enough... or simpler, count how many rows seem to have an inner region, and only treat it as the case if this count is high enough.
    Thank you for your suggestions.

    In the meantime I have Googled and found some interesting stuff on binary image analysis that I'm going to study in the next few days. If I can find no answers then perhaps I'll come back for further help.
    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)

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