Using Python for Digital image processing __python

Source: Internet
Author: User
Tags cos glob

PiL (Python Imaging library) is a standard library of image processing on the Python platform. The function is very powerful, but the API is simple and easy to use.
As PIL only supported the Python2.7 and the years of disrepair, a group of volunteers created a compatible version of PIL based on the name Pillow, supporting the latest python3.x and adding many new features. -Liaoche

1. Install Pillow

Use the PIP installation at the command line.

Pip Install Pillow

Official documents:
Pillow Official Document 2. Operation Image 2.1 image Open, rotate and display

Rotate the image 90 ° to show

From PIL import Image
im = Image.open ("middlebury_02_noisy_depth. PNG ")
im.rotate. Show ()
2.2 Preservation of the image

Creates a 128*128 thumbnail for the PNG file in the current directory.

From PIL import Image
import glob,os
size = 128,128 to
infile in Glob.glob ("*. PNG "):
    File,ext = Os.path.splitext (infile)
    im = Image.open (infile)
    im.thumbnail (size)
    Im.save ( File + ". Thumbnail", "PNG")

Website Reference 2.3 at the same time show more than one picture

Display this image.

Image.show (Title=none,command=none)

This are mainly intended for debugging purposes.
On Windows, it saves the "image to a temporary BMP file and uses" standard BMP display utility to show it (usually Paint ).

Parameters: title: Optional title to the "image window,where possible command: command used to show The image

This task for OpenCV and Matlab are very simple.
OPENCV implementation: Display two pictures in one window
The realization of MATLAB: with subplot can.

So how do you do that with Python? There are many ways to find the Internet, and the feeling is foggy until I see the following sentence: (The Gospel of Citrus)

In addition to using OPENCV in Python, you can also manipulate pictures using the matplotlib and PIL libraries. I prefer matpoltlib, because its syntax is more like MATLAB.

In Matplotlib, a figure object can contain multiple child graphs (Axes) that can be drawn quickly using subplot ().
Matplotlib to draw multiple child graphs--subplot

#!/usr/bin/env Python3        
#-*-coding:utf-8-*-  

import matplotlib.pyplot as Plt
import NumPy as NP

def f (t) : Return
    Np.exp (-t) * NP.COS (2 * np.pi * t)

if __name__== ' __main__ ':
    t1 = np.arange (0, 5, 0.1)
    t2 = Np.ara Nge (0, 5, 0.02)

    plt.figure (a)
    plt.subplot (221)
    plt.plot (T1, F (T1), ' Bo ', T2, F (T2), ' r--')

    Plt.subplot (222)
    Plt.plot (T2, Np.cos (2 * np.pi * T2), ' r--') plt.subplot (

    212)
    Plt.plot ([1,2,3,4],[ 1,4,9,16])

    plt.show ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.