1 / 11

Python Essential 세미나

Python Essential 세미나. 2001. 5. 9( 수 ). The Python Imaging Library. 발표자 : 김진열. ● Python Imaging Library(PIL) 이란 ? (1). PIL 이란 ? 지원파일포맷 지원파일포맷별 확장자 PIL 사용예제 Open, Rotate, Save, Display - 손톱그림생성 -Crop, paste -Filtering -Tkinter 연동 참고사이트. Python Imaging Library 는 파이썬에서 이미지를

fisseha
Download Presentation

Python Essential 세미나

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Python Essential 세미나 2001. 5. 9(수) The Python Imaging Library 발표자 : 김진열

  2. ● Python Imaging Library(PIL)이란? (1) • PIL이란? • 지원파일포맷 • 지원파일포맷별 • 확장자 • PIL사용예제 • Open, Rotate, • Save, Display • -손톱그림생성 • -Crop, paste • -Filtering • -Tkinter 연동 • 참고사이트 • Python Imaging Library는 파이썬에서 이미지를 • 처리할 수 있게 한다. • 이 라이브러리는 다양한 파일 포맷을 지원하고, • 효율적인 내부 표현으로 강력한 이미지 처리 능력 • 을 갖는다. • 플랫폼은 Windows 및 Linux/Unix를 지원한다. • 코아(core) 이미지 라이브러리는 몇 가지의 • 기본적인 픽셀 포맷으로 저장되어 있는 데이터에 • 빠르게 접근한다. • 이 라이브러리는 일반적인 이미지 처리 도구의 • 기본으로 아주 적당하다.

  3. ● Python Imaging Library(PIL)이란? (2) • PIL이란? • 지원파일포맷 • 지원파일포맷별 • 확장자 • PIL사용예제 • Open, Rotate, • Save, Display • -손톱그림생성 • -Crop, paste • -Filtering • -Tkinter 연동 • 참고사이트 이 라이브러리는 다음과 같은 작업에 수행된다. Image Archives - PIL는 이미지 통합 저장과 배치 처리 응용 : thumbnail, 파일 포맷을 변환, 이미지를 출력 등 - 현재 버전으로도 많은 수의 포맷을 식별하고 읽는다. - 쓰기 지원은 국제적으로 몇몇의 자주 사용되는 교환 표현 포맷으로 제한 Image Display - 현재 릴리즈는 PythonWin에서 사용할 수 있는 Windows DIB 포맷 뿐 아니라 Tk PhotoImage와 BitmapImage 인터페이스도 포함 X와 Mac에서는 Jack Jansen의 img library를 사용 Image Processing - 기본적인 이미지 처리 함수 제공 : 점 연산, 내장 콘볼루션 커널들을 이용한 필터링, 색공간 변환등 - 이미지 크기 변환, 회전 및 임의의 밀접한 관계가 있는 변환 제공 - 히스토그램 메써드도 있어서 통계적인 이미지도 쉽게 도식

  4. ● PIL의 지원파일 포맷 BMP CUR (read only) DCX (read only) EPS (write-only) FLI, FLC (read only) FPX (read only) GBR (read only) GD (read only) GIF ICO (read only) IM IMT (read only) JPEG MIC (read only) MCIDAS (read only) MPEG (identify only) MSP PCD (read only) PCX PDF (write only) PNG PPM PSD (read only) SGI (read only) SUN (read only) TGA (read only) TIFF XBM XPM (read only) • PIL이란? • 지원파일포맷 • 지원파일포맷별 • 확장자 • PIL사용예제 • Open, Rotate, • Save, Display • -손톱그림생성 • -Crop, paste • -Filtering • -Tkinter 연동 • 참고사이트

  5. ● PIL의 지원파일 포맷별 확장자 BMP. ".bmp", ".dib" CUR. ".cur" DCX. ".dcx" EPS. ".eps", ".ps" FLI. ".fli", ".flc" FPX. ".fpx" GBR. ".gbr" GD. ".gd" GIF. ".gif" ICO. ".ico" IM. ".im" JPEG. ".jpg", ".jpe", ".jpeg" MIC. ".mic" MSP. ".msp" PCD. ".pcd" PCX. ".pcx" PDF. ".pdf" PNG. ".png" PPM. ".pbm", ".pgm", ".ppm" PSD. ".psd" SGI. ".bw", ".rgb", ".cmyk" SUN. ".ras" TGA. ".tga" TIFF. ".tif", ".tiff" XBM. ".xbm" XPM. ".xpm" • PIL이란? • 지원파일포맷 • 지원파일포맷별 • 확장자 • PIL사용예제 • Open, Rotate, • Save, Display • -손톱그림생성 • -Crop, paste • -Filtering • -Tkinter 연동 • 참고사이트

  6. <원본이미지> <변환된 이미지> ● PIL 사용예제(1) • PIL이란? • 지원파일포맷 • 지원파일포맷별 • 확장자 • PIL사용예제 • Open, Rotate, • Save, Display • -손톱그림생성 • -Crop, paste • -Filtering • -Tkinter 연동 • 참고사이트 1. Open, rotate, save, display import Image #Open Image im = Image.open("sample.jpg") #Rotate 45° r_im = im.rotate(45) #Save Image r_im.save("rotated_sample.jpg",'JPEG') #Display Image r_im.show() Show()는 우선 이미지파일을 BMP포맷으로 변환한 후 연동된 그래픽툴(그림판, ACDSEE등)에 의해 출력된다.

  7. <resize> <thumbnail> ● PIL 사용예제(2) • PIL이란? • 지원파일포맷 • 지원파일포맷별 • 확장자 • PIL사용예제 • Open, Rotate, • Save, Display • -손톱그림생성 • -Crop, paste • -Filtering • -Tkinter 연동 • 참고사이트 2. 손톱그림(thumbnails) 생성 ① resize를 이용한 경우 import os, Image infile = "sample.jpg " outfile = os.path.splitext(infile)[0]+ "_s" + ".jpg " Image.open(infile).resize((128,128)).save(outfile,"JPEG") ② thumbnail을 이용한 경우 import os, Image infile = "sample.jpg " outfile = os.path.splitext(infile)[0]+ "_s" + ".jpg " im = Image.open(infile) im.thumbnail((128,128)) im.save(outfile,"JPEG") ※ Thumbnail일 경우 원본이미지 비율에 맞게 축소

  8. <cutting된 이미지> <paste된 이미지> ● PIL 사용예제(3) • PIL이란? • 지원파일포맷 • 지원파일포맷별 • 확장자 • PIL사용예제 • Open, Rotate, • Save, Display • -손톱그림생성 • -Crop, paste • -Filtering • -Tkinter 연동 • 참고사이트 3. Crop, Paste ① Crop box = (100,100,400,400) cutting = im.crop(box) cutting.save("cutting_sample.jpg","JPEG") ② Paste cutting = cutting.rotate(180) im.paste(cutting,box) im.save("paste.jpg")

  9. <BLUR> <CONTOUR> <EMBOSS> ● PIL 사용예제(4) • PIL이란? • 지원파일포맷 • 지원파일포맷별 • 확장자 • PIL사용예제 • Open, Rotate, • Save, Display • -손톱그림생성 • -Crop, paste • -Filtering • -Tkinter 연동 • 참고사이트 4. Filtering ImageFilter Module을 사용하여 구현, 현재 지원되는 Filter는 다음과 같다. BLUR , CONTOUR , DETAIL, EDGE_ENHANCE, EDGE_ENHANCE_MORE, EMBOSS , FIND_EDGES , SMOOTH, SMOOTH_MORE, SHARPEN 사용예제 import ImageFilter imout = img.filter(ImageFilter.BLUR)

  10. <소스 실행결과> ● PIL 사용예제(5) • PIL이란? • 지원파일포맷 • 지원파일포맷별 • 확장자 • PIL사용예제 • Open, Rotate, • Save, Display • -손톱그림생성 • -Crop, paste • -Filtering • -Tkinter 연동 • 참고사이트 5. Tkinter와의 연동 ImageTk Module을 사용하여 구현 import ImageTk import Image win = ImageTk.Tkinter.Tk() im = Image.open("sample.jpg") img = ImageTk.PhotoImage(im) can = ImageTk.Tkinter.Canvas(win) can.pack() can.create_image(2,2,image=img) win.mainloop() Tkinter모듈의 PhotoImage는 GIF, PPM 포맷형식만을 지원한다. 그러나 ImageTk모듈을 이용하면 PIL이 지원하는 모든 파일 포맷을 사용할 수 있다.

  11. ● 참고사이트 • PIL이란? • 지원파일포맷 • 지원파일포맷별 • 확장자 • PIL사용예제 • Open, Rotate, • Save, Display • -손톱그림생성 • -Crop, paste • -Filtering • -Tkinter 연동 • 참고사이트 Python Imaging Library (PIL) - 이강성: http://www.python.or.kr:8080/python/GUI/pil/ PIL handbook : http://www.pythonware.com/library/pil/handbook/ License : http://www.pythonware.com/library/pil/handbook /software-license.htm

More Related