Generate image using OpenAI® image generation API
[images,httpResponse] = generate(model,prompt)
___ = generate(___,Name=Value)
[images,httpResponse] = generate(model,prompt)
generates images from an OpenAI image generation model given a natural language prompt.
___ = generate(___,Name=Value)
specifies additional options using one or more name-value arguments.
First, specify the OpenAI API key as an environment variable and save it to a file called ".env"
. Next, load the environment file using the loadenv
function.
loadenv(".env")
Connect to the OpenAI Images API. By default, the model is DALL·E 2.
model = openAIImages
model =
openAIImages with properties:
ModelName: "dall-e-2"
TimeOut: 10
Generate and display an image based on a natural language prompt.
catImage = generate(model,"An image of a cat confused by a complicated knitting pattern.");
imshow(catImage{1})
openAIImages
object
Image generation model, specified as an openAIImages
object.
character vector | string scalar
Natural language prompt instructing the model what to do.
Example: "Please draw a frog wearing spectacles."
1
(default) | positive integer
Specify the number of images to generate.
Generating more than one image at once is only supported for DALL·E 2.
"1024x1024"
(default) | "256x256"
| "512x512"
| "1792x1024"
| "1024x1792"
Size of the generated image in pixels.
Sizes supported for DALL·E 2:
"1024x1024"
"256x256"
"512x512"
Sizes supported for DALL·E 3:
"1024x1024"
"1024x1792"
"1792x1024"
"standard"
(default) | "hd"
Specify the OpenAI "quality"
parameter. This option is only supported for DALL·E 3.
If you specify the quality to be "hd"
, then the cost per generated image increases.
For more information on the differences between standard and HD quality, see https://cookbook.openai.com/articles/what_is_new_with_dalle_3.
"vivid"
(default) | "natural"
Specify the OpenAI "style"
parameter. This option is only supported for DALL·E 3.
For more information on the differences between vivid and natural style, see https://cookbook.openai.com/articles/what_is_new_with_dalle_3.
cell array of numerical matrices
Images that the model generates, returned as a cell array with NumImages
elements. Each element of the cell array contains a generated image specified as an RGB images of size Size
. For example, if you specify Size="1024x1024"
, then the generated images have size 1024x1024x3
.
matlab.net.http.ResponseMessage
object
Response message returned by the server, specified as a matlab.net.http.ResponseMessage
object.
openAIImages
| edit
| createVariation
Copyright 2024 The MathWorks, Inc.