python PIL library of image processing

  • PIL library is a python language third-party library, you need to install the tool through the pip, the name of the library is installed pillow.

  PIL library supports image storage, display and processing, it can handle almost all image formats, image scaling can be done, cropping, image overlay and to add lines, images and text operations.

    Functional Requirements:

  1. Picture Archiving: batch processing of the image, to generate a preview image, an image format conversion.
  2. Image processing: basic image processing, pixel processing, color processing and the like. 
  • PIL Image library Class Resolution

  Import method: from PIL import Image

  To load an image file, the simplest form follows function after all operations on the im

from PIL Import Image 
IM = Image.open ( " H: \\ Google b.jpg download \\ " )

  Common attributes:

  1. format: file format of the source file. If the image is created by the PIL, then its file format to None.
  2. mode: mode image. This indicates that the string used image pixel format. A typical value of the attribute "1", "L", "RGB" or "CMYK".
  3. size: size of the image is calculated according to the number of pixels. Its return value tuple width and height (width, height).
  4. palette: color palette table. If the image mode is "P", ImagePalette class instance is returned; otherwise, will be None.

  Micro examples:

from PIL import Image
im=Image.open("H:\\谷歌下载\\b.jpg")
print(im.format,im.size,im.mode)

 

 

   Micro examples:

  Swap color images. Color separation may be achieved by the exchange of three color channels RGB image.

from the PIL Import Image 
IM = Image.open ( " H: \\ Google b.jpg download \\ " ) 
R & lt, G, B = im.split () 
OM = Image.merge ( " the RGB " , (B, G, r)) 
om.save ( " H: \\ Google b.jpg download \\ " )

Before the exchange:

After the exchange:

  • PIL library ImageFilter Class Resolution
  1. BLUR: blur filter. Make pictures blurred than the original number.
  2. CONTOUR: Contour. I.e. contour filter, the contour information extracted from the image.
  3. DETALL: details. That is, detail enhancement filter, it will manifest the picture detail.
  4. EDGE_ENHANCE: edge enhancement. Edge enhancement filtering, projection, strengthen and improve the image enhancement method of image borders and contours between the different gray regions. And treated so that the boundary edge of the image is reflected in the image gray mutation, to improve the ability to identify the human eye.
  5. EDGE_ENHANCE_MORE: edge stronger. Depth filter edge enhancement, so that the image will be more apparent from the edge portion.
  6. EMBOSS: relief. Relief filter, which makes the image showing a relief effect.
  7. FIND_EDGES: edge look. Looking edge information filtering, finds the edge information in the image.
  8. SMOOTH: Smooth. Smoothing, large area projection image, low-frequency component, or stem portion and interference noise suppression high-frequency component image, image brightness gentle gradient, the gradient mutation reduced, improving image quality.
  9. SMOOTH_MORE: smoother. Depth of smoothing, so that the image will become smoother.
  10. SHARPEN: sharpening. Contour sharpening filter, the compensated image, edge enhancement, and grayscale image transition portion, image becomes clear.

  Micro examples: 

from PIL Import Image
 from PIL Import ImageFilter 
IM = Image.open ( " H: \\ Google b.jpg download \\ " ) 
OM = im.filter (ImageFilter.CONTOUR) 
om.save ( " H: \\ Google Download \ \ b.jpg " )

After treatment:

 

Guess you like

Origin www.cnblogs.com/DrcProgrammingCool/p/11781102.html