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

  • Home
  • SEARCH
  • 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 8751463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:03:13+00:00 2026-06-13T13:03:13+00:00

I am new to python and would like to be pointed in the next

  • 0

I am new to python and would like to be pointed in the next direction. I am using PIL. Done a fair bit of research, and I’m still stuck!

I need to get the rgb of each pixel starting at 0,0 and going along each row all the way down the y coordinate. Its a bmp and only black and white, but I only want python to print pixels which are between 10,10,10 and 0,0,0. Could someone offer me some wisdom?

  • 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-13T13:03:14+00:00Added an answer on June 13, 2026 at 1:03 pm

    If you’re sure that r==g==b for all pixels, then this should work:

    from PIL import Image
    
    im = Image.open("g.bmp")       # The input image. Should be greyscale
    out = open("out.txt", "wb")    # The output.
    
    data = im.getdata()            # This will create a generator that yields
                                   # the value of the rbg values consecutively. If
                                   # g.bmp is a 2x2 image of four rgb(12, 12, 12) pixels, 
                                   # list(data) should be 
                                   # [(12,12,12), (12,12,12), (12,12,12), (12,12,12)]
    
    for i in data:                   # Here we iterate through the pixels.
        if i[0] < 10:                # If r==b==g, we only really 
                                     # need one pixel (i[0] or "r")
    
            out.write(str(i[0])+" ") # if the pixel is valid, we'll write the value. So for
                                     # rgb(4, 4, 4), we'll output the string "4"
        else:
            out.write("X ")          # Otherwise, it does not meet the requirements, so
                                     # we'll output "X"
    

    If it is NOT guaranteed that r==g==b for some reason, adjust the conditions as necessary. If you want an average of 10, for example, you could change the condition to something like

    if sum(i) <= 30: # Equivalent to sum(i)/float(len(i)) <= 10 if we know the length is 3
    

    Also note that for greyscale-format files (as opposed to greyscale images in a color file format) im.getdata() will return simply the grey level as a single value. So for a 2×2 image of rgb(15, 15, 15), list(data) will output [4, 4, 4, 4] instead of [(4, 4, 4), (4, 4, 4), (4, 4, 4), (4, 4, 4)]. In this case, when analyzing, refer just to i instead of i[0]

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

Sidebar

Related Questions

I'm new to Python and would like to read a config file using the
I'm new to OpenCV and would like to use its Python binding. When trying
I am new to python. I would like all the python gurus to suggest
Am new in Python and would like to do a task... I need to
I am new to Python and would like to know if someone would kindly
I am a new user of python and would like to try subnets-resolver .
I am new to python and i would like to know how to make
So I am fairly new to python. But would like your help solving this
Obviously , I'm new to Python. I would like to use StringIO in my
I'm new to python and would like some assistance. I have a variable q

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.