学习PIL模块笔记(二)
im.getextrema() => 2-tuple
im.getpixel(xy) => value or tuple
Returns the pixel at the given position. If the image is a multi-layer image, this method returns a tuple.
im.histogram() => list
Returns a histogram for the image. The histogram is returned as a list of pixel counts, one for each pixel value in the source image. If the image has more than one band, the histograms for all bands are concatenated (for example, the histogram for an "RGB" image contains 768 values).
im.histogram(mask) => list
Returns a histogram for those parts of the image where the mask image is non-zero. The mask image must have the same size as the image, and be either a bi-level image (mode "1") or a greyscale image ("L").
im.load()
Allocates storage for the image and loads it from the file (or from the source, for lazy operations). In normal cases, you don't need to call this method, since the Image class automatically loads an opened image when it is accessed for the first time.
pix = im.load() print pix[x, y] pix[x, y] = value
Access via this object is a lot faster than getpixel and putpixel.
im.offset(xoffset, yoffset) => image
(Deprecated) Returns a copy of the image where the data has been offset by the given distances. Data wraps around the edges. If yoffset is omitted, it is assumed to be equal to xoffset.
im.paste(image, box)
Pastes another image into this image. The box argument is either a 2-tuple giving the upper left corner, a 4-tuple defining the left, upper, right, and lower pixel coordinate, or None (same as (0, 0)). If a 4-tuple is given, the size of the pasted image must match the size of the region.
im.paste(colour, box)
Same as above, but fills the region with a single colour. The colour is given as a single numerical value for single-band images, and a tuple for multi-band images.
im.paste(image, box, mask)
Same as above, but updates only the regions indicated by the mask. You can use either "1", "L" or "RGBA" images (in the latter case, the alpha band is used as mask). Where the mask is 255, the given image is copied as is. Where the mask is 0, the current value is preserved. Intermediate values can be used for transparency effects.
im.paste(colour, box, mask)
Same as above, but fills the region indicated by the mask with a single colour.
im.point(table) => image
im.point(function) => image
Returns a copy of the image where each pixel has been mapped through the given table. The table should contains 256 values per band in the image. If a function is used instead, it should take a single argument. The function is called once for each possible pixel value, and the resulting table is applied to all bands of the image.
im.point(table, mode) => image
im.point(function, mode) => image
Map the image through table, and convert it on fly. This can be used to convert "L" and "P" images to "1" in one step, e.g. to threshold an image.
im.putalpha(band)
Copies the given band to the alpha layer of the current image.
im.putdata(data)
im.putdata(data, scale, offset)
Copy pixel values from a sequence object into the image, starting at the upper left corner (0, 0). The scale and offset values are used to adjust the sequence values:
im.putpalette(sequence)
Attach a palette to a "P" or "L" image. The palette sequence should contain 768 integer values, where each group of three values represent the red, green, and blue values for the corresponding pixel index. Instead of an integer sequence, you can use an 8-bit string.
im.putpixel(xy, colour)
Modifies the pixel at the given position. The colour is given as a single numerical value for single-band images, and a tuple for multi-band images.
im.load() putpixel = im.im.putpixel for i in range(n): ... putpixel((x, y), value)
In 1.1.6, the above is better written as:
pix = im.load() for i in range(n): ... pix[x, y] = value
22、resize
im.resize(size) => image
im.resize(size, filter) => image
Returns a resized copy of an image. The size argument gives the requested size in pixels, as a 2-tuple: (width, height).
im.rotate(angle) => image
im.rotate(angle, filter=NEAREST, expand=0) => image
Returns a copy of an image rotated the given number of degrees counter clockwise around its centre.
im.save(outfile, options...)
im.save(outfile, format, options...)
Saves the image under the given filename. If format is omitted, the format is determined from the filename extension, if possible. This method returns None.
im.seek(frame)
Seeks to the given frame in a sequence file. If you seek beyond the end of the sequence, the method raises an EOFError exception. When a sequence file is opened, the library automatically seeks to frame 0.
im.show()
Displays an image. This method is mainly intended for debugging purposes.
im.split() => sequence
Returns a tuple of individual image bands from an image. For example, splitting an "RGB" image creates three new images each containing a copy of one of the original bands (red, green, blue).
im.tell() => integer
Returns the current frame number.
im.thumbnail(size)
im.thumbnail(size, filter)
Modifies the image to contain a thumbnail version of itself, no larger than the given size. This method calculates an appropriate thumbnail size to preserve the aspect of the image, calls the draft method to configure the file reader (where applicable), and finally resizes the image.
im.tobitmap() => string
Returns the image converted to an X11 bitmap.
im.tostring() => string
Returns a string containing pixel data, using the standard "raw" encoder.
im.tostring(encoder, parameters) => string
Returns a string containing pixel data, using the given data encoding.
im.transform(size, method, data) => image
im.transform(size, method, data, filter) => image
Creates a new image with the given size, and the same mode as the original, and copies data to the new image using the given transform.
im.transform(size, EXTENT, data) => image
im.transform(size, EXTENT, data, filter) => image
Extracts a subregion from the image.
im.transform(size, AFFINE, data) => image
im.transform(size, AFFINE, data, filter) => image
Applies an affine transform to the image, and places the result in a new image with the given size.
im.transform(size, QUAD, data) => image
im.transform(size, QUAD, data, filter) => image
Maps a quadrilateral (a region defined by four corners) from the image to a rectangle with the given size.
im.transform(size, MESH, data) image => image
im.transform(size, MESH, data, filter) image => image
Similar to QUAD, but data is a list of target rectangles and corresponding source quadrilaterals.
im.transpose(method) => image
Returns a flipped or rotated copy of an image.
im.verify()
Attempts to determine if the file is broken, without actually decoding the image data. If this method finds any problems, it raises suitable exceptions. This method only works on a newly opened image; if the image has already been loaded, the result is undefined. Also, if you need to load the image after using this method, you must reopen the image file.
im.format => string or None
The file format of the source file. For images created by the library, this attribute is set to None.
im.mode => string
Image mode. This is a string specifying the pixel format used by the image. Typical values are "1", "L", "RGB", or "CMYK."
im.size => (width, height)
Image size, in pixels. The size is given as a 2-tuple (width, height).
im.palette => palette or None
Colour palette table, if any. If mode is "P", this should be an instance of the ImagePalette class. Otherwise, it should be set to None.
im.info => dictionary
A dictionary holding data associated with the image.
浙公网安备 33010602011771号