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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:39:24+00:00 2026-06-10T07:39:24+00:00

I have an image stored in a numpy array, as yielded by imread() :

  • 0

I have an image stored in a numpy array, as yielded by imread():

>>> ndim
array([[[  0,   0,   0],
        [  4,   0,   0],
        [  8,   0,   0],
        ..., 
        [247,   0,  28],
        [251,   0,  28],
        [255,   0,  28]],

       [[  0, 255, 227],
        [  4, 255, 227],
        [  8, 255, 227],
        ..., 
        [247, 255, 255],
        [251, 255, 255],
        [255, 255, 255]]], dtype=uint8)
>>> ndim.shape
(512, 512, 3)

I want to efficiently find the (x, y) coordinate (or coordinates) of pixels with a specific color value, e.g.

>>> c
array([ 32,  32, 109], dtype=uint8)

>>> ndim[200,200]
array([ 32,  32, 109], dtype=uint8)

>>> ndim.T[0, 200, 200]
32
>>> ndim.T[1, 200, 200]
32
>>> ndim.T[2, 200, 200]
109

… in this case, I know the pixel at (200, 200) has the RGB value (32, 32, 109) — I can test for this.

What I want to do is query the ndarray for a pixel value and get back the coordinates. In the above case, the putative function find_pixel(c) would return (200, 200).

Ideally this find_pixel() function would return a list of coordinate tuples and not just the first value it finds.

I’ve looked at numpy’s “fancy indexing”, which confused me greatly… Most of my attempts at figuring this out have been overwrought and unnecessarily baroque.

I am sure there is a very simple method that I am overlooking here. What is the best way to do this — is there an altogether better mechanism to get these values than that which I have outlined?

  • 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-10T07:39:26+00:00Added an answer on June 10, 2026 at 7:39 am

    For some array colour array a and a colour tuple c:

    indices = numpy.where(numpy.all(a == c, axis=-1))
    

    indices should now be a 2-tuple of arrays, the first of which contains the indices in the first dimensions and the second of which contains the indices in the second dimension corresponding to pixel values of c.

    If you need this as a list of coordinate tuples, use zip:

    coords = zip(indices[0], indices[1])
    

    For example:

    import numpy
    a = numpy.zeros((4, 4, 3), 'int')    
    
    for n in range(4):
        for m in range(4):
            a[n, m, :] = n + m
            if (n + m) == 4:
                print n, m
    
    c = (4, 4, 4)
    indices = numpy.where(numpy.all(a == c, axis=-1))
    print indices
    print zip(indices[0], indices[1])
    

    will output:

    1 3
    2 2
    3 1
    (array([1, 2, 3]), array([3, 2, 1]))
    [(1, 3), (2, 2), (3, 1)]
    

    which corresponds to all the pixels of value (4, 4, 4).

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

Sidebar

Related Questions

In numpy/scipy I have an image stored in an array. I can display it,
I have an 8bit Image (stored in an Array) containing black(0) and white(255) pixels.
Possible Duplicate: base64 encoded images in email signatures I have a image stored in
I have currently got imagepaths stored within the database and image files stored in
I have a string that contains HTML image elements that is stored in a
I have a service that converts images stored on a website to byte array
I have a image file stored at a remote server (i.e http://example.com/images).The images in
I have an image that is currently stored in variable of type File.. File
I have the following image xml tag in which image path is stored NSString
I have an image stored which I can view in a browser using http

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.