Skip to content

Commit

Permalink
Improving example text: image generation
Browse files Browse the repository at this point in the history
  • Loading branch information
debymf committed Apr 13, 2024
1 parent 3f117db commit e092537
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
Binary file removed examples/ExampleDALLE.mlx
Binary file not shown.
50 changes: 50 additions & 0 deletions examples/UsingDALLEToEditImages.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
%% Using DALL·E to Edit Images
% This example shows how to generate and edit images using the |openAIImages|
% object.
%
% To run this example, you need a valid OpenAI API key. Creating images using
% DALL-E may incur a fee.

loadenv(".env")
addpath('..')
%% Generate image variations
% Use the image variation feature in DALL·E 2.

mdl = openAIImages(ModelName="dall-e-2");
%%
% Show the image to get variations for.

imagePath = fullfile('examples','images','bear.png');
figure
imshow(imagePath)
%%
% Benerate variations for that image.

[images,resp] = createVariation(mdl, imagePath, NumImages=4);
if ~isempty(images)
tiledlayout('flow')
for ii = 1:numel(images)
nexttile
imshow(images{ii})
end
else
disp(resp.Body.Data.error)
end
%% Edit an Image with DALL·E
% Use an image containing a mask to apply modifications to the masked area.

imagePath = fullfile('examples','images','mask_bear.png');
figure
imshow(imagePath)
%%
% Add a swan to the masked area using the function |edit|.

[images,resp] = edit(mdl, imagePath, "Swan", MaskImagePath=maskImagePath);
if isfield(resp.Body.Data,'data')
figure
imshow(images{1});
else
disp(resp.Body.Data.error)
end
%%
% _Copyright 2024 The MathWorks, Inc._
Binary file added examples/UsingDALLEToEditImages.mlx
Binary file not shown.
27 changes: 27 additions & 0 deletions examples/UsingDALLEToGenerateImages.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
%% Using DALL·E to generate images
% This example shows how to generate images using the |openAIImages| object.
%
% To run this example, you need a valid OpenAI API key. Creating images using
% DALL-E may incur a fee.

loadenv(".env")
addpath('..')
%% Image Generation with DALL·E 3
% Create an |openAIImages| object with |ModelName| |dall-e-3|.

mdl = openAIImages(ModelName="dall-e-3");
%%
% Generate and visualize an image. This model only supports the generation of
% one image per request.

images = generate(mdl,"A Lynx Point Siamese cat playing with some yarn");
figure
imshow(images{1})
%%
% You can also define the style and quality of the image

images = generate(mdl,"A Lynx Point Siamese cat playing with some yarn", Quality="hd", Style="natural");
figure
imshow(images{1})
%%
% _Copyright 2024 The MathWorks, Inc._
Binary file added examples/UsingDALLEToGenerateImages.mlx
Binary file not shown.

0 comments on commit e092537

Please sign in to comment.