PIL rotate image colors (BGR -> RGB)

后端 未结 11 2190
深忆病人
深忆病人 2020-11-29 21:21

I have an image where the colors are BGR. How can I transform my PIL image to swap the B and R elements of each pixel in an efficient manner?

11条回答
  •  庸人自扰
    2020-11-29 22:00

    Assuming no alpha band, isn't it as simple as this?

    b, g, r = im.split()
    im = Image.merge("RGB", (r, g, b))
    

    Edit:

    Hmm... It seems PIL has a few bugs in this regard... im.split() doesn't seem to work with recent versions of PIL (1.1.7). It may (?) still work with 1.1.6, though...

提交回复
热议问题