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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:11:21+00:00 2026-05-31T13:11:21+00:00

I am dealing with images and would like to determine if a set of

  • 0

I am dealing with images and would like to determine if a set of pixels are closer to white or black.

So given a set of colors/pixles, how does one determine if they closer to a white or a black?

I have tried some noobish algorithms, does anyone know how I can do this?

  • 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-05-31T13:11:21+00:00Added an answer on May 31, 2026 at 1:11 pm

    I would say that you can first convert the color to gray scale and then check if it’s nearer to black or white.

    First convert the RGB color value to compute luminance by the following formula

    Y = 0.2126*R + 0.7152*G + 0.0722*B
    

    Then check if the value is nearer to 0 or to 255 and choose black or white accordingly

    color c = Y < 128 ? black : white
    

    Mind that this works well if the color space is not gamma compressed, otherwise you will have to add a step before calculating the luminance which is a gamma expansion, compute Y, then perform a gamma compression to obtain a non-linear luminance value that you can then use to decide if color is nearer to black or white.

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

Sidebar

Related Questions

Say I have an image of size 3841 x 7195 pixels. I would like
I'm merging multiple small images into a rectangular mosaic. When dealing with a small
Other questions dealing with use of match_parent pre 2.2 have answers stating one should
Rails and ActiveRecord do a perfectly nice job of dealing with what I would
I spend a large amount of my time writing code dealing with images. I
I am creating a profile page, and I would like to create a followers
First of all this code does work and when its dealing with a few
Whenever dealing with the loading and rendering of images in Java, I have previously
I would like to load vector graphics stored as XAML files (separate files, not
I would like advice as to best practice in testing object existence for cross-browser

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.