LocalMode
Transformers

Image-to-Image

Super resolution and image enhancement with Swin2SR.

Enhance images using super resolution models. Upscale low-resolution images to higher quality directly in the browser.

For full API reference (imageToImage(), options, result types, and custom providers), see the Core Vision guide.

See it in action

Try Photo Enhancer for a working demo.

ModelSizeScaleUse Case
Xenova/swin2SR-lightweight-x2-64~50MB2xLightweight 2x upscaling (recommended)
Xenova/swin2SR-classical-sr-x4-64~50MB4xHigher quality 4x upscaling

Photo Enhancer Example

Based on the Photo Enhancer showcase app:

import { transformers } from '@localmode/transformers';
import { imageToImage } from '@localmode/core';

const model = transformers.imageToImage('Xenova/swin2SR-lightweight-x2-64');

async function enhancePhoto(imageDataUrl: string) {
  const { image } = await imageToImage({
    model,
    image: imageDataUrl,
    abortSignal: controller.signal,
  });

  // Convert Blob to data URL for display
  const reader = new FileReader();
  return new Promise<string>((resolve) => {
    reader.onload = () => resolve(reader.result as string);
    reader.readAsDataURL(image);
  });
}

Best Practices

Super Resolution Tips

  1. 2x upscaling — The lightweight model doubles image dimensions
  2. Input size matters — Very large images will be slow; resize input if needed
  3. Output is a Blob — Use URL.createObjectURL() or FileReader to display
  4. Support cancellation — Super resolution can take several seconds

Performance Note

Super resolution is computationally intensive. Processing time increases with input image size. For best results, keep input images under 1024x1024 pixels.

Showcase Apps

AppDescriptionLinks
Photo EnhancerUpscale and enhance photosDemo · Source

Next Steps

On this page