Notice
Recent Posts
Recent Comments
Link
- Arawn's Dev Blog
- Outsider's Dev Story
- Toby's Epril
- Benelog
- NHN 개발자 블로그
- SK 플래닛 기술 블로그
- OLC CENTER
- 소프트웨어 경영/공학 블로그
- 모바일 컨버전스
- KOSR - Korea Operating System …
- 넥스트리 블로그
- 리버스코어 ReverseCore
- SLiPP
- 개발자를 위하여... (Nextree 임병인 수석)
- "트위터 부트스트랩: 디자이너도 놀라워할 매끈하고 직관…
- Learning English - The English…
- real-english.com
- 'DataScience/Deep Learning' 카테…
- Deep Learning Summer School, M…
- Deep Learning Courses
민서네집
[python] Image Crop/Resize , JPEG Image를 TensorFlow 입력으로 변환 본문
from PIL import Image new_width = 256 new_height = 256 image = Image.open("original.jpg") width, height = image.size # Get dimensions left = (width - new_width)/2 top = (height - new_height)/2 right = (width + new_width)/2 bottom = (height + new_height)/2 image = image.crop((left, top, right, bottom)) image.save("cropped_image.jpg")imageCrop.py
|
[출처]
https://www.facebook.com/groups/TensorFlowKR/permalink/325407324466999
import tensorflow as tf import matplotlib import matplotlib.pyplot as plt import numpy as np import os from PIL import Image ''' Example: image resizing with TensorFlow API [Reference] https://github.com/thomaspark-pkj/tf-image-classification/blob/master/convert.py http://stackoverflow.com/questions/20060096/installing-pil-with-pip ''' cur_dir = os.getcwd() FLAGS = tf.app.flags.FLAGS FLAGS.height=256 FLAGS.width=256 FLAGS.depth=3 def convert_images(sess): value = tf.read_file('original.jpg') decoded_image = tf.image.decode_jpeg(value, channels=FLAGS.depth) resized_image = tf.image.resize_images(decoded_image, FLAGS.height, FLAGS.width) resized_image = tf.cast(resized_image, tf.uint8) try: image = sess.run(resized_image) except Exception as e: print e.message plt.imshow(np.reshape(image.data, [256, 256, FLAGS.depth])) plt.show() img = Image.fromarray(image, "RGB") img.save(os.path.join(cur_dir,"resized.jpg")) def main(argv = None): with tf.Session() as sess: convert_images(sess) if __name__ == '__main__': tf.app.run()tensorflow_resize.py
'Python' 카테고리의 다른 글
How to get python module(file) location (inspect 모듈 사용) (0) | 2016.08.21 |
---|---|
[2016-08-18][Study] 딥엘라스틱: 파트 3 (0) | 2016.08.19 |
PyCharm 원격 빌드 설정 (0) | 2016.08.15 |
Windows 10 Ubuntu Bash Shell 에서 TensorFlow 설치하기 (2) | 2016.08.15 |
Jupyter notebook에서 Root 디렉터리 들어가기 (0) | 2016.08.15 |
Comments