ImageMorph
Module¶
The ImageMorph
module provides morphology operations on images.
-
class
PIL.ImageMorph.
LutBuilder
(patterns=None, op_name=None)[源代码] 基类:
object
A class for building a MorphLut from a descriptive language
The input patterns is a list of a strings sequences like these:
4:(... .1. 111)->1
(whitespaces including linebreaks are ignored). The option 4 describes a series of symmetry operations (in this case a 4-rotation), the pattern is described by:
- . or X - Ignore
- 1 - Pixel is on
- 0 - Pixel is off
The result of the operation is described after “->” string.
The default is to return the current pixel value, which is returned if no other match is found.
Operations:
- 4 - 4 way rotation
- N - Negate
- 1 - Dummy op for no other operation (an op must always be given)
- M - Mirroring
Example:
lb = LutBuilder(patterns = ["4:(... .1. 111)->1"]) lut = lb.build_lut()
-
add_patterns
(patterns)[源代码]
-
build_default_lut
()[源代码]
-
build_lut
()[源代码] Compile all patterns into a morphology lut.
TBD :Build based on (file) morphlut:modify_lut
-
get_lut
()[源代码]
-
class
PIL.ImageMorph.
MorphOp
(lut=None, op_name=None, patterns=None)[源代码] 基类:
object
A class for binary morphological operators
-
apply
(image)[源代码] Run a single morphological operation on an image
Returns a tuple of the number of changed pixels and the morphed image
-
get_on_pixels
(image)[源代码] Get a list of all turned on pixels in a binary image
Returns a list of tuples of (x,y) coordinates of all matching pixels.
-
load_lut
(filename)[源代码] Load an operator from an mrl file
-
match
(image)[源代码] Get a list of coordinates matching the morphological operation on an image.
Returns a list of tuples of (x,y) coordinates of all matching pixels.
-
save_lut
(filename)[源代码] Save an operator to an mrl file
-
set_lut
(lut)[源代码] Set the lut from an external source
-