Let's go.
python
%pylab inline
from PIL import Image,ImageDraw,ImageFont
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')
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
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')
↓ 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