image
pixeltable.functions.image
Pixeltable UDFs for ImageType
.
Example:
import pixeltable as pxt
t = pxt.get_table(...)
t.select(t.img_col.convert('L')).collect()
alpha_composite
alpha_composite(im1: ImageT, im2: ImageT) -> ImageT
Alpha composite im2
over im1
.
Equivalent to PIL.Image.alpha_composite()
b64_encode
b64_encode(img: ImageT, image_format: str = 'png') -> str
Convert image to a base64-encoded string.
Parameters:
-
img
(ImageT
) –image
-
image_format
(str
, default:'png'
) –image format supported by PIL
blend
blend(im1: ImageT, im2: ImageT, alpha: float) -> ImageT
Return a new image by interpolating between two input images, using a constant alpha.
Equivalent to PIL.Image.blend()
composite
composite(image1: ImageT, image2: ImageT, mask: ImageT) -> ImageT
Return a composite image by blending two images using a mask.
Equivalent to PIL.Image.composite()
convert
convert(self: ImageT, mode: str) -> ImageT
Convert the image to a different mode.
Equivalent to
PIL.Image.Image.convert()
.
Parameters:
-
mode
(str
) –The mode to convert to. See the Pillow documentation for a list of supported modes.
crop
crop(self: ImageT, box: JsonT) -> ImageT
Return a rectangular region from the image. The box is a 4-tuple defining the left, upper, right, and lower pixel coordinates.
Equivalent to
PIL.Image.Image.crop()
effect_spread
effect_spread(self: ImageT, distance: int) -> ImageT
Randomly spread pixels in an image.
Equivalent to
PIL.Image.Image.effect_spread()
Parameters:
-
distance
(int
) –The distance to spread pixels.
entropy
entropy(
self: ImageT, mask: Optional[ImageT] = None, extrema: Optional[JsonT] = None
) -> float
Returns the entropy of the image, optionally using a mask and extrema.
Equivalent to
PIL.Image.Image.entropy()
Parameters:
-
mask
(Optional[ImageT]
, default:None
) –An optional mask image.
-
extrema
(Optional[JsonT]
, default:None
) –An optional list of extrema.
get_metadata
get_metadata(self: ImageT) -> JsonT
Return metadata for the image.
getbands
getbands(self: ImageT) -> JsonT
Return a tuple containing the names of the image bands.
Equivalent to
PIL.Image.Image.getbands()
getbbox
getbbox(self: ImageT, *, alpha_only: bool = True) -> JsonT
Return a bounding box for the non-zero regions of the image.
Equivalent to PIL.Image.Image.getbbox()
Parameters:
-
alpha_only
(bool
, default:True
) –If
True
, and the image has an alpha channel, trim transparent pixels. Otherwise, trim pixels when all channels are zero.
getchannel
getchannel(self: ImageT, channel: int) -> ImageT
Return an L-mode image containing a single channel of the original image.
Equivalent to
PIL.Image.Image.getchannel()
Parameters:
-
channel
(int
) –The channel to extract. This is a 0-based index.
getcolors
getcolors(self: ImageT, maxcolors: int = 256) -> JsonT
Return a list of colors used in the image, up to a maximum of maxcolors
.
Equivalent to
PIL.Image.Image.getcolors()
Parameters:
-
maxcolors
(int
, default:256
) –The maximum number of colors to return.
getextrema
getextrema(self: ImageT) -> JsonT
Return a 2-tuple containing the minimum and maximum pixel values of the image.
Equivalent to
PIL.Image.Image.getextrema()
getpalette
getpalette(self: ImageT, mode: Optional[str] = None) -> JsonT
Return the palette of the image, optionally converting it to a different mode.
Equivalent to
PIL.Image.Image.getpalette()
Parameters:
-
mode
(Optional[str]
, default:None
) –The mode to convert the palette to.
getpixel
getpixel(self: ImageT, xy: ArrayT) -> JsonT
Return the pixel value at the given position. The position xy
is a tuple containing the x and y coordinates.
Equivalent to
PIL.Image.Image.getpixel()
Parameters:
-
xy
(ArrayT
) –The coordinates, given as (x, y).
getprojection
getprojection(self: ImageT) -> JsonT
Return two sequences representing the horizontal and vertical projection of the image.
Equivalent to
PIL.Image.Image.getprojection()
histogram
histogram(
self: ImageT, mask: Optional[ImageT] = None, extrema: Optional[JsonT] = None
) -> JsonT
Return a histogram for the image.
Equivalent to
PIL.Image.Image.histogram()
Parameters:
-
mask
(Optional[ImageT]
, default:None
) –An optional mask image.
-
extrema
(Optional[JsonT]
, default:None
) –An optional list of extrema.
quantize
quantize(
self: ImageT,
colors: int = 256,
method: Optional[int] = None,
kmeans: int = 0,
palette: Optional[int] = None,
dither: int = PIL.Image.Dither.FLOYDSTEINBERG,
) -> ImageT
Convert the image to 'P' mode with the specified number of colors.
Equivalent to
PIL.Image.Image.quantize()
Parameters:
-
colors
(int
, default:256
) –The number of colors to quantize to.
-
method
(Optional[int]
, default:None
) –The quantization method. See the Pillow documentation for a list of supported methods.
-
kmeans
(int
, default:0
) –The number of k-means clusters to use.
-
palette
(Optional[int]
, default:None
) –The palette to use.
-
dither
(int
, default:FLOYDSTEINBERG
) –The dithering method. See the Pillow documentation for a list of supported methods.
reduce
reduce(self: ImageT, factor: int, box: Optional[JsonT] = None) -> ImageT
Reduce the image by the given factor.
Equivalent to
PIL.Image.Image.reduce()
Parameters:
-
factor
(int
) –The reduction factor.
-
box
(Optional[JsonT]
, default:None
) –An optional 4-tuple of ints providing the source image region to be reduced. The values must be within (0, 0, width, height) rectangle. If omitted or None, the entire source is used.
resize
resize(self: ImageT, size: JsonT) -> ImageT
Return a resized copy of the image. The size parameter is a tuple containing the width and height of the new image.
Equivalent to
PIL.Image.Image.resize()
rotate
rotate(self: ImageT, angle: int) -> ImageT
Return a copy of the image rotated by the given angle.
Equivalent to
PIL.Image.Image.rotate()
Parameters:
-
angle
(int
) –The angle to rotate the image, in degrees. Positive angles are counter-clockwise.
transpose
transpose(self: ImageT, method: int) -> ImageT
Transpose the image.
Equivalent to
PIL.Image.Image.transpose()
Parameters:
-
method
(int
) –The transpose method. See the Pillow documentation for a list of supported methods.