0

I'm struggling to find the (x,y) coordinate of certain RGB values in an image. Lets say I edit an image and put a single pixel of (0,255,5), how can I find the 2D coordinate?

My current approach is using numpy.where, but it doesn't seem to work. I'm aware of opencv storing images in BGR. I don't really want to use the HSV approach and inRange because I just want single pixels of very specific values, so that would be overkill.

    import numpy as np
    import cv2

    im = cv2.imread(image)
    point = np.where(im == 5,255,0))
chris
  • 4,840
  • 5
  • 35
  • 66
  • Shouldn't it be something like `np.where(im == [0,255,5]))` ? – Miki Nov 11 '16 at 10:04
  • that does the same thing unfortunately – chris Nov 11 '16 at 10:06
  • The approach is basically correct. You just need to use Python correctly(which is not really my thing :D). Check [here](http://stackoverflow.com/a/12138972/5008845) – Miki Nov 11 '16 at 10:10
  • yeah I know this is simple, ive used opencv a lot in python and c++ so this frustrates me to no end! – chris Nov 11 '16 at 10:11
  • You say you are aware of BGR vs RGB but still you search for RGB? Why is that? I think you should search for `np.where(im == [5,255,0]))` – Mailerdaimon Nov 11 '16 at 10:17
  • sorry i wrote it wrong in question. that still returns way more values than it should so i dont think its working – chris Nov 11 '16 at 10:19
  • Are you sure that there can be only one pixel with that exact value? Have you checked the results? Maybe there realy are more pixel with this bgr value? – Mailerdaimon Nov 11 '16 at 10:21
  • And check out this question, it is about replacing pixels but includes finding them first: http://stackoverflow.com/questions/11433604/opencv-setting-all-pixels-of-specific-bgr-value-to-another-bgr-value – Mailerdaimon Nov 11 '16 at 10:23
  • i just checked for pink pixels and there is nothing even remotely pink, still returns a lot. ill check it out thanks – chris Nov 11 '16 at 10:24
  • I think @Mailerdaimon is correct , your image must contain many pixels of same value.. You should check it first. You can also use a trick, convert your image to BGRA and the whole img will have same alpha value, you can change alpha value of pixel which you are editing, slightly. And then use np.where(im == (5,255,0,alpha_value)) – Garvita Tiwari Nov 11 '16 at 10:28
  • Possible duplicate of [Finding the (x,y) indexes of specific (R,G,B) color values from images stored in NumPy ndarrays](http://stackoverflow.com/questions/12138339/finding-the-x-y-indexes-of-specific-r-g-b-color-values-from-images-stored-in) – Mailerdaimon Nov 11 '16 at 10:34

0 Answers0