I have an RGB image which I am loading into a 2D array using PIL

```
img = Image.open(path)
imgData = numpy.array(img)

```

I need to efficiently translate this into a 2D array of RGB tuples (in some sense a 3D array) the same size containing a rough 'classification' of each pixel - 'red', 'green', 'white' or 'other' - at each index based on which 'colour region' they lie within. This is for purposes of image recognition.

My current implementation uses a element-wise for loop but is very slow (an 8MP image takes 1+ minutes):

```
for i in range(cols): # for every col
    for j in range(rows): # for every row
        r,g,b = imgData[i,j]

        if b > 220:     # white
            n = 3
        elif r > 230:   # red
            n = 2
        else:           # green
            n = 1

        mapData[i,j] = n

```

(I realise that the order of the if statements here affects the precedence of the classifications - this is not a major issue for now although I would prefer to define the colour spaces exclusively)

I am running Python 3.6.4 and happy to use NumPy or not. Having done a bunch of research, it seems like there are a number of faster and more 'pythonic' and vectorised ways to do this but I have not been able to get any working.

Any help would be much appreciated
Thanks!