Skip to main content

module  pixeltable.functions.image

Pixeltable UDFs for ImageType. Example:
import pixeltable as pxt

t = pxt.get_table(...)
t.select(t.img_col.convert('L')).collect()

udf  alpha_composite()

Signature
alpha_composite(im1: pxt.Image, im2: pxt.Image) -> pxt.Image
Alpha composite im2 over im1. Equivalent to PIL.Image.alpha_composite()

udf  b64_encode()

Signature
b64_encode(
    img: pxt.Image,
    image_format: pxt.String = 'png'
) -> pxt.String
Convert image to a base64-encoded string. Parameters:
  • img (pxt.Image): image
  • image_format (pxt.String): image format supported by PIL

udf  blend()

Signature
blend(
    im1: pxt.Image,
    im2: pxt.Image,
    alpha: pxt.Float
) -> pxt.Image
Return a new image by interpolating between two input images, using a constant alpha. Equivalent to PIL.Image.blend()

udf  composite()

Signature
composite(
    image1: pxt.Image,
    image2: pxt.Image,
    mask: pxt.Image
) -> pxt.Image
Return a composite image by blending two images using a mask. Equivalent to PIL.Image.composite()

udf  convert()

Signature
convert(self: pxt.Image, mode: pxt.String) -> pxt.Image
Convert the image to a different mode. Equivalent to PIL.Image.Image.convert(). Parameters:
  • mode (pxt.String): The mode to convert to. See the Pillow documentation for a list of supported modes.

udf  crop()

Signature
crop(self: pxt.Image, box: pxt.Json) -> pxt.Image
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()

udf  effect_spread()

Signature
effect_spread(self: pxt.Image, distance: pxt.Int) -> pxt.Image
Randomly spread pixels in an image. Equivalent to PIL.Image.Image.effect_spread() Parameters:
  • distance (pxt.Int): The distance to spread pixels.

udf  entropy()

Signature
entropy(
    self: pxt.Image,
    mask: pxt.Image | None = None,
    extrema: pxt.Json | None = None
) -> pxt.Float
Returns the entropy of the image, optionally using a mask and extrema. Equivalent to PIL.Image.Image.entropy() Parameters:
  • mask (pxt.Image | None): An optional mask image.
  • extrema (pxt.Json | None): An optional list of extrema.

udf  get_metadata()

Signature
get_metadata(self: pxt.Image) -> pxt.Json
Return metadata for the image.

udf  getbands()

Signature
getbands(self: pxt.Image) -> pxt.Json
Return a tuple containing the names of the image bands. Equivalent to PIL.Image.Image.getbands()

udf  getbbox()

Signature
getbbox(
    self: pxt.Image,
    *,
    alpha_only: pxt.Bool = True
) -> pxt.Json | None
Return a bounding box for the non-zero regions of the image. Equivalent to PIL.Image.Image.getbbox() Parameters:
  • alpha_only (pxt.Bool): If True, and the image has an alpha channel, trim transparent pixels. Otherwise, trim pixels when all channels are zero.

udf  getchannel()

Signature
getchannel(self: pxt.Image, channel: pxt.Int) -> pxt.Image
Return an L-mode image containing a single channel of the original image. Equivalent to PIL.Image.Image.getchannel() Parameters:
  • channel (pxt.Int): The channel to extract. This is a 0-based index.

udf  getcolors()

Signature
getcolors(self: pxt.Image, maxcolors: pxt.Int = 256) -> pxt.Json
Return a list of colors used in the image, up to a maximum of maxcolors. Equivalent to PIL.Image.Image.getcolors() Parameters:
  • maxcolors (pxt.Int): The maximum number of colors to return.

udf  getextrema()

Signature
getextrema(self: pxt.Image) -> pxt.Json
Return a 2-tuple containing the minimum and maximum pixel values of the image. Equivalent to PIL.Image.Image.getextrema()

udf  getpalette()

