PIL 이용한 이미지처리 - 3 본문

[PL]/Python

PIL 이용한 이미지처리 - 3

객과 함께. 2007. 9. 20. 16:06
아래 예제들은 제가 PIL문서를 공부하면서 예제 부분을 작성한 것입니다.
아래 예제을 사용시 문제가 생겨도 책임 지지 않습니다.
자세한 사항은 PIL문서를 참고 하시길....
	< Public Image Library  >
	EX 1)
	#!/usr/bin/python
	import Image, sys
	im = Image.open("00.jpg")
	r,g,b = im.split()
	ima = Image.merge("RGB",(b,g,r))
	ima.save("006.jpg")
	EX 2)
	#!/usr/bin/python
	import Image, sys
	im = Image.open("01.jpg")
	box = (100,100,400,400)
	region = im.crop(box)
	im.save("006.jpg")
	EX 3)
	#!/usr/bin/python
	#coding: cp949
	import Image, sys
	im = Image.open("01.jpg")
	cut = im.resize((128,128))
	cut = im.rotate(45)
	im.save("007.jpg")
	EX 4)
	#!/usr/bin/python
	import Image, sys
	im = Image.open("00.jpg").convert("L")
	im.save("009.jpg")
	im = Image.open("009.jpg").convert("RGB")
	im.save("042.jpg")
	im = Image.open("042.jpg").convert("1")
	im.save("010.jpg")
	EX 5)
	#!/usr/bin/python
	#coding: cp949
	import ImageFilter, Image
	im = Image.open("00.jpg")
	out = im.point(lambda i: i * 1.2)
	im.save("035.jpg")
	EX 6)
	#!/usr/bin/python
	#coding: cp949
	import Image
	im = Image.new("RGB",(747,1116),(34,143,100))
	im.save("049.jpg")
	EX 7)
	#!/usr/bin/python
	import Image,math
	im = Image.open("01.jpg")
	ima = Image.open("00.jpg")
	out = Image.blend(ima, im, 9.3)
	out.save("051.jpg")
	EX 8)
	#!/usr/bin/python
	import Image
	im = Image.open("00.jpg")
	out = Image.eval(lambda i: i * 1.2 + 1.0 ,  im )
	out.save("052.jpg")
	EX 9)
	#!/usr/bin/python
	#coding: cp949
	import Image
	R,G,B = 2, 3,4
	im = Image.open("00.jpg")
	im.convert("L")
	im.L = R * 999/1000 + G * 887/1000 + B * 114/1000
	im.save("053.jpg")
	EX 10)
	#!/usr/bin/python
	#coding: cp949
	import Image
	im = Image.open("01.jpg")
	im.copy().save("004.jpg")
	im.crop((100,100,500,500)).save("005.jpg")
	EX 11)
	import Image
	im = Image.open("00.jpg")
	am = im.getbands()
	print am
	EX 12)
	#!/usr/bin/python
	#coding: cp949
	import Image
	im = Image.open("01.jpg")
	am = im.getpixel((50,50))
	print am
	EX 13)
	#!/usr/bin/python
	#coding: cp949
	import Image
	im = Image.open("010.jpg")
	im.thumbnail((400,200)) 
	im.save("010.png")
	EX 14)
	#!/usr/bin/python
	#coding: cp949
	import Image
	im = Image.open("01.jpg")
	#im.transform((600,900), Image.EXTENT,(100,100,500,500))
	#im.save("012.jpg")
	#im.transform((747,1116), Image.EXTENT,(100,100,500,500), mage.BICUBIC)
	#im.save("013.jpg")
	#im.transform((300,700), Image.AFFINE,(1.2, 0, 1, 2, 0, 1))
	#im.save("014.jpg")
	#im.transform((300,700), Image.AFFINE,(1.2, 0, 1, 2, 0, 1),Image.BILINEAR)
	#im.save("015.jpg")
	im.transform((747,1116), Image.MESH, [0,0,2,1,0,1,0,1])
	im.save("016.jpg")
	EX 15)
	#!/usr/bin/python
	#coding: cp949
	import ImageChops,Image
	im = Image.open("01.jpg")
	ImageChops.constant(im, 1.2)
	im.save("018.jpg")
	EX 16)
	#!/usr/bin/python
	#coding: cp949
	import ImageChops, Image
	im = Image.open("01.jpg")
	ImageChops.invert(im)
	im.save("020.jpg")
	EX 17)
	#!/usr/bin/python
	#coding: cp949
	import ImageChops, Image
	im = Image.open("02.jpg")
	am = Image.open("01.jpg")
	out = ImageChops.darker(im, am).save("022.jpg")
	EX 18)
	#!/usr/bin/python
	#coding: cp949
	import Image , ImageChops
	im = Image.open("00.jpg")
	am = Image.open("01.jpg")
	out = ImageChops.difference(im,am)
	out.save("023.jpg")
	EX 19)
	#!/usr/bin/python
	#coding: cp949
	import Image , ImageChops
	im = Image.open("00.jpg")
	am = Image.open("01.jpg")
	out = ImageChops.multiply(im,am)
	out.save("024.jpg")
	EX 20)
	#!/usr/bin/python
	#coding: cp949
	import Image , ImageChops
	im = Image.open("00.jpg")
	am = Image.open("01.jpg")
	out = ImageChops.screen(im, am)
	out.save("025.jpg")
	EX 21)
	#!/usr/bin/python
	#coding: cp949
	import Image , ImageChops
	im = Image.open("01.jpg")
	am = Image.open("02.jpg")
	out = ImageChops.blend(im, am, 0.5)
	out.save("025.jpg")
	EX 22)
	#!/usr/bin/python
	#coding: cp949
	import PIL, Image
	im = Image.open("00.jpg")
	out = CrackCode(im, cc.area(0.9), cc.bbox(right))
	out.save("026.jpg")
	EX 23)
	#!/usr/bin/python
	#coding: cp949
	import ImageOps,Image
	im = Image.open("040.jpg")
	am = ImageOps.autocontrast(im, cutoff=30)
	cm = ImageOps.crop(am, border=40)
	bm = ImageOps.equalize(cm) 
	dm = ImageOps.expand(bm, border=10, fill=12) 
	em = ImageOps.fit(dm, (500,900), Image.NEAREST, 20, (0.9 , 1.9)) 
	fm = ImageOps.flip(em)
	gm = ImageOps.grayscale(fm)
	hm = ImageOps.invert(gm) 
	jm = ImageOps.mirror(hm) 
	vm = ImageOps.solarize(jm, threshold=128)
	vm.save("041.jpg")

'[PL] > Python' 카테고리의 다른 글

[GUI ] wxpython 을 사용하여.  (0) 2007.10.12
wxpython .............  (0) 2007.10.11
PIL 이용한 이미지처리 - 2  (0) 2007.09.20
PIL 모듈을이용하여 이미지 처리  (0) 2007.09.17
연산 예제 프로그램  (0) 2007.08.27