0

I'm working in Python reading in images, and getting a 3-dimensional matrix of RGB values for pixels.

I want to take these 3-d arrays and make a matrix with only RGB values equal to r=62, g=57, b=47.

How can I do this? I've looked into masking but I don't understand how to implement this.

Edit: I'm talking about numpy arrays not lists. numpy has a lot of built in functions, for loops are pretty inefficient.

J. Smith
  • 143
  • 1
  • 2
  • 11
  • @Art I said arrays. imread from scimage.io returns a 3-d numpy array. – J. Smith Dec 12 '16 at 00:40
  • 1
    @TigerhawkT3 that post is for lists, does it also work for 3-d numpy arrays? – J. Smith Dec 12 '16 at 00:41
  • That would be http://stackoverflow.com/questions/19666626/replace-all-elements-of-python-numpy-array-that-are-greater-than-some-value instead then. Next time, please provide all relevant information within your question. – TigerhawkT3 Dec 12 '16 at 00:45

1 Answers1

1

If rgb is a NumPy array, then this should work:

rgb[rgb!=[62,57,47]]=0
DYZ
  • 55,249
  • 10
  • 64
  • 93