8

PythonImagingLibraryを使用して写真のRGB値を変更しようとしています。私は関数Image.pointを使用してきましたが、R、G、およびBの値に別の関数を実装できるようにしたいことを除いて、必要なことを実行します。誰かが私がこれを行う方法を知っていますか?

ありがとう!

4

1 に答える 1

7

numpy画像の個々のバンドの計算を行うために、PIL に加えて使用することをお勧めします。

決して見栄えを良くすることを意図していない不自然な例として:

import Image
import numpy as np

im = Image.open('snapshot.jpg')

# In this case, it's a 3-band (red, green, blue) image
# so we'll unpack the bands into 3 separate 2D arrays.
r, g, b = np.array(im).T

# Let's make an alpha (transparency) band based on where blue is < 100
a = np.zeros_like(b)
a[b < 100] = 255

# Random math... This isn't meant to look good...
# Keep in mind that these are unsigned 8-bit integers, and will overflow.
# You may want to convert to floats for some calculations.
r = (b + g) * 5

# Put things back together and save the result...
im = Image.fromarray(np.dstack([item.T for item in (r,g,b,a)]))

im.save('output.png')

入力 ここに画像の説明を入力


出力 ここに画像の説明を入力

于 2012-05-31T01:34:16.307 に答える