Image processing by python (Pillow)

Motivation

・ I studied image processing with python in order to play with the raspberry pi and the sensor in combination.

Environment to use

Install Anaconda (python3.5) https://www.continuum.io/downloads

sample.png

・ All information stored in pixels is one-dimensional ・ Generally, convert from RGB to grayscale with the following formula

Y = 0.299 * R + 0.587 * G + 0.114 * B

・ Y is brightness (represents light intensity)

Grayscale conversion code

test.py


#Load a class that represents an image
from PIL import Image
#Open sample image
img = Image.open('sample.png')

#Convert to grayscale
gray_img = img.convert('L')
gray_img.save('sample-gray.png')

Execute with the following command

$ python test.py

sample-gray.png

RGB replacement

test2.py


from PIL import Image
img = Image.open('sample.png')

r, g, b = img.split()

img = Image.merge("RGB", (b,r,g))
img.save('sample-convert.png')

sample-convert.png

Finally

Since I was able to process the image, I would like to do image recognition (corresponding to scale changes) next time.

Recommended Posts

Image processing by python (Pillow)
python image processing
Communication processing by Python
Image processing by Python 100 knock # 1 channel replacement
First Python image processing
Grayscale by matrix-Reinventor of Python image processing-
100 image processing by Python Knock # 6 Color reduction processing
Image processing with Python
Easy image processing in Python with Pillow
Image processing by Python 100 knock # 11 smoothing filter (average filter)
Image processing with PIL (Pillow)
Image Processing Collection in Python
[Python] Image processing with scikit-image
Image processing by matrix Basics & Table of Contents-Reinventor of Python image processing-
Personal notes for python image processing
Image processing with Python 100 knocks # 3 Binarization
Image processing with Python 100 knocks # 2 Grayscale
100 Language Processing Knock Chapter 1 by Python
[Image processing] Posterization
Basics of binarized image processing with Python
Image processing with Python 100 knock # 10 median filter
Socket communication and multi-thread processing by Python
Image processing with Python 100 knocks # 8 Max pooling
Straight line drawing by matrix-Inventor's original research of Python image processing-
Python file processing
Image processing with Python 100 knock # 12 motion filter
Drawing with Matrix-Reinventor of Python Image Processing-
Analysis of X-ray microtomography image by Python
Image processing 100 knocks ①
Image processing with Python 100 knocks # 7 Average pooling
Light image processing with Python x OpenCV
Matrix Convolution Filtering-Reinventor of Python Image Processing-
Image processing with Python 100 knocks # 9 Gaussian filter
Image processing from scratch with python (5) Fourier transform
Image processing from scratch with python (4) Contour extraction
Image processing? The story of starting Python for
Primality test by Python
Python distributed processing Spartan
Image processing with MyHDL
File processing in Python
Python: Natural language processing
Visualization memo by Python
Multithreaded processing in python
Flat Field image processing
Read digital image processing
Affine transformation by matrix (scaling, rotation, shearing, movement) -Reinventor of Python image processing-
Text processing in Python
Image format in Python
Beamformer response by python
Python string processing illustration
Various processing of Python
Image Processing with PIL
Notes on HDR and RAW image processing with Python
[Python] Specify the range from the image by dragging the mouse
JPEG image generation by specifying quality with Python + OpenCV
[Python] Mask the image into a circle using Pillow
Learn Python asynchronous processing / coroutines by comparing with Node.js
[Python] Send gmail with python: Send one by one with multiple image files attached
100 Language Processing with Python Knock 2015
UTF8 text processing in python
opencv-python Introduction to image processing