ImagenModel

@PublicPreviewAPI
public final class ImagenModel


Represents a generative model (like Imagen), capable of generating images based on various input types.

Summary

Public methods

final @NonNull ImagenGenerationResponse<@NonNull ImagenInlineImage>
editImage(
    @NonNull List<@NonNull ImagenReferenceImage> referenceImages,
    @NonNull String prompt,
    ImagenEditingConfig config
)

Generates an image from a single or set of base images, returning the result directly to the caller.

final @NonNull ImagenGenerationResponse<@NonNull ImagenInlineImage>

Generates an image, returning the result directly to the caller.

final @NonNull ImagenGenerationResponse<@NonNull ImagenInlineImage>
inpaintImage(
    @NonNull ImagenInlineImage image,
    @NonNull String prompt,
    @NonNull ImagenMaskReference mask,
    @NonNull ImagenEditingConfig config
)

Generates an image by inpainting a masked off part of a base image.

final @NonNull ImagenGenerationResponse<@NonNull ImagenInlineImage>
outpaintImage(
    @NonNull ImagenInlineImage image,
    @NonNull Dimensions newDimensions,
    @NonNull ImagenImagePlacement newPosition,
    @NonNull String prompt,
    ImagenEditingConfig config
)

Generates an image by outpainting the given image, extending its content beyond the original borders using context from the original image, and optionally, the prompt.

Public methods

editImage

public final @NonNull ImagenGenerationResponse<@NonNull ImagenInlineImageeditImage(
    @NonNull List<@NonNull ImagenReferenceImage> referenceImages,
    @NonNull String prompt,
    ImagenEditingConfig config
)

Generates an image from a single or set of base images, returning the result directly to the caller.

Parameters
@NonNull List<@NonNull ImagenReferenceImage> referenceImages

the image inputs given to the model as a prompt

@NonNull String prompt

the text input given to the model as a prompt

ImagenEditingConfig config

the editing configuration settings

generateImages

public final @NonNull ImagenGenerationResponse<@NonNull ImagenInlineImagegenerateImages(@NonNull String prompt)

Generates an image, returning the result directly to the caller.

Parameters
@NonNull String prompt

The input(s) given to the model as a prompt.

inpaintImage

public final @NonNull ImagenGenerationResponse<@NonNull ImagenInlineImageinpaintImage(
    @NonNull ImagenInlineImage image,
    @NonNull String prompt,
    @NonNull ImagenMaskReference mask,
    @NonNull ImagenEditingConfig config
)

Generates an image by inpainting a masked off part of a base image. Inpainting is the process of filling in missing or masked off parts of the image using context from the original image and prompt.

Parameters
@NonNull ImagenInlineImage image

the base image

@NonNull String prompt

the text input given to the model as a prompt

@NonNull ImagenMaskReference mask

the mask which defines where in the image can be painted by Imagen.

@NonNull ImagenEditingConfig config

the editing configuration settings, it should include an ImagenEditMode

outpaintImage

public final @NonNull ImagenGenerationResponse<@NonNull ImagenInlineImageoutpaintImage(
    @NonNull ImagenInlineImage image,
    @NonNull Dimensions newDimensions,
    @NonNull ImagenImagePlacement newPosition,
    @NonNull String prompt,
    ImagenEditingConfig config
)

Generates an image by outpainting the given image, extending its content beyond the original borders using context from the original image, and optionally, the prompt.

Parameters
@NonNull ImagenInlineImage image

the base image

@NonNull Dimensions newDimensions

the new dimensions for the image, must be larger than the original image.

@NonNull ImagenImagePlacement newPosition

the placement of the base image within the new image. This can either be coordinates (0,0 is the top left corner) or an alignment (ex: ImagenImagePlacement.BOTTOM_CENTER)

@NonNull String prompt

optional, can be used to specify the background generated if context is insufficient

ImagenEditingConfig config

the editing configuration settings