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: 2024-05-21T18:30:00Z
Last Updated: 2024-07-24T18:30:00Z
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
LibrariesLoaded | Event raised when native libraries have been loaded successfully |
BackgroundRemoved | Event raised after getting output image path. It is a temp file so it will be deleted as soon as user closes app.imagePath | text |
ErrorOccurred | Event raised when any error occurs.errorMsg | text |
BackgroundReplaced | Event 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
IsInitialized | Returns whether Image Segmenter has been initialized or not |
LoadLibraries | Tries to load native libraries from zip. 'zipPath' can be file path and direct url.zipPath | text |
Initialize | Initialize 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 |
ProcessImage | Process input image (can be Image component, file path or content uri) to remove background from itimage | any |
ReplaceBackgroundWithColor | Replaces background color of provided imagebgColor | number imagePath | text |
Release | Closes Image Segmenter and releases acquired resources. |
Properties
OutputQuality | Sets output image quality. Default value is 100. Property Type : write-only Accepts : number |
BlurBackground | Tells segmenter to blur background instead of removing it. Property Type : write-only Accepts : boolean |
BlurRadius | Sets 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 threshold
. 1.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.
Release Segmenter once your job is done.
Not mandatory, but as a good practice.
5. Samples and Demo
Demo Video:
6. Purchase Extension
https://sunnythedeveloper.in/830-2/
Thank you.
Hope it helps!