Skip to content

Commit e092537

Browse files
committed
Improving example text: image generation
1 parent 3f117db commit e092537

5 files changed

+77
-0
lines changed

examples/ExampleDALLE.mlx

-4.59 MB
Binary file not shown.

examples/UsingDALLEToEditImages.m

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
%% Using DALL·E to Edit Images
2+
% This example shows how to generate and edit images using the |openAIImages|
3+
% object.
4+
%
5+
% To run this example, you need a valid OpenAI API key. Creating images using
6+
% DALL-E may incur a fee.
7+
8+
loadenv(".env")
9+
addpath('..')
10+
%% Generate image variations
11+
% Use the image variation feature in DALL·E 2.
12+
13+
mdl = openAIImages(ModelName="dall-e-2");
14+
%%
15+
% Show the image to get variations for.
16+
17+
imagePath = fullfile('examples','images','bear.png');
18+
figure
19+
imshow(imagePath)
20+
%%
21+
% Benerate variations for that image.
22+
23+
[images,resp] = createVariation(mdl, imagePath, NumImages=4);
24+
if ~isempty(images)
25+
tiledlayout('flow')
26+
for ii = 1:numel(images)
27+
nexttile
28+
imshow(images{ii})
29+
end
30+
else
31+
disp(resp.Body.Data.error)
32+
end
33+
%% Edit an Image with DALL·E
34+
% Use an image containing a mask to apply modifications to the masked area.
35+
36+
imagePath = fullfile('examples','images','mask_bear.png');
37+
figure
38+
imshow(imagePath)
39+
%%
40+
% Add a swan to the masked area using the function |edit|.
41+
42+
[images,resp] = edit(mdl, imagePath, "Swan", MaskImagePath=maskImagePath);
43+
if isfield(resp.Body.Data,'data')
44+
figure
45+
imshow(images{1});
46+
else
47+
disp(resp.Body.Data.error)
48+
end
49+
%%
50+
% _Copyright 2024 The MathWorks, Inc._

examples/UsingDALLEToEditImages.mlx

6.31 MB
Binary file not shown.

examples/UsingDALLEToGenerateImages.m

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
%% Using DALL·E to generate images
2+
% This example shows how to generate images using the |openAIImages| object.
3+
%
4+
% To run this example, you need a valid OpenAI API key. Creating images using
5+
% DALL-E may incur a fee.
6+
7+
loadenv(".env")
8+
addpath('..')
9+
%% Image Generation with DALL·E 3
10+
% Create an |openAIImages| object with |ModelName| |dall-e-3|.
11+
12+
mdl = openAIImages(ModelName="dall-e-3");
13+
%%
14+
% Generate and visualize an image. This model only supports the generation of
15+
% one image per request.
16+
17+
images = generate(mdl,"A Lynx Point Siamese cat playing with some yarn");
18+
figure
19+
imshow(images{1})
20+
%%
21+
% You can also define the style and quality of the image
22+
23+
images = generate(mdl,"A Lynx Point Siamese cat playing with some yarn", Quality="hd", Style="natural");
24+
figure
25+
imshow(images{1})
26+
%%
27+
% _Copyright 2024 The MathWorks, Inc._
2.74 MB
Binary file not shown.

0 commit comments

Comments
 (0)