1

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:

funie200
  • 3,688
  • 5
  • 21
  • 34
ryanmitchell
  • 13
  • 1
  • 3

1 Answers1

1

you can use np.where:

ycbcr[:,:,1][np.where(ycbcr[:,:,1]<128)]=0
YFrog
  • 109
  • 6
  • Thanks, but then it shows me "image object is not subscriptable" as an error – ryanmitchell Jan 19 '20 at 23:08
  • i think you use the PIl package. you can use: a = np.array(a) from here: https://stackoverflow.com/questions/384759/how-to-convert-a-pil-image-into-a-numpy-array – YFrog Jan 19 '20 at 23:13
  • I'm just doing ```image = Image.open("ahab.jpg")``` and then ```ycbcr = image.convert('YCbCr')```. Could it be the wrong way of loading the image? – ryanmitchell Jan 19 '20 at 23:19