[PAID] ImageSegmentation: Remove background from Image using AI ($8 or INR 551) 

 ImageSegmentation Extension

With ImageSegmenation extension you can easily remove, replace and blur background of an Image using AI which ensures results will be quite good. You might feel sometimes results are not completely accurate but then it’s limitation of lite model running on Android. It works completely offline without requirement of Internet or any API.

1. Overview

LatestVersion: 2
Released:  May 22, 2024
Last Updated:  July 25, 2024
Min SDK: 21
Permissions: READ_MEDIA_IMAGES (not required if you use Activity Starter to pick images)

Aix Size: 1.1 mb

Key Features:

  • Easy Integration: Simple and easy to understand extension blocks
  • High Accuracy: Utilizes advanced machine learning models to accurately distinguish between the person/s (or objects) and the background.
  • Customizable Output: Offers flexibility in output image quality and you can customize confidence threshold of Segmenter to avoid losing too much details or vice-versa.
  • Optimized for Performance: Optimized to run efficiently on mobile devices, balancing performance and battery consumption.
  • Offline Capability: Can run locally on the device, without needing an internet connection.

2. Blocks

3. Documentation

Events
LibrariesLoadedEvent raised when native libraries have been loaded successfully
BackgroundRemovedEvent raised after getting output image path. It is a temp file so it will be deleted as soon as user closes app.
imagePath | text
ErrorOccurredEvent raised when any error occurs.
errorMsg | text
BackgroundReplacedEvent raised after replacing image’s background with color. It is a temp file so it will be deleted as soon as user closes app.
imagePath | text
Methods
IsInitializedReturns whether Image Segmenter has been initialized or not
LoadLibrariesTries to load native libraries from zip. ‘zipPath’ can be file path and direct url.
zipPath | text
InitializeInitialize Image Segmenter with provided thresholdConfidence threshold. A pixel having thresholdConfidence less than this value will be removed from foreground. Default value is 0.5, however it is recommended to keep it between 0.5 and 0.8 to avoid losing image details.
confidenceThreshold | number
ProcessImageProcess input image (can be Image component, file path or content uri) to remove background from it
image | any
ReplaceBackgroundWithColorReplaces background color of provided image
bgColor | number
imagePath | text
ReleaseCloses Image Segmenter and releases acquired resources.
Properties
OutputQualitySets output image quality. Default value is 100.
Property Type : write-only
Accepts : number
BlurBackgroundTells segmenter to blur background instead of removing it.
Property Type : write-only
Accepts : boolean
BlurRadiusSets blur radius, value should be between 1 and 25. Default value is 10.
Property Type : write-only
Accepts : number

4. Example Usage

Load Native Libraries
You can load native libraries either using url or file path. Also you can use NativeUtil extension to find recommended ABI type to download/load only required library. This will help you to reduce app size on device.

LibrariesLoaded event will be raised if libs have been loaded successfully, otherwise ErrorOccurred event will be raised.

Then initialize Image Segmenter with appropriate confidence threshold1.0 means only pixels with very high probability of being foreground will be included in final image. This value will lose a lot of required details in image.
0.1 means pixels with low probablity will also be included in foreground so it may produce highly inaccurate results.
So choose something median value like 0.5.

Now if initialization was successful then proceed to process input image.
I’ll use Activity Starter to pick image and then show on Image component.

After background is removed from image, it is saved to a temp file which will be deleted once user exits app.
Processing time depends upon image quality and size

Bakground will be blurred instead of removing if BlurBackground property is set to true.

Release Segmenter once your job is done.

Not mandatory, but as a good practice.

5. Samples and Demo

Original ImageBackground Removed

Demo Video:

6. Purchase Extension

7. Updates

ChangeLog Version 2

  • Native Libraries can be loaded at runtime using zip files, so apk size will not increase. No need to inject .so files.
    image
    zipPath can be file path or url
  • Now you can set background color of a transparent (png) image
    image
  • Added BlurBackground property to blur background of image instead of removing it
    BlurRadius property has been added also to control intensity (1 to 25) of Blur. However, note that it depends on complexity of image’s background as well.

Thank you.
Hope it helps!

Subscribe
Notify of
guest
0 Comments
Oldest
Newest
Inline Feedbacks
View all comments