python3 read image and a method of visualizing (PIL / Pillow, opencv / cv2)

Original:

 

 

Use TensorFlow do image processing time, some images will visually manipulate. Now, on to list some of what I know and visualize the image reading method.

1. Pillow module

Pre-existence 1.1 Pillow module

Pillow is python2 the PIL module. PIL module (Python Imaging Library) is a powerful and convenient Python image processing library, but only supports Python2.7.

Pillow is a derivation branch PIL, but now has evolved into more dynamic than the PIL itself Python image processing library.

1.2 Pillow install module

The pillow is mounted at the two, by a first command line CMD directly pip. But I went wrong at the time of installation, the network is probably the reason. So I installed directly pycharm, no problems

CMD installation command: pip install Pillow

Pillow 1.3 using visualization module

Import Module 1.3.1 Pillow:

Import PIL 
or
from PIL import Image

If the import Pillow will write error "ModuleNotFoundError: No module named 'Pillow'", it may be because Pillow is the reason derived from the PIL it.

1.3.2 Image.open(img_path).convert()

convert()
convert () method is an instance of an object image, accepts a mode parameter for designating a color mode
------------------ 1 (1-bit pixels, black and white, one pixel per byte storage)
L ------------------ (. 8-bit pixels, black and white)
P ------------------ (. 8-bit pixels, palette mapping to use any other pattern)
RGB ------------------ (3x8-bit pixels, true color)
The RGBA ------------------ (4x8-bit pixels, true color with a transparency mask)
The CMYK -------------------- (4x8 bits pixel color separation)
The YCbCr -------------------- (3x8 bits pixel color video format)
The I ----------------------- (32 bit signed integer pixel)
F. ------------------------ (32-bit floating point pixels)

 

1.3.3 code directly 105, 106 two lines suffice:

 

 effect:

 

 

 Default opened with drawing tools.

If the convert () parameter to '1', the effect is as follows:

 

 The remaining parameters are not going to use.

2. cv2 module reads the image, matplotlib visual display

2.1 cv2 install module

pip install opencv-python

If the problem can not be installed or install, you can try pycharm or download the installation package in the official website for manual installation.

2.2 matplotlib for Python comes with no installation

2.3 Code:

 

 The results are as follows:

 

 Why not the same as the color image of the original image, such as color or flipped out of her, as they are inconsistent with the display mode cv2 matplotlib, the color image is read opencv BGR format, Matplotlib display a color image is RGB format.

Guess you like

Origin www.cnblogs.com/zrmw/p/11685066.html