Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8586809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:24:13+00:00 2026-06-11T22:24:13+00:00

Given a list of x,y coordinates and a known width & height how can

  • 0

Given a list of x,y coordinates and a known width & height how can the NUMBER of the enclosed areas be determined (in C#)?

For Example:

enter image description here

In this image 5 ENCLOSED AREAS are defined:

  1. Face (1)
  2. Eyes (2)
  3. Nose (1)
  4. Right of face (1)

The list of x,y points would be any pixel in black, including the mouth.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:24:15+00:00Added an answer on June 11, 2026 at 10:24 pm

    You can use this simple algorithm, based on idea of flood fill with helper bitmap:

    // backColor is an INT representation of color at fillPoint in the beginning.
    // result in pixels of enclosed shape.
    private int GetFillSize(Bitmap b, Point fillPoint)
    {
       int count = 0;
       Point p;
       Stack pixels = new Stack();
       var backColor = b.GetPixel(fillPoint.X, fillPoint.Y);
       pixels.Push(fillPoint);
       while (pixels.Count != 0)
       {
           count++;
    
           p = (Point)pixels.Pop();
           b.SetPixel(p.X, p.Y, backColor);
    
           if (b.GetPixel(p.X - 1, p.Y).ToArgb() == backColor)
               pixels.Push(new Point(p.X - 1, p.Y));
    
           if (b.GetPixel(p.X, p.Y - 1).ToArgb() == backColor)
               pixels.Push(new Point(p.X, p.Y - 1));
    
           if (b.GetPixel(p.X + 1, p.Y).ToArgb() == backColor)
               pixels.Push(new Point(p.X + 1, p.Y));
    
           if (b.GetPixel(p.X, p.Y + 1).ToArgb() == backColor)
               pixels.Push(new Point(p.X, p.Y + 1));
       }
    
       return count;
    }
    

    UPDATE

    The code above works only this quadruply-linked enclosed areas. The following code works with octuply-linked enclosed areas.

    // offset points initialization.
    Point[] Offsets = new Point[]
    {
        new Point(-1, -1),
        new Point(-0, -1),
        new Point(+1, -1),
        new Point(+1, -0),
        new Point(+1, +1),
        new Point(+0, +1),
        new Point(-1, +1),
        new Point(-1, +0),
    };
    
    ...
    
    private int Fill(Bitmap b, Point fillPoint)
    {
        int count = 0;
        Point p;
        Stack<Point> pixels = new Stack<Point>();
        var backColor = b.GetPixel(fillPoint.X, fillPoint.Y).ToArgb();
        pixels.Push(fillPoint);
        while (pixels.Count != 0)
        {
            count++;
    
            p = (Point)pixels.Pop();
            b.SetPixel(p.X, p.Y, Color.FromArgb(backColor));
    
            foreach (var offset in Offsets)
                if (b.GetPixel(p.X + offset.X, p.Y + offset.Y).ToArgb() == backColor)
                    pixels.Push(new Point(p.X + offset.X, p.Y + offset.Y));
        }
    
        return count;
    }
    

    The picture below clearly demonstates what I mean. Also one could add more far points to offset array in order to able to fill areas with gaps.

    Connectedness

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a list like this: num = [1, 2, 3, 4, 5] There are
This list is a simple function that maps a 2D point to a number,
The polygon is given as a list of Vector2I objects (2 dimensional, integer coordinates).
Problem: Given a list of spheres, find all empty spaces that are completely enclosed
I have a list of more than 15 thousand latitude and longitude coordinates. Given
Given a list of coordinates, how do I calculate the minimum bounding rectangle (MBR),
Given an R list, I wish to find the index of a given list
The original code was somehow complex, i simplify it as: Given: list of class
Given a list a containing vectors of unequal length and a vector b containing
Given a List such as List(1, 2, 3, 4, 5, 6, 7) what is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.