Skip to main content

Image Editing: Style Transfer

Feature Description

Image filters have long been a common feature in many applications. With large models, you can quickly implement image filtering functionality without complex image processing, enabling a variety of filter effects.

Large models can achieve filtering through multiple methods such as image-to-image generation, using LORA, and fine-tuning models.

In this article, we use the style transfer API to quickly implement image filtering. Compared to other methods, the style transfer API is simple to use, produces significant effects, and can quickly achieve various filter effects.

Models Supporting Style Transfer

Experience the API Effect

Function Description

The Serverless API provides an interface for quick experience, allows you to quickly test the API effects. Open the Serverless API page, find the Kolors model under Image Generation and Processing, click to enter the interface details page, and switch to the style transfer API.

image-20250113153212170

In the style transfer interface, the original image refers to the image you want to transform and modify. The prompt and style image are the text and style reference used to guide the modification of the original image.

Ghibli-like Style Transfer

Next, we'll use this interface to complete a Ghibli-style transfer.

Use the following image as the reference style:

20250113164303_吉卜力风格__小清新

Use an ordinary landscape photo as the original image.

P1012997

Fill in these images on the page. To make the output image more consistent with the original, we set the strength parameter to 0.4.

image-20250113173048253

The output result is as follows:

image-20250113173107828

Fluffy Style Transfer

The reference image is as follows:

image-20250114143124824

Following the same steps as above, we can quickly replicate the fluffy image style through the style transfer interface.

The input is as follows:

image-20250114144653414

The output result is as follows:

image-20250114144718497

Calling the Style Transfer API

After experiencing and verifying the functionality, we can now integrate the above features into our own applications through code calls.

python
import os
import requests
import base64
from PIL import Image
from io import BytesIO
from requests_toolbelt import MultipartEncoder

API_URL = "https://ai.gitee.com/v1/images/style-migration"
headers = {
"Authorization": "Bearer <your token>",
}

def open_image(img_path):
file_name = os.path.basename(img_path)
return (file_name, open(img_path, "rb"), "application/octet-stream")

def query(payload):
data = {}
for key, value in payload.items():
if key == "image":
continue
if key == "style_image":
continue
if value is None:
data[key] = ""
elif isinstance(value, list):
data[key] = ",".join(map(str, value))
elif isinstance(value, bool):
data[key] = str(value).lower()
else:
data[key] = str(value)

data["image"] = open_image(payload["image"])
data["style_image"] = open_image(payload["style_image"])
multipart_data = MultipartEncoder(fields=data)
headers["Content-Type"] = multipart_data.content_type
response = requests.post(API_URL, headers=headers, data=multipart_data)
return response.json()

output = query({
"model": "Kolors",
"size": "1024x1024",
"steps": 25,
"guidance_scale": 6,
"strength": 0.6,
"scale": 0.5,
"prompt": "Convert the girl's photo to the JoJo style of the reference image",
"style_image": "jojo.jpeg",
"image": "woman1.png",
})
data = output["data"][0]["b64_json"]

img = Image.open(BytesIO(base64.b64decode(data)))
img.save("img_style.png")
img.show()

Usage Scenarios

🎨 Art Creation

  • Painting Style Conversion: Transform photos into oil paintings, watercolors, sketches, traditional Chinese paintings, and other artistic styles
  • Anime Stylization: Convert real photos into anime, cartoon, or illustration styles
  • Famous Painting Style Imitation: Mimic the painting styles of masters like Van Gogh, Picasso, and Monet
  • Cultural Style Fusion: Blend artistic characteristics from different cultural backgrounds, such as Chinese, Japanese, and European styles

📸 Photography Post-Processing

  • Filter Effects: Quickly implement photography filters like retro, film, black and white, and warm tones
  • Atmosphere Creation: Adjust the overall atmosphere of images, such as dreamy, mysterious, and warm
  • Seasonal Styles: Convert images to visual effects of different seasons (spring, summer, autumn, winter)
  • Era Styles: Create a sense of era such as 80s retro, cyberpunk, and steampunk

🎮 Game Development

  • Concept Art: Create concept art of different styles for game scenes and characters
  • Art Style Unification: Ensure all materials in the game maintain a consistent artistic style
  • Original Painting Production: Convert 3D renderings into hand-painted style original paintings
  • UI Stylization: Apply specific artistic styles to game interface elements

🎬 Film and Television Production

  • Storyboard Design: Create storyboard sketches of different styles for film and television works
  • Post-Processing Color Grading: Achieve specific visual styles and color effects
  • Animation Style: Convert live-action materials into animation styles
  • Special Effects Preview: Quickly preview the presentation of different visual effects

🏢 Commercial Applications

  • Brand Image: Create visual styles with brand characteristics for enterprises
  • Product Display: Display products in different artistic styles to enhance visual appeal
  • Advertising Creativity: Quickly generate advertising visual schemes of various styles
  • Packaging Design: Apply specific artistic styles to product packaging

📱 Social Media

  • Personal Avatars: Create personalized style avatars for social media
  • Content Creation: Add unique visual styles to social platform content
  • Emoticon Production: Create emoticons and stickers with specific styles
  • Short Video Materials: Produce visual materials with a unified style for short videos

🏠 Interior Design

  • Decoration Preview: Convert indoor space images into different decoration styles
  • Style Exploration: Quickly preview decoration styles such as modern, classical, industrial, and Nordic
  • Color Matching: Try different color schemes and material effects
  • Atmosphere Design: Create different spatial atmospheres such as warm, simple, and luxurious

📚 Education and Training

  • Art Teaching: Help students understand the characteristics of different artistic styles
  • Creative Inspiration: Provide students with creative inspiration and reference materials
  • Historical Reenactment: Convert modern scenes into visual styles of historical periods
  • Cultural Display: Showcase artistic expressions under different cultural backgrounds

💼 E-Commerce Retail

  • Product Stylization: Apply styles that match the preferences of target users to product images
  • Scene Creation: Create shopping scenes that match the brand tone
  • Festival Themes: Adjust product display styles according to different festivals
  • User Personalization: Provide personalized visual experiences for different user groups