Try using Pillow on iPython (Part 2)

Pillow work flow (2)

  1. Load the image with Image.open
  2. Gonyo Gonyo the image
  3. Save the image edited with Image.save

Let's go.

python


%pylab inline
from PIL import Image,ImageDraw,ImageFont

File format conversion

python


#Load image
img = Image.open('in-image/lena_std.tif')

#File information display
print('size    : ', img.size)
print('format  : ', img.format) 
print('mode    : ', img.mode) 
print('palette : ', img.palette) 
print('info    : ', img.info) 

pl_img = np.array(img) ; plt.imshow( pl_img ) #display

#Convert the file format and save (automatically determine by looking at the extension)
img.save('work-image/lena.jpg') 

lena.jpg

Resize image file

python


img = Image.open('work-image/lena.jpg')

#File information display
print('size    : ', img.size)
print('format  : ', img.format) 
print('mode    : ', img.mode) 
print('palette : ', img.palette) 
print('info    : ', img.info) 

# 200*Resize to 200
resize_img = img.resize((200,200),Image.ANTIALIAS)

#File information display
print('size    : ', resize_img.size)
print('format  : ', resize_img.format) 
print('mode    : ', resize_img.mode) 
print('palette : ', resize_img.palette) 
print('info    : ', resize_img.info) 

#Save the converted data
resize_img.save('work-image/resize_lena.jpg') 

pl_img = np.array(resize_img) ; plt.imshow( pl_img ) #display

resize_lena.jpg

Image cropping

python


#The original data (img) has already been read, so trim it
trim_img = img.crop((64,64,448,448))

pl_img = np.array(trim_img) ; plt.imshow( pl_img ) #display

#Save trimmed data
trim_img.save('work-image/trim_lena.jpg') 

trim_lena.jpg

↓ I gave a notebook to nbviewer (I mean, this is the main one) nbviewer.ipython.org/github/suto3/git-public/blob/master/python/notebook/Pillow-workflow02.ipynb

↓ Click here for the working environment Pillow environment construction --Virtual environment by virtualenv, interactive environment by iPython --Qiita

Try using Pillow on iPython (Part 1) --Qiita

Try Pillow on iPython (Part 3) --Qiita

No, iPython is easy w.

Recommended Posts

Try using Pillow on iPython (Part 1)
Try using Pillow on iPython (Part 2)
Try using Pillow on iPython (Part 3)
Try using OpenCV on Windows
Try using SQLAlchemy + MySQL (Part 1)
Try using SQLAlchemy + MySQL (Part 2)
Try using ArUco on Raspberry Pi
Try using Bash on Windows 10 2 (TensorFlow installation)
Try using Tkinter
Try using docker-py
Try using cookiecutter
Try using PDFMiner
Try using geopandas
Try using Selenium
Try using scipy
Try using pandas.DataFrame
Try using django-swiftbrowser
Try using matplotlib
Try using tf.metrics
Try using PyODE
Graph analysis and visualization on IPython Notebook using Cytoscape / cyREST and py2cytoscape Part 1
Python: Try using the UI on Pythonista 3 on iPad
Try using the Python web framework Tornado Part 1
Make predictions using regression on actual data ~ part1
Try using the Python web framework Tornado Part 2
Visualize network data using Cytoscape from IPython Notebook Part 1
Try using virtualenv (virtualenvwrapper)
Try using E-Cell 4 on Windows 7 or Mac OS X
Try using the temperature sensor (LM75B) on the Raspberry Pi.
[Azure] Try using Azure Functions
I tried using Ipython
Try using virtualenv now
Try using W & B
Try using Django templates.html
[Kaggle] Try using LGBM
Try using Python's feedparser.
Try using Python's Tkinter
Try FEniCS on Windows!
Try Poerty on Windows
Try NeosVR on Linux
Notes on using Alembic
Try using Tweepy [Python2.7]
Try deepdream on Mac
Try using Pytorch's collate_fn
When using optparse with iPython
Try normal Linux programming Part 7
[Python] Try using Tkinter's canvas
OpenPose on MacBook Pro Part 2
Try using Jupyter's Docker image
Try using scikit-learn (1) --K-means clustering
Try function optimization using Hyperopt
Try StyleGAN on Google Colaboratory
Make iPython available on OSGeo4W
Try using matplotlib with PyCharm
Try using Azure Logic Apps
Try using Kubernetes Client -Python-
[Kaggle] Try using xg boost
Try using the Twitter API
Try normal Linux programming Part 2
[Django] Notes on using django-debug-toolbar
Displaying strings on IPython Notebook