AI Image Upscaling in Mobile Apps: On-Device and Cloud Solutions
You take a photo with your phone camera — 12 MP, but after cropping you're left with 600×600 pixels. Need 4× upscaling? Bicubic interpolation blurs everything. Neural networks restore textures of skin, fur, fabric. We implement AI upscaling three ways: on-device via Core ML / ONNX, cloud API, or hybrid. With over 5 years of experience and more than 30 AI projects, we guarantee quality results. On-device processing can save up to 80% on server infrastructure costs compared to cloud solutions. Contact us for a consultation on choosing the right approach.
Example code for on-device upscaler in Swift
import CoreML
import Vision
class ImageUpscaler {
private let model: VNCoreMLModel
init() throws {
let config = MLModelConfiguration()
config.computeUnits = .cpuAndNeuralEngine // Uses Neural Engine
let coreMLModel = try RealESRGAN(configuration: config)
model = try VNCoreMLModel(for: coreMLModel.model)
}
func upscale(_ image: UIImage) async throws -> UIImage {
guard let cgImage = image.cgImage else { throw UpscaleError.invalidInput }
return try await withCheckedThrowingContinuation { continuation in
let request = VNCoreMLRequest(model: model) { request, error in
if let error = error {
continuation.resume(throwing: error)
return
}
guard let results = request.results as? [VNPixelBufferObservation],
let outputBuffer = results.first?.pixelBuffer else {
continuation.resume(throwing: UpscaleError.noOutput)
return
}
let ciImage = CIImage(cvPixelBuffer: outputBuffer)
let context = CIContext()
guard let outputCG = context.createCGImage(ciImage, from: ciImage.extent) else {
continuation.resume(throwing: UpscaleError.conversionFailed)
return
}
continuation.resume(returning: UIImage(cgImage: outputCG))
}
request.imageCropAndScaleOption = .scaleFit
let handler = VNImageRequestHandler(cgImage: cgImage)
try? handler.perform([request])
}
}
}
Real-ESRGAN is the highest quality model for ×4 upscaling. Core ML-converted versions exist. Limitation: Real-ESRGAN expects a fixed input tile size (usually 256×256 or 512×512). For larger images, we slice into tiles with overlap (16–32 pixels) to avoid seams. (Real-ESRGAN: Xintao Wang et al., GitHub repository)
func upscaleTiled(_ image: UIImage, tileSize: Int = 256, overlap: Int = 16) async throws -> UIImage {
let tiles = splitIntoTiles(image: image, tileSize: tileSize, overlap: overlap)
let upscaledTiles = try await withThrowingTaskGroup(of: (Int, Int, UIImage).self) { group in
for (row, col, tile) in tiles {
group.addTask {
let upscaled = try await self.upscale(tile)
return (row, col, upscaled)
}
}
var results: [(Int, Int, UIImage)] = []
for try await result in group { results.append(result) }
return results
}
return mergeTiles(upscaledTiles, originalSize: image.size, scaleFactor: 4, overlap: overlap)
}
On iPhone 15 Pro with Neural Engine: 512×512 → 2048×2048 takes ~800 ms. 1024×1024 split into tiles takes 2–4 seconds.
On-Device: ONNX Runtime on Android
Real-ESRGAN in ONNX format (~15 MB for the small model):
class OnnxUpscaler(context: Context) {
private val session: OrtSession
init {
val env = OrtEnvironment.getEnvironment()
val options = OrtSession.SessionOptions().apply {
addNnapi() // Uses NNAPI for acceleration
}
val modelBytes = context.assets.open("realesrgan_x4.onnx").readBytes()
session = env.createSession(modelBytes, options)
}
fun upscale(bitmap: Bitmap): Bitmap {
// Convert Bitmap to float tensor [1, 3, H, W], normalize to [0, 1]
val inputTensor = bitmapToTensor(bitmap)
val inputName = session.inputNames.first()!!
val output = session.run(mapOf(inputName to inputTensor))
val outputTensor = output[0].value as Array<*>
// Convert tensor back to Bitmap
return tensorToBitmap(outputTensor, bitmap.width * 4, bitmap.height * 4)
}
}
NNAPI on modern Android devices delivers 2–4× speedup over CPU. On Snapdragon 8 Gen 2 — 512×512 in ~1.2 seconds.
Cloud APIs
When on-device is too slow or you need a higher scaling factor (×8, ×16):
Replicate — Real-ESRGAN:
let body: [String: Any] = [
"version": "...", // real-esrgan model hash
"input": [
"image": "data:image/jpeg;base64,\(base64Image)",
"scale": 4,
"face_enhance": true // GFPGAN for face enhancement
]
]
face_enhance: true runs GFPGAN on top of Real-ESRGAN — important for portraits to avoid artifacts.
Stability AI Upscale API:
val requestBody = MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("image", "photo.jpg", imageFile.asRequestBody("image/jpeg".toMediaType()))
.addFormDataPart("output_format", "png")
.build()
Stability AI returns PNG with ×4 upscaling via Creative Upscaler (SD-based, adds details) or Conservative Upscaler (fewer changes to original).
How to Integrate AI Upscaling: Step-by-Step
- Model selection — Real-ESRGAN for on-device, cloud API for maximum quality.
- Conversion to required format — Core ML for iOS, ONNX for Android.
- Implement tiling — split into tiles with overlap, parallel processing.
- UI integration — progress indicator, before/after slider.
- Testing — on different devices, with various source images.
Approach Selection
| Scenario | Recommendation |
|---|---|
| Fast upscaling of camera photos | On-device (VisionKit/ONNX), tiling |
| Portraits with face restoration | Replicate Real-ESRGAN + face_enhance |
| Document/text scans | Stability AI Conservative Upscaler |
| Old photos (×8 and above) | Cloud — Real-ESRGAN or Topaz Gigapixel API |
| Offline requirement | On-device mandatory |
Choosing Between On-Device and Cloud Upscaling
On-device is fast and free but limited by device performance and model size. Cloud APIs offer higher quality and scaling factors but add latency and cost. If your app targets offline scenarios or saves bandwidth, choose on-device. For maximum quality in portraits or old photos, cloud is justified. We implement a hybrid approach that automatically selects the best path.
Comparison: On-Device vs Cloud Upscaling
| Parameter | On-Device (Core ML/ONNX) | Cloud API |
|---|---|---|
| Speed | <2 sec (512×512) | 3-10 sec + network |
| Quality | Good (Real-ESRGAN) | Excellent (GFPGAN + Real-ESRGAN) |
| Offline | Yes | No |
| Scaling factor | ×4 | ×4–×16 |
| Cost | Free | Varies by provider |
Why Real-ESRGAN Beats Standard Algorithms
Real-ESRGAN delivers 2–3× better quality than bicubic upscaling: it restores textures, noise reduction, sharpness. Combined with GFPGAN for faces, artifacts are virtually eliminated. This is proven in extensive testing and confirmed by the original paper. We use this model in most projects, including products with thousands of users.
UX: Progress and Comparison
On-device upscaling should show tiling progress: "Processing 3 of 12 tiles." The user doesn't experience freezes.
After completion, an interactive before/after slider (MagnificationGesture on iOS, custom touch view on Android) is standard UI for any photo enhancement tool.
What's Included
- Requirements analysis and optimal approach selection (on-device / cloud / hybrid)
- Development of native upscaling module (Swift / Kotlin)
- Integration of chosen model (Core ML, ONNX, cloud API)
- Tiling with overlap and progress indication
- Before/after slider
- Testing on real devices with different specifications
- Documentation and source code delivery
- One month of post-launch support
Estimated Timeline
On-device upscaling with tiling and progress indicator — 5–8 days. Cloud upscaling + face enhancement + before/after slider + gallery save — 8–12 days. Hybrid with quality evaluation and path selection — additional 3–5 days.
Contact us for a project assessment: get a consultation on approach selection and approximate cost.







