python "can't assign to comparison" error

3.4k Views Asked by At

I want single YCbCr-channels that are smaller or bigger that 128 of a picture set to 0. But I keep getting the error "can't assign to comparison" and I don't really know what I am doing wrong.

This is the code:

def calc_coloursplash(image_data, modus):
    ycbcr = image_data.convert('YCbCr')

    if modus == 1:
        ycbcr[:,:,1] <= 128 = 0
        ycbcr[:,:,2] <= 128 = 0
    elif modus == 2:
        ycbcr[:,:,1] >= 128 = 0
        ycbcr[:,:,2] <= 128 = 0
    elif modus == 3:
        ycbcr[:,:,1] >= 128 = 0
        ycbcr[:,:,2] >= 128 = 0
    elif modus == 4:
        ycbcr[:,:,1] <= 128 = 0
        ycbcr[:,:,2] >= 128 = 0
    else:
        print("There are only modes 1-4")

    return ycbcr

And this picture shows the different modes I implemented:

1

There are 1 best solutions below

3
On

you can use np.where:

ycbcr[:,:,1][np.where(ycbcr[:,:,1]<128)]=0