Image-variation-and-edition
Image variation and edition
This Markdown file can be "evaluated" with the Raku package "Text::CodeProcessing", [AAp2]. Here is a shell command:
file-code-chunks-eval Image-variation-and-edition.md Remark: For doing image generations using text prompts see the document Image-generation.md (and its woven version, Image-generation_woven.md.)
Image variation
Here we load the Raku package "WWW::OpenAI", [AAp1]:
use WWW::OpenAI;Variations of images can be generated with the function openai-variate-image -- see the section
"Images" of [OAI2].
Here is a (random mandala) image:
Remark: Below we refer to the image above as "the original image."
Here we generate a few variations of the image above, and get "whole images" in Base64 format:
my @imgResB64 = |openai-variate-image(
$*CWD ~ '/../resources/RandomMandala.png',
n => 2,
size => 'small',
response-format => 'b64_json',
format => 'values',
method => 'tiny');
@imgResB64.map({ '' }).join("\n\n") Remark: The obtained images are put into the woven document via the output of the code cell,
which has the setting results=asis.
The first argument is a prompt used to generate the image(s).
Here are the descriptions of the named arguments (options):
ntakes a positive integer, for the number of images to be generatedsizetakes the values '1024x1024', '512x512', '256x256', 'large', 'medium', 'small'.response-formattakes the values "url" and "b64_json"methodtakes the values "tiny" and "curl"
Here we generate a few variations of the original mandala image above, get their URLs, and place (embed) the image links using a table:
my @imgRes = |openai-variate-image(
$*CWD ~ '/../resources/RandomMandala.png',
response-format => 'url',
n => 2,
size => 'small',
format => 'values',
method => 'tiny');
@imgRes.map({ '' }).join("\n\n") Image edition
Editions of images can be generated with the function openai-edit-image -- see the section
"Images" of [OAI2].
Here are the descriptions of positional arguments:
fileis a file name string (a PNG image with RGBA color space)promptis a prompt tha describes the image edition
Here are the descriptions of the named arguments (options):
mask-filea file name of a mask image (can be an empty string orWhatever)ntakes a positive integer, for the number of images to be generatedsizetakes the values '1024x1024', '512x512', '256x256', 'large', 'medium', 'small'.response-formattakes the values "url" and "b64_json"methodtakes the values "tiny" and "curl"
Here is a random mandala color (RGBA) image:
Here we generate a few editions of the colored mandala image above, get their URLs, and place (embed) the image links using a table:
my @imgRes = |openai-edit-image(
$*CWD ~ '/../resources/RandomMandala2.png',
'add cosmic background',
response-format => 'url',
n => 2,
size => 'small',
format => 'values',
method => 'tiny');
@imgRes.map({ '' }).join("\n\n") References
Articles
[AA1] Anton Antonov, "Connecting Mathematica and Raku", (2021), RakuForPrediction at WordPress.
Packages
[AAp1] Anton Antonov, WWW::OpenAI Raku package, (2023), GitHub/antononcube.
[AAp2] Anton Antonov, Text::CodeProcessing, (2021), GitHub/antononcube.
[OAI1] OpenAI Platform, OpenAI platform.
[OAI2] OpenAI Platform, OpenAI documentation.
[OAIp1] OpenAI, OpenAI Python Library, (2020), GitHub/openai.