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.
Register for the add-on: make sure you're logged in to your account and then go to the Add-ons page. For more information about add-on registrations, see Registering for add-ons.
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.
By default, delivery URLs that use this add-on either need to be signed or eagerly generated. You can optionally remove this requirement by selecting this add-on in the Allow unsigned add-on transformations section of the Security account settings in the Cloudinary console (the demo account has this setting applied to make the examples on this page easier to read and try out).
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 effect (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:
To apply this transformation using the Transformation Editor, first select to Add overlay & watermark and specify the source artwork's Image ID. Then select Style transfer as the effect of the overlay image.
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 preserve_color option.
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:
Source artworkTarget photoDefault style transfer
Now take a look at the next three images to see how the result changes with the use of the adjustment settings:
Preserve original colorsAdjust style strength to 60Adjust strength and preserve colors
Here's the transformation code for that last image, using both the preserve_color and style_strength options:
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.
For example: ....c_scale,w_700/l_your_artwork/e_style_transfer,fl_layer_apply/your_target_photo.jpg
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.
For example: ....c_scale,w_700/l_your_artwork/e_style_transfer,fl_layer_apply/c_scale,w_200/your_target_photo.jpg
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.
You can optionally remove the signed URL default requirement for a particular add-on by selecting it in the Allow unsigned add-on transformations section of the Security account settings in the Cloudinary console.