ImagenMaskReference

@PublicPreviewAPI
abstract classImagenMaskReference :ImagenReferenceImage

Known direct subclasses
ImagenBackgroundMask

A generated mask image which will auto-detect and mask out the background.

ImagenForegroundMask

A generated mask image which will auto-detect and mask out the foreground.

ImagenRawMask

Represents a mask for Imagen editing.

ImagenSemanticMask

Represents a generated mask for Imagen editing which masks out certain objects using object detection.


Represents a mask for Imagen editing. This image (generated or provided) should contain only black and white pixels, with black representing parts of the image which should not change.

Summary

Public companion functions

List<ImagenReferenceImage>
generateMaskAndPadForOutpainting(
    image: ImagenInlineImage,
    newDimensions: Dimensions,
    newPosition: ImagenImagePlacement
)

Generates two reference images ofImagenRawImage andImagenRawMask.

List<ImagenReferenceImage>
generateMaskAndPadForOutpainting(
    image: ImagenInlineImage,
    newDimensions: Dimensions,
    newPosition: ImagenImagePlacement,
    dilation: Double
)

Generates two reference images ofImagenRawImage andImagenRawMask.

Public companion functions

generateMaskAndPadForOutpainting

fun generateMaskAndPadForOutpainting(
    image: ImagenInlineImage,
    newDimensions: Dimensions,
    newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER
): List<ImagenReferenceImage>

Generates two reference images ofImagenRawImage andImagenRawMask. These images are generated in this order:

  • OneImagenRawImage containing the original image, padded out to the new dimensions with black pixels, with the original image placed at the given placement

  • OneImagenRawMask of the same dimensions containing white everywhere except at the placement original image. This is the format expected by Imagen for outpainting requests.

Parameters
image: ImagenInlineImage

the original image

newDimensions: Dimensions

the new dimensions for outpainting. These new dimensionsmust be more than the original image.

newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER

the placement of the original image within the new outpainted image.

generateMaskAndPadForOutpainting

fun generateMaskAndPadForOutpainting(
    image: ImagenInlineImage,
    newDimensions: Dimensions,
    newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER,
    dilation: Double = 0.01
): List<ImagenReferenceImage>

Generates two reference images ofImagenRawImage andImagenRawMask. These images are generated in this order:

  • OneImagenRawImage containing the original image, padded out to the new dimensions with black pixels, with the original image placed at the given placement

  • OneImagenRawMask of the same dimensions containing white everywhere except at the placement original image. This is the format expected by Imagen for outpainting requests.

Parameters
image: ImagenInlineImage

the original image

newDimensions: Dimensions

the new dimensions for outpainting. These new dimensionsmust be more than the original image.

newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER

the placement of the original image within the new outpainted image.

dilation: Double = 0.01

the dilation for the outpainting mask. See:ImagenRawMask.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-28 UTC.