ImagePath module Introduction to Python image processing library pil

Source: Internet
Author: User
Tags compact image processing library python list

ImagePath modules are used to store and manipulate two-dimensional vector data. The Path object is passed to the imagedraw module.

function of the ImagePath module

1. Path

Definition:imagepath.path (coordinates)? Path Instance

Meaning: Create a path object. The list of coordinates can be any form of sequence object, including two tuples [(x, y),...] or the value [x, y,...].

The user can also create a new path object from another path object.

In 1.1.6 and later versions, users can also enter any object that implements the python buffer API . This buffer should provide a read operation and Containc floats in machine byte order.

The Path object implements the sequence interface of most python , like a (x, y) pair. Users can use the len () function to access their internal items, slicing. However, the current version does not support shard alignment, or internal items and slice blocks are deleted.

Second, the method of ImagePath module

1. Compact

Definition:p.compact (distance=2)? Count

Meaning: Compress this pathby removing points close to each other. This method modifies the path itself to return the number of deleted points.

The variable distance is calculated by city distance, which defaults to two pixels.

Example:

>>> from PIL importimagepath>>> path =imagepath.path ((0,0,1,1,2,2,3,3,4,4,4,4,5,5,5,5,6,6)) > >> len (path) 9>>> path.compact (2) 2>>> len (path) 7

This function compresses (4,4,4,4,5,5,5,5) in the path object, so the length of the path object is reduced by 2.

2. Getbbox

Definition:p.getbbox () ? 4-tuple

Meaning: Gets the bounding box of the path object.

Example:

>>> from PIL importimagepath>>> path= Imagepath.path ((0,0,1,1,2,2,3,3,4,4,4,4,5,5,5,5,6,6)) > >> len (path) 9>>> Path.getbbox () (0.0, 0.0, 6.0, 6.0)

For a coordinate group (0,0,1,1,2,2,3,3,4,4,4,4,5,5,5,5,6,6), its upper-left corner is (0,0), and the lower-right corner is (6,6), So the method returns four tuples (0.0,0.0, 6.0, 6.0).

3. Map

Definition:p.map (function)

Meaning: The path object is mapped by the function specified by the variable function .

Example:

This example needs to be studied again.

4. Tolist

Definition:p.tolist () ? List

Meaning: Convert the path object to python list[(x, y),...].

Example:

>>> from PIL importimagepath>>> path =imagepath.path ((0,0,1,1,2,2,3,3,4,4,4,4,5,5,5,5,6,6)) > >> path.tolist () [(0.0, 0.0), (1.0, 1.0), (2.0,2.0), (3.0, 3.0), (4.0, 4.0), (4.0, 4.0), (5.0, 5.0), (5.0, 5.0), (6.0 , 6.0)]

5. Transform

Definition:p.transform (Matrix)

Meaning: The path object is converted using an affine transform. The variable matrix is a six-tuple and operates as follows:

Xout = xIn * A + YIn * b + C

yout = xIn * d + yIn * e + F

Example:

>>> from PIL importimagepath>>> path =imagepath.path ((0,0,1,1,2,2,3,3,4,4,4,4,5,5,5,5,6,6)) > >> path.tolist () [(0.0, 0.0), (1.0, 1.0), (2.0,2.0), (3.0, 3.0), (4.0, 4.0), (4.0, 4.0), (5.0, 5.0), (5.0, 5.0), (6.0 , 6.0)]>>>path.transform ((2,3,1,3,2,2)) >>> path.tolist () [(1.0, 2.0), (6.0, 7.0), (11.0,12.0), (16.0 , 17.0), (21.0, 22.0), (21.0, 22.0), (26.0, 27.0), (26.0, 27.0), (31.0, 32.0)]

ImagePath module Introduction to Python image processing library pil

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.