RGB channel만들기 ¶
~cpp import Image im = Image.open("lena.jpg") newR = Image.new("RGB",im.size) newG = Image.new("RGB",im.size) newB = Image.new("RGB",im.size) sizeX, sizeY = im.size for x in range(sizeX): for y in range(sizeY): r,g,b = im.getpixel((x,y)) newR.putpixel((x,y),(r,0,0)) newG.putpixel((x,y),(0,g,0)) newB.putpixel((x,y),(0,0,b)) newR.show() newG.show() newB.show()
RGB 별 Gray화 ¶
~cpp import Image im = Image.open("lena.jpg") newGray = Image.new("P",im.size) sizeX, sizeY = im.size for x in range(sizeX): for y in range(sizeY): r,g,b = im.getpixel((x,y)) k = (r + g + b) / 3 newGray.putpixel((x,y),k) newGray.show()
Whitening ¶
~cpp import Image im = Image.open("lena.jpg") for x in range(50,100): for y in range(50,100): r,g,b = im.getpixel((x,y)) im.putpixel((x,y),(r+50,g+50,b+50)) im.show()
Darkening ¶
~cpp import Image im = Image.open("lena.jpg") for x in range(50,100): for y in range(50,100): r,g,b = im.getpixel((x,y)) im.putpixel((x,y),(r-50,g-50,b-50)) im.show()
alpha ¶
~cpp import Image im = Image.open("lena.jpg") for x in range(50,100): for y in range(100,150): r1,g1,b1 = im.getpixel((x,y)) r2,g2,b2 = im.getpixel((x,y-100)) im.putpixel((x,y-100),((r1+r2)/2,(g1+g2)/2,(b1+b2)/2)) im.show()
== 모자이크 ==
캠이랑놀자
~cpp import Image im = Image.open("lena.jpg") for x in range(0,255,5): for y in range(0,255,5): r = g = b = 0 for m in range(x,x+5): for n in range(y,y+5): t1,t2,t3 = im.getpixel((m,n)) r += t1 g += t2 b += t3 for m in range(x,x+5): for n in range(y,y+5): im.putpixel((m,n),(r/25,g/25,b/25)) im.show()----
캠이랑놀자