ImagenMaskReference

@PublicPreviewAPI
public abstract classImagenMaskReference extendsImagenReferenceImage

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

Nested types

Public methods

static final @NonNullList<@NonNullImagenReferenceImage>

Generates two reference images ofImagenRawImage andImagenRawMask.

static final @NonNullList<@NonNullImagenReferenceImage>
generateMaskAndPadForOutpainting(
    @NonNullImagenInlineImage image,
    @NonNullDimensions newDimensions,
    @NonNullImagenImagePlacement newPosition,
    double dilation
)

Generates two reference images ofImagenRawImage andImagenRawMask.

Public methods

generateMaskAndPadForOutpainting

public static final @NonNullList<@NonNullImagenReferenceImagegenerateMaskAndPadForOutpainting(
    @NonNullImagenInlineImage image,
    @NonNullDimensions newDimensions,
    @NonNullImagenImagePlacement newPosition
)

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
@NonNullImagenInlineImage image

the original image

@NonNullDimensions newDimensions

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

@NonNullImagenImagePlacement newPosition

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

generateMaskAndPadForOutpainting

public static final @NonNullList<@NonNullImagenReferenceImagegenerateMaskAndPadForOutpainting(
    @NonNullImagenInlineImage image,
    @NonNullDimensions newDimensions,
    @NonNullImagenImagePlacement newPosition,
    double dilation
)

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
@NonNullImagenInlineImage image

the original image

@NonNullDimensions newDimensions

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

@NonNullImagenImagePlacement newPosition

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

double dilation

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.