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 8208755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:29:05+00:00 2026-06-07T09:29:05+00:00

Suppose we’re working on binary images with black the foreground and white the background.

  • 0

Suppose we’re working on binary images with black the foreground and white the background.
Is there any efficient way of finding black pixels with in a polygon, which is specified by a list of vertex coordinates?

Computing a bounding box from a polygon is NOT ideal because there can be many closely displaced polygons whose bounding boxes may overlap.

Of course, the brute force way will be finding black pixels from an entire image first, and then running the polygon test for each black pixel, which is too time-consuming for the task.

Any suggestions are welcome!

Thank you!

  • 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-07T09:29:07+00:00Added an answer on June 7, 2026 at 9:29 am

    Depending on your workflow or end goal the following may work for you.

    Use cvFillPoly to create a binary mask of the polygon, then use cvCopy to make a copy of the image using the mask created to a whited out array, thus the only black pixels are those that were in the polygon.

    Or instead of using the pointPolygonTest you could use a raycasting algorithm and only check if the pixel is black if you have had an odd number of crossings.

    Doing the raycasting algorithm yourself could save alot of time over calling pointPolygonTest.

    You could have a situation where the scanline that a point is on has a polygon that occupies the entirety of the line.

    The raycasting algorithm counts polygon line crossings from one side, until it reaches the point being tested. If there are m line segments we perform m line segment ray intersections, order them, and count how many have occured.

    If you use the pointPolygonTest you are having to do this for every point, but all the rays you test for the n points on this line, all intersect the line, and their intersections with the line segments all occur at the same place, so you can save all this recalculation by writing the algorithm yourself and augmenting it to check for black pixels when the number of crossings has been odd.

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

Sidebar

Related Questions

Suppose I have a given collection. Without ever changing the collection in any way,
Suppose we have the name written in any none-latin letters - languages, like Arabic,
Suppose there is a MySQL user alice that is currently connected to the database.
Suppose I have tables: Employee(empid, ....) Phone(phoneid, ...) EmployeePhone(empid, phoneid, ...) there is foreign
suppose there is a script doing something like this: # module writer.py import sys
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
Suppose that I want to install a binary module for Python on Windows. Suppose
Suppose there are two tables- T1 T2 --- ---------- A A | 1 A
Suppose there is such HTML tags: ​<span> <span id='s1'>Text 1</span> <span id='s2'>Text 2</span> </span>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
suppose i have a .on() function wherein i select multiple ids $(#i, #am, #your,

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.