Last updated: Oct-31-2023
Cloudinary is a cloud-based service that provides solutions for image and video management, including server or client-side upload, on-the-fly image and video transformations, quick CDN delivery, and a variety of asset management options.
The Neural Artwork Style Transfer add-on takes Cloudinary image transformations to a new level with the
style_transfer effect. This effect applies a complex deep learning neural network algorithm that extracts artistic styles from a source image and applies them to the content of a target photograph.
Before you can use the Neural Art Style Transfer add-on:
You must have a Cloudinary account. If you don't already have one, you can sign up for a free account.
Keep in mind that many of the examples on this page use our SDKs. For SDK installation and configuration details, see the relevant SDK guide.
If you are new to Cloudinary, you may want to take a look at How to integrate Cloudinary in your app for a walk through on the basics of creating and setting up your account, working with SDKs, and then uploading, transforming and delivering assets.
Gatys et al is credited with using the VGG neural network to demonstrate how different abstractions of the source and target images can be filtered at different layers, so that the essential elements of the input image can be applied without losing the essence of the target content. Cloudinary's algorithm takes advantage of Xun Huange and Serge Belongie's enhancement on the Gatys algorithm, which make it possible to use any image for both source and target, and still deliver a good quality style transfer in real time, using a single feed-forward neural network.
To apply this style transfer effect on any photograph, specify the public ID of the source artwork as an image overlay (
l_ in URLs) and
style_transfer as the overlay
e_style_transfer in URLs) to apply (include this effect in the
layer_apply component of your URL). The target photograph is the public ID of the image to deliver.
In the example below, the styles of the Sailing Angel artwork are transferred to the Golden Gate Bridge photo:
The algorithm is able to recognize styles in the source painting, such as brush stroke style, textures, and dominant colors. It can then apply those styles to the content elements of the target photograph. In the resulting image, there is some content loss, and some style loss, but the neural network algorithm optimizes these losses so that the main elements of the artwork's style come through while ensuring that the content of the target photo is clearly recognizable.
- If you want to retain the target photograph's colors, you can include the
- If you want to control how much of the style from the source painting is transferred, you can adjust the
style_strength(1-100, default: 100).
For example, if you transfer the styles of the lighthouse source artwork to the beach_2_kids target photo, you clearly get a result that is heavily influenced by the lighthouse image's colors and brushstroke styles:
Now take a look at the next three images to see how the result changes with the use of the adjustment settings:
Here's the transformation code for that last image, using both the
The Neural Artwork add-on supports generating images with the
style_transfer effect for any resolution up to 3000x3000, and it's capable of rendering the new image very quickly even at large sizes. However, because of the way the algorithm analyzes the content of the target photo, you will get different results for different sizes of the target photo. Also, keep in mind that the neural network algorithm behind our Neural Artwork add-on was initially designed for optimum output of images at resolutions in the range of 600x600 - 800x800.
Therefore, when this optimum resolution range is appropriate for your intended usage, use resize or cropping transformations to bring the target photo into this range in one transformation component, and then apply the
style_transfer effect in a later transformation component.
Likewise, if you want to output images that are significantly smaller than the above recommended resolution range, you may want to apply the
style_transfer effect in an earlier transformation component, and then apply the resizing to the small size in a later transformation component.
Cloudinary's dynamic image transformation URLs are powerful tools for agile web and mobile development. However, due to the potential costs of your customers accessing unplanned dynamic URLs that apply the neural art algorithm, image transformation add-on URLs are required (by default) to be signed using Cloudinary's authenticated API or, alternatively, you can eagerly generate the requested derived images using Cloudinary's authenticated API.
To create a signed Cloudinary URL, set the
sign_url parameter to true when building a URL or creating an image tag.
The following code example generates a neural artwork by overlaying the
davinci_mona_lisa artwork with the
coffee_cup_st photo, including a signed Cloudinary URL:
The generated Cloudinary URL shown below includes a signature component (
/s--D2UmnV-Z--/). Only URLs with a valid signature that matches the requested image transformation will be approved for on-the-fly image transformation and delivery.
For more details on signed URLs, see Signed delivery URLs.
2 Pick a target photo below OR Upload your own
|3 Press the magic button:|
You can create even more unique results by combining the Neural Artwork
style_transfer effect with other transformations. For details, see Image transformations and the Transformation URL API Reference.