Stay organized with collections Save and categorize content based on your preferences.
ML Kit's subject segmentation API allows developers to easily separate multiple subjects from the background in a picture, enabling use cases such as sticker creation, background swap, or adding cool effects to subjects.
Subjects are defined as the most prominent people, pets, or objects in the foreground of the image. If 2 subjects are very close or touching each other, they are considered a single subject.
The subject segmentation API takes an input image and generates an output mask or bitmap for the foreground. It also provides a mask and bitmap for each one of the subjects detected (the foreground is equal to all subjects combined).
By default, the foreground mask and foreground bitmap are the same size as the input image (the size of each individual subject's mask and bitmap will likely differ from input image size). Each pixel of the mask is assigned a float number that has a range between 0.0 and 1.0. The closer the number is to 1.0, the higher the confidence that the pixel represents a subject, and vice versa.
On average the latency measured on Pixel 7 Pro is around 200 ms. This API currently only supports static images.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003eThe ML Kit subject segmentation API enables developers to isolate subjects (people, pets, objects) from the background in images for various applications like sticker creation and background replacement.\u003c/p\u003e\n"],["\u003cp\u003eThis API provides individual masks and bitmaps for each detected subject, allowing for granular manipulation and effects.\u003c/p\u003e\n"],["\u003cp\u003eAll processing happens on-device, ensuring user privacy and eliminating the need for internet connectivity.\u003c/p\u003e\n"],["\u003cp\u003eThis API is currently in beta and might undergo changes that could affect backward compatibility.\u003c/p\u003e\n"]]],[],null,["| This API is offered in beta, and is not subject to any SLA or deprecation policy. Changes may be made to this API that break backward compatibility.\n\nML Kit's subject segmentation API allows developers to easily separate multiple\nsubjects from the background in a picture, enabling use cases such as sticker\ncreation, background swap, or adding cool effects to subjects.\n\nSubjects are defined as the most prominent people, pets, or objects in the\nforeground of the image. If 2 subjects are very close or touching each other,\nthey are considered a single subject.\n\nThe subject segmentation API takes an input image and generates an output mask\nor bitmap for the foreground. It also provides a mask and bitmap for each one of\nthe subjects detected (the foreground is equal to all subjects combined).\n\nBy default, the foreground mask and foreground bitmap are the same size as the\ninput image (the size of each individual subject's mask and bitmap will likely\ndiffer from input image size). Each pixel of the mask is assigned a float number\nthat has a range between `0.0` and `1.0`. The closer the number is to `1.0`, the\nhigher the confidence that the pixel represents a subject, and vice versa.\n\nOn average the latency measured on Pixel 7 Pro is around 200 ms. This API\ncurrently only supports static images.\n\n[Android](/ml-kit/vision/subject-segmentation/android)\n\nKey capabilities\n\n- **Multi-subject segmentation:** provides masks and bitmaps for each individual subject, rather than a single mask and bitmap for all subjects combined.\n- **Subject recognition:** subjects recognized are objects, pets, and humans.\n- **On-device processing:** all processing is performed on the device, preserving user privacy and requiring no network connectivity.\n\nExample results\n\n| Input Image | Output Image + Mask |\n|-------------|---------------------|\n| | |\n| | |\n| | |"]]