Skip to content

Image to Image

Transform existing images using text prompts while preserving elements of the original.

Basic Usage

typescript
import { NovelAI } from 'novelai-sdk-unofficial';
import { readFileSync, writeFileSync } from 'fs';

const client = new NovelAI({ apiKey: 'your-api-key' });

const inputImage = readFileSync('input.png');

const images = await client.image.generate({
  prompt: 'cyberpunk style, neon lights',
  model: 'nai-diffusion-4-5-full',
  i2i: {
    image: inputImage,
    strength: 0.5,
  },
});

writeFileSync('output.png', images[0]);

Parameters

ParameterTypeDefaultDescription
imageImageInputrequiredInput image
strengthnumber0.7Transformation strength (0.01-0.99)
noisenumber0Additional noise (0-0.99)
maskImageInputoptionalInpainting mask

Strength Parameter

The strength parameter controls how much the output differs from the input:

  • Low (0.1-0.3): Minor changes, preserves most of the original
  • Medium (0.4-0.6): Balanced transformation
  • High (0.7-0.9): Major changes, less of the original preserved
typescript
// Subtle enhancement
i2i: { image: input, strength: 0.2 }

// Moderate transformation
i2i: { image: input, strength: 0.5 }

// Major transformation
i2i: { image: input, strength: 0.8 }

Noise Parameter

Adding noise can help with creativity but may reduce coherence:

typescript
i2i: {
  image: input,
  strength: 0.5,
  noise: 0.1, // Slight noise for variation
}

Inpainting

Use a mask to selectively transform parts of the image:

typescript
const inputImage = readFileSync('input.png');
const maskImage = readFileSync('mask.png'); // White = transform, Black = preserve

const images = await client.image.generate({
  prompt: 'blue hair',
  i2i: {
    image: inputImage,
    strength: 0.7,
    mask: maskImage,
  },
});

Mask Format

  • White areas: Will be transformed
  • Black areas: Will be preserved
  • Gray areas: Partial transformation

Examples

Style Transfer

typescript
const images = await client.image.generate({
  prompt: 'oil painting style, impressionist',
  i2i: {
    image: photoImage,
    strength: 0.6,
  },
});

Color Correction

typescript
const images = await client.image.generate({
  prompt: 'vibrant colors, high contrast',
  i2i: {
    image: inputImage,
    strength: 0.3,
  },
});

Background Change

typescript
// With mask covering the background
const images = await client.image.generate({
  prompt: 'beach sunset background',
  i2i: {
    image: inputImage,
    strength: 0.8,
    mask: backgroundMask,
  },
});

Character Outfit Change

typescript
// With mask covering the outfit
const images = await client.image.generate({
  prompt: 'wearing a red dress',
  i2i: {
    image: inputImage,
    strength: 0.7,
    mask: outfitMask,
  },
});

Tips

  1. Match the size - The output will match the input image dimensions.

  2. Start with lower strength - Begin around 0.3-0.5 and increase if needed.

  3. Be specific in prompts - Describe what you want to change clearly.

  4. Use masks for precision - Inpainting gives you fine control over what changes.

  5. Consider the original - The prompt should work with, not against, the input image.

Combining with Other Features

With ControlNet

typescript
const images = await client.image.generate({
  prompt: 'enhanced, detailed',
  i2i: {
    image: inputImage,
    strength: 0.4,
  },
  controlnet: {
    images: [
      {
        image: styleReference,
        strength: 0.5,
      },
    ],
  },
});

Released under the MIT License.