Signature
getpalette(
    self: pxt.Image,
    mode: pxt.String | None = None
) -> pxt.Json | None
Return the palette of the image, optionally converting it to a different mode. Equivalent to PIL.Image.Image.getpalette() Parameters:
  • mode (pxt.String | None): The mode to convert the palette to.

udf  getpixel()

Signature
getpixel(self: pxt.Image, xy: pxt.Json) -> pxt.Json
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 (pxt.Json): The coordinates, given as (x, y).

udf  getprojection()

Signature
getprojection(self: pxt.Image) -> pxt.Json
Return two sequences representing the horizontal and vertical projection of the image. Equivalent to PIL.Image.Image.getprojection()

udf  height()

Signature
height(self: pxt.Image) -> pxt.Int
Return the height of the image.

udf  histogram()

Signature
histogram(
    self: pxt.Image,
    mask: pxt.Image | None = None,
    extrema: pxt.Json | None = None
) -> pxt.Json
Return a histogram for the image. Equivalent to PIL.Image.Image.histogram() Parameters:
  • mask (pxt.Image | None): An optional mask image.
  • extrema (pxt.Json | None): An optional list of extrema.

udf  mode()

Signature
mode(self: pxt.Image) -> pxt.String
Return the image mode.

udf  point()

Signature
point(
    self: pxt.Image,
    lut: pxt.Json,
    mode: pxt.String | None = None
) -> pxt.Image
Map image pixels through a lookup table. Equivalent to PIL.Image.Image.point() Parameters:
  • lut (pxt.Json): A lookup table.

udf  quantize()

Signature
quantize(
    self: pxt.Image,
    colors: pxt.Int = 256,
    method: pxt.Int | None = None,
    kmeans: pxt.Int = 0,
    palette: pxt.Image | None = None,
    dither: pxt.Int = <Dither.FLOYDSTEINBERG: 3>
) -> pxt.Image
Convert the image to ‘P’ mode with the specified number of colors. Equivalent to PIL.Image.Image.quantize() Parameters:
  • colors (pxt.Int): The number of colors to quantize to.
  • method (pxt.Int | None): The quantization method. See the Pillow documentation for a list of supported methods.
  • kmeans (pxt.Int): The number of k-means clusters to use.
  • palette (pxt.Image | None): The palette to use.
  • dither (pxt.Int): The dithering method. See the Pillow documentation for a list of supported methods.

udf  reduce()

Signature
reduce(
    self: pxt.Image,
    factor: pxt.Int,
    box: pxt.Json | None = None
) -> pxt.Image
Reduce the image by the given factor. Equivalent to PIL.Image.Image.reduce() Parameters:
  • factor (pxt.Int): The reduction factor.
  • box (pxt.Json | 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.

udf  resize()

Signature
resize(self: pxt.Image, size: pxt.Json) -> pxt.Image
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()

udf  rotate()

Signature
rotate(self: pxt.Image, angle: pxt.Int) -> pxt.Image
Return a copy of the image rotated by the given angle. Equivalent to PIL.Image.Image.rotate() Parameters:
  • angle (pxt.Int): The angle to rotate the image, in degrees. Positive angles are counter-clockwise.

udf  thumbnail()

Signature
thumbnail(
    self: pxt.Image,
    size: pxt.Json,
    resample: pxt.Int = <Resampling.LANCZOS: 1>,
    reducing_gap: pxt.Float | None = 2.0
) -> pxt.Image
Create a thumbnail of the image. Equivalent to PIL.Image.Image.thumbnail() Parameters:
  • size (pxt.Json): The size of the thumbnail, as a tuple of (width, height).
  • resample (pxt.Int): The resampling filter to use. See the Pillow documentation for a list of supported filters.
  • reducing_gap (pxt.Float | None): The reducing gap to use.

udf  transpose()

Signature
transpose(self: pxt.Image, method: pxt.Int) -> pxt.Image
Transpose the image. Equivalent to PIL.Image.Image.transpose() Parameters:
  • method (pxt.Int): The transpose method. See the Pillow documentation for a list of supported methods.

udf  width()

Signature
width(self: pxt.Image) -> pxt.Int
Return the width of the image.