Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark, in light modeAuto light/dark, in dark modeSkip to content
Pillow (PIL Fork) 12.0.0 documentation
Light LogoDark Logo
Pillow (PIL Fork) 12.0.0 documentation
Back to top

ImageMorph module

TheImageMorph module provides morphology operations on images.

classPIL.ImageMorph.LutBuilder(patterns:list[str]|None=None,op_name:str|None=None)[source]

Bases: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 4describes a series of symmetry operations (in this case a4-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 isreturned 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:list[str])None[source]
build_default_lut()None[source]
build_lut()bytearray[source]

Compile all patterns into a morphology lut.

TBD :Build based on (file) morphlut:modify_lut

get_lut()bytearray|None[source]
classPIL.ImageMorph.MorphOp(lut:bytearray|None=None,op_name:str|None=None,patterns:list[str]|None=None)[source]

Bases:object

A class for binary morphological operators

apply(image:Image)tuple[int,Image][source]

Run a single morphological operation on an image

Returns a tuple of the number of changed pixels and themorphed image

get_on_pixels(image:Image)list[tuple[int,int]][source]

Get a list of all turned on pixels in a binary image

Returns a list of tuples of (x,y) coordinatesof all matching pixels. SeeCoordinate system.

load_lut(filename:str)None[source]

Load an operator from an mrl file

match(image:Image)list[tuple[int,int]][source]

Get a list of coordinates matching the morphological operation onan image.

Returns a list of tuples of (x,y) coordinatesof all matching pixels. SeeCoordinate system.

save_lut(filename:str)None[source]

Save an operator to an mrl file

set_lut(lut:bytearray|None)None[source]

Set the lut from an external source


[8]
ページ先頭

©2009-2025 Movatter.jp