A Style is Worth One Code: Unlocking Code-to-Style Image Generation with Discrete Style Space

Huijie Liu, Shuhao Cui, Haoxiang Cao, Shuai Ma, Kai Wu, Guoliang Kang

TL;DR

CoTyle is the first open-source framework for code-to-style image generation, allowing users to generate images in unique, highly consistent, and novel artistic styles using just a single numerical code. By combining a discrete style codebook with an autoregressive transformer, CoTyle eliminates the need for complex text prompts or reference images, outperforming commercial alternatives like Midjourney in style consistency.

What Problem Does This Paper Address?

When generating stylized images using text-to-image diffusion models, creators typically face a frustrating trilemma between consistency, creativity, and reproducibility:

  • Textual prompts often fail to maintain style consistency across multiple generated images.
  • Reference images or LoRAs provide better consistency but limit creativity (you can only replicate existing styles) and suffer from poor reproducibility/portability due to the large file sizes or pixel-level dependencies involved.
Figure 2. Different to previous methods, CoTyle uses a numerical style code to represent a style, eliminating the need for complex prompts, images, or LoRAs, and allowing easy creation of unique styles just modifying the code. “Creativity”, “Consistency”, and “Reproducibility” refer to a model’s ability to (1) generate novel styles, (2) produce multiple images in the same style consistently, and (3) reproduce styles using simple, user-friendly style definitions.

While commercial platforms like Midjourney have introduced numerical style codes (e.g., --sref [code]) to solve this, their implementations remain closed-source. This paper introduces CoTyle, filling the academic and open-source gap by treating style generation as a discrete token-prediction problem.

Methods

CoTyle achieves code-to-style generation through a three-stage pipeline:

  1. Discrete Style Codebook: Instead of standard image reconstruction codebooks, the authors train a discrete style codebook using a contrastive loss on paired style images. This forces the model to map images with identical styles (but different contents) to the same distribution while pushing different styles apart, effectively filtering out content noise.
  2. Textual-Branch Style Conditioning: The quantized style embeddings are fed into a Diffusion Transformer (DiT). Crucially, instead of injecting style through the visual branch (which often loses semantic structure), the authors treat style embeddings as text tokens and pass them through the textual branch of a Vision-Language Model (VLM) encoder.
  3. Autoregressive Style Generator: To turn a numerical code into a style, they train a Qwen2-0.5B transformer from scratch to predict sequences of these discrete style tokens. During inference, a user-provided numerical code acts as a random seed to sample the initial token, and the transformer autoregressively generates the remaining sequence to construct a complete style controller.
Figure 3. Overview of CoTyle. (a) We first train a style codebook and an image generation model conditioned on style images. (b) Then, we use the corresponding codebook indices of the style images to train an autoregressive style generator. (c) During inference, a style code is used to randomly sample the first index and autoregressively predict the rest.

The High-Frequency Suppression Trick

The authors observed that certain codebook indices appeared with disproportionately high frequency across datasets, acting as meaningless "placeholders" that defaulted the model back to standard photorealism. To combat this, they introduced a suppression coefficient during inference to down-weight these high-frequency logits, significantly boosting style intensity and diversity.

Datasets

The model was trained on a large-scale collection of paired style images (images sharing the same artistic style but depicting different content).

For evaluation, the authors constructed:

  • Code-to-Style Benchmark: 500 randomly sampled numerical codes, generating 4 images per code (2,000 total images) to evaluate style consistency and diversity.
  • Image-Conditioned Benchmark: 500 prompt and reference image pairs to compare against traditional style-transfer methods.

Key Insights and Ideas

  • Style belongs in the text branch: Injecting style via the visual branch (e.g., feature concatenation) tends to capture low-level color tones but misses complex semantic-style elements like geometry and texture. Passing style embeddings through the VLM text encoder yields results that better align with human perception.
  • Discretization acts as a content filter: Quantizing style features into discrete codebook vectors inherently suppresses irrelevant background and content information, leaving a pure representation of the artistic style.
  • Not all tokens are created equal: The discovery of "placeholder" tokens highlights a common quirk in autoregressive vision models. Actively suppressing these dominant, non-descriptive tokens is essential for unlocking strong, vivid stylization.

Key Results

CoTyle was evaluated against Midjourney and several state-of-the-art image-conditioned baselines using the Context-Style Distance (CSD) metric:

  • Superior Style Consistency: On the code-to-style task, CoTyle achieved a consistency score of 0.6007, significantly outperforming Midjourney's 0.4734.
  • Higher Aesthetic Quality: CoTyle scored 0.7173 on QualityCLIP aesthetics, compared to Midjourney's 0.5948.
  • Style Interpolation: Because styles are represented as sequences of discrete tokens, CoTyle allows for smooth style blending. Users can linearly mix subsets of indices from two different style codes to create entirely new hybrid styles.

Limitations and Future Work

While CoTyle beats Midjourney in consistency and aesthetic scores, it exhibits slightly lower overall style diversity (0.7764 vs Midjourney's 0.8088). The authors attribute this to the limited breadth of their training dataset compared to the massive, proprietary datasets used by commercial giants. Expanding the dataset to cover a wider spectrum of artistic variations is noted as a primary direction for future improvement.

Summary updated

BibTeX
@inproceedings{liu2026style,
  author = {Huijie Liu and Shuhao Cui and Haoxiang Cao and Shuai Ma and Kai Wu and Guoliang Kang},
  title = {{A Style is Worth One Code: Unlocking Code-to-Style Image Generation with Discrete Style Space}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2026},
  url = {https://openreview.net/forum?id=rfCuIDGAL8},
}
Figure