Mobile Image Segmentation Implementation
We've repeatedly faced the same challenge: a client wants to implement image segmentation in a mobile app but doesn't know where to start. Segmentation is the most computationally expensive computer vision task on mobile. While detection returns a bounding box, segmentation returns a pixel-wise mask. For a 512×512 image, that's 262,144 pixels, each with a class, and all must be processed and rendered within 33 ms for 30 FPS. Without proper model selection and rendering, real-time is unattainable. We've accumulated experience across 10+ computer vision projects and guarantee stable performance.
Semantic or Instance Segmentation?
Semantic segmentation assigns one class per pixel (sky, person, road). All people in frame share the class 'person'. Models: DeepLabV3+, MobileNetV3 Segmentation. The TFLite version of DeepLabV3+ with 257×257 input runs in 22–35 ms on modern Android devices.
Instance segmentation gives each object instance its own mask. Three people = three masks. Models: Mask R-CNN, YOLOv8-seg. Significantly heavier: YOLOv8n-seg on TFLite takes 80–120 ms on mobile. True real-time with such a model requires flagship devices with GPU delegate.
For most consumer use cases (background removal, blur effect), semantic segmentation of 'person' or 'background' is sufficient. This is covered by ML Kit Selfie Segmentation — on-device, 30 FPS, a dedicated neural net trained for this scenario. Our experience shows ML Kit is 2–3× faster than universal models with comparable quality.
| Model | Type | FPS (iPhone 13) | FPS (Pixel 6) | Use Case |
|---|---|---|---|---|
| DeepLabV3+ (TFLite) | Semantic | 28 | 22 | General segmentation |
| YOLOv8n-seg (TFLite) | Instance | 8 | 10 | Detailed instance mask |
| ML Kit Selfie Segm. | Semantic | 30 | 28 | Portrait / background |
How-to: Integrate ML Kit Selfie Segmentation in 5 Days
Integration takes 5–7 days using our checklist:
- Add SDK via Gradle (Android) or CocoaPods (iOS).
- Create a
SelfieSegmenterOptionsinstance withSTREAM_MODE. - Feed frames to
segmenter.process()(each camera frame). - Obtain the mask and overlay via GPU (Metal/OpenGL).
- Optimize: use
enableRawSizeMask()for quality.
Android code snippet
val segmenter = Segmentation.getClient( SelfieSegmenterOptions.Builder() .setDetectorMode(SelfieSegmenterOptions.STREAM_MODE) .enableRawSizeMask() .build() ) Achieving Real-Time Mask Overlay
The segmentation mask is a ByteArray or FloatArray with class indices. Overlaying it onto a video stream within 33 ms requires GPU.
On iOS, we use Metal for blending: the mask is converted to CIImage via CIFilter.pixellate or a custom Metal kernel, then blended with the original frame using CIBlendWithMask. All Metal rendering avoids CPU-GPU copy overhead via MTLBuffer with shared storage mode.
On Android, we use RenderScript (deprecated in API 31+) or Vulkan/OpenGL ES via SurfaceView. For newer projects: AGSL (Android Graphics Shading Language) starting Android 13, or Canvas.drawBitmap with Paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_IN) for simple cases.
A common mistake: generating a Bitmap from the mask on CPU for every frame. On Pixel 6 this takes ~18 ms just for allocation and copy — eating the entire 33 ms budget. The correct approach: use Bitmap.copyPixelsFromBuffer with a pre-allocated ByteBuffer or pass the mask directly to a shader.
ML Kit Selfie Segmentation in Practice
The fastest path for “background blur” in video calls or photo editors is ML Kit. Case study: a corporate video presentation app with virtual background on iOS. Core Image CIBlendWithMask + ML Kit Selfie Segmentation (iOS SDK): 28 ms on iPhone 13 mini at 720p. On iPhone SE 2nd gen — 41 ms, causing dropped frames every 2–3 seconds at 30 FPS. Solution: reduce processing resolution to 540p, upscale mask using bilinear interpolation — 24 ms, dropped frames gone.
What Our Work Includes
- Requirement analysis and optimal model selection (ML Kit / custom / OpenCV).
- Pipeline design (frame capture → segmentation → overlay → rendering) accounting for target FPS.
- Implementation: coding in Swift/Kotlin, integrating TFLite/Metal/OpenGL.
- Testing on real devices (from iPhone SE to flagship Android).
- Task-specific optimization: profiling, latency reduction.
- Integration documentation and training for the client's team.
Timeline and Cost
ML Kit Selfie Segmentation integration with effect overlay — 5–7 days. Custom segmentation model with Metal/OpenGL rendering on real-time video — 2–3 weeks. Cost is determined individually after analysis. We have over 5 years of market experience and 15+ computer vision projects completed. Order turnkey segmentation development and get a ready solution. Get a consultation for your project.







