-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improving example text: image generation
- Loading branch information
Showing
5 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.