Вы можете сделать это:
import numpy as np
# Generate random image
np.random.seed(42)
r = np.random.randint(0,256,(8,5,3), dtype=np.uint8)
# Make space for results
res = np.zeros((8,5),dtype=np.uint8)
# Calculate mask
res[(r[...,0]>r[...,1]) & (r[...,1]>r[...,2])] = 1
Массив ввода r
:
array([[[102, 220, 225],
[ 95, 179, 61],
[234, 203, 92], <--- matches
[ 3, 98, 243],
[ 14, 149, 245]],
[[ 46, 106, 244],
[ 99, 187, 71],
[212, 153, 199],
[188, 174, 65], <--- matches
[153, 20, 44]],
[[203, 152, 102], <--- matches
[214, 240, 39],
[121, 24, 34],
[114, 210, 65],
[239, 39, 214]],
[[244, 151, 25],
[ 74, 145, 222],
[ 14, 202, 85],
[145, 117, 87],
[184, 189, 221]],
[[116, 237, 109],
[ 85, 99, 172],
[226, 153, 103],
[235, 146, 36],
[151, 62, 68]],
[[181, 130, 160],
[160, 166, 149],
[ 6, 69, 5],
[ 52, 253, 112],
[ 14, 1, 3]],
[[ 76, 248, 87],
[233, 212, 184],
[235, 245, 26],
[213, 157, 253],
[ 68, 240, 37]],
[[219, 91, 54],
[129, 9, 51],
[ 0, 191, 20],
[140, 46, 187],
[147, 1, 254]]], dtype=uint8)
Массив результатов:
array([[0, 0, 1, 0, 0],
[0, 0, 0, 1, 0],
[1, 0, 0, 0, 0],
[1, 0, 0, 1, 0],
[0, 0, 1, 1, 0],
[0, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[1, 0, 0, 0, 0]], dtype=uint8)