Key takeaways:
- Segmentation works at the pixel level: classification gives one label for the whole image and object detection draws a box around each object, while segmentation returns a mask that follows each object’s outline.
- The three main types are semantic segmentation, which labels every pixel by class, instance segmentation, which separates individual objects of the same class, and panoptic segmentation, which does both in a single output.
- U-Net (2015), DeepLab (2016) and Mask R-CNN (2017) learn a fixed set of classes from labeled masks, while Meta’s Segment Anything models segment objects they were never trained on from a click, a box or, since SAM 3, a short text prompt.
- In everyday image workflows, segmentation is the step behind background removal, object extraction and generative remove or replace, which Cloudinary exposes as URL parameters such as e_background_removal and e_extract.
AI segmentation is the use of machine learning models to split an image into regions and label every pixel with the object or area it belongs to. The result is a mask that follows each object’s exact outline, which is what lets software cut a product out of its background, measure a structure on a medical scan or tell a car where the road ends.
This guide covers image segmentation. In marketing, “AI segmentation” can also mean grouping customers into audiences, which is a different technique that works on customer data rather than pixels.
The pace of change in this space has accelerated sharply, with promptable foundation models, transformer-based architectures, and open-vocabulary techniques reshaping how objects are identified and separated in images.
In this article:
- What is AI Image Segmentation?
- How AI Image Segmentation Works
- Semantic vs. Instance vs. Panoptic Segmentation
- AI Segmentation Models Compared: U-Net, DeepLab, Mask R-CNN and SAM
- Foundation Models and the Segment Anything Approach
- Why AI Image Segmentation is Important
- How Cloudinary Uses AI Segmentation in Image Transformations
What is AI Image Segmentation?
Image segmentation is the process of partitioning an image into distinct regions or segments based on intrinsic characteristics, such as color, intensity, texture, shape, and so on, for other image processing tasks like object detection and classification. Unlike other related image processing techniques like image classification, which categorizes an image within a class, and object detection, which identifies objects within an image, image segmentation analyzes an image at the pixel level and then assigns annotations based on the properties of each pixel in the image.
A quick way to see the difference: for a photo of a dog on a couch, classification answers “dog”, object detection returns a rectangle around the dog, and segmentation returns a dog-shaped mask that separates every pixel of fur from the couch behind it.
Image segmentation can be broadly categorized under two types: traditional and AI-based image segmentation. Traditional image segmentation utilizes techniques, such as, thresholding, edge detection and clustering, to analyze images. These methods rely on fixed mathematical and statistical rules, which work on clean, high-contrast images but struggle with cluttered scenes, overlapping objects and large, varied datasets.
AI image segmentation, on the other hand, is a subfield of image segmentation that uses machine learning or deep learning algorithms, particularly Support Vector Machines (SVMs), Random Forests, and Convolutional Neural Networks, to automate and enhance the segmentation process. AI-based image segmentation outshines traditional methods in terms of accuracy and efficiency when handling complex and large datasets.
How AI Image Segmentation Works
The difference from classical methods is that an AI model learns what objects look like from labeled examples instead of following hand-written rules. Basically, it involves training machine learning models on labeled image datasets to learn patterns and features so they can perform segmentation on new and unseen images.
Let’s break down the different steps that make up AI image segmentation:
Data collection and Preprocessing
Data is the foundation of any AI image segmentation project. Depending on the objectives of your project, you can use either your own labeled image dataset or open source image datasets. If you’re working with self-collected images, you’ll need to manually annotate each image with pixel-level segmentation mask, then you can preprocess the images by normalizing, manipulation (e.g., resizing, upscaling, and so on), to improve the model’s ability to generalize.
One of the major disadvantages of doing this is that it requires significant time and expert annotation skills, which can sometimes lead to drudgery. However, because the dataset contains domain specific images, there’s high accuracy and the model is less error prone.
However, freely available, open-source image datasets contain images that have already been annotated and are ready to use. Meta’s SA-1B, released with the Segment Anything paper, holds more than 1 billion masks on 11 million licensed images. These datasets, however, may not be suitable for niche applications.
Model building or Selection
In image processing, a model is a program or algorithm that uses a set of data that enables it to recognize certain patterns, and then makes predictions or inference based on the data. There are several types of AI models, including machine learning models, deep learning models, supervised learning and unsupervised learning models.
Convolutional Neural Networks (CNNs) are a subtype of machine learning models and are used for classification tasks in computer vision and image processing. CNNs are powerful tools for recognizing patterns in images and they serve as the foundation of most AI image segmentation models. Some other commonly used models include Fully Convolutional Networks (FCNs), U-Nets and Mask R-CNN. More recently, Vision Transformer (ViT) architectures have become a foundation for state-of-the-art segmentation, treating an image as a sequence of patches to capture global context that CNNs handle less directly. Many leading systems now combine convolutional and transformer components to balance accuracy, efficiency, and boundary quality.
To see what an example AI model looks like, you can explore open-source models on platforms like Huggingface and Kaggle.
Training and Evaluation
After a model has been selected, the next step is to train it on the dataset. In each training step, the model runs a forward pass on a batch of images and predicts their masks, a loss function measures the discrepancy between the predicted and ground truth segmentations, and backpropagation adjusts the model’s parameters to reduce that loss. During training, the model learns to extract relevant features from images and map them to pixel-level predictions.
For example, Cross-Entropy Loss is a common choice for classification tasks. It measures the discrepancy between the model’s predicted probabilities and the true labels. Depending on the specific task, other loss functions like Mean Squared Error (MSE) or Focal Loss may be more suitable.
After training, the model’s performance can be evaluated using metrics, such as:
- Intersection over Union (IoU): This measures the overlap between predicted and ground truth segmentations.
- Pixel Accuracy: Used to calculate the proportion of correctly classified pixels.
- Mean Intersection over Union (mIoU): Calculates the averages of the IoU across different object classes.
Fine Tuning and Post-Processing
Fine-tuning is a performance optimization task that can help you get the most out of your data and improve the performance of your model.
For example, consider a scenario where we want to segment specific anatomical structures in medical images, such as tumors in brain scans. Then, we can use a pre-trained image segmentation model (like U-Net or DeepLab v3) that has been trained on a large dataset and learned general-purpose features like edges, textures, and object boundaries.
Finally, we then train the model with a smaller, domain-specific dataset of medical images (e.g., MRI scans) with pixel-level annotations for the target anatomical structures. By leveraging the pre-trained model, the new model can converge faster and require less training data.
Although not a mandatory step, fine-tuning can help improve the performance of the model by adapting to the specific domain and reduce overfitting (this occurs when a model fits too closely with its training dataset, leading to a model that gives high accuracy on the training data but poor performance on new, unseen data) by leveraging the knowledge gained from the large-scale pre-training dataset.
Semantic vs. Instance vs. Panoptic Segmentation
Semantic segmentation labels every pixel with a class, instance segmentation separates each individual object, and panoptic segmentation combines the two so that every pixel gets a class and every countable object gets its own ID. The panoptic segmentation paper calls countable objects such as people and cars “things” and amorphous regions such as sky or grass “stuff”.
| Type | What gets labeled | Are two objects of the same class kept apart? | Output | Typical models | Typical uses |
|---|---|---|---|---|---|
| Semantic segmentation | Every pixel, by class (road, building, tree, car) | No: all cars share one “car” region | One class map for the whole image | FCN, U-Net, DeepLab | Medical scans, street scenes, any task where the class of a region matters more than the count |
| Instance segmentation | Countable objects only (people, cars, products, cells) | Yes: each object gets its own mask and ID | A mask, class and usually a box per detected object | Mask R-CNN | Counting, autonomous driving, robotics, product cutouts |
| Panoptic segmentation | Every pixel: “stuff” by class and “things” by instance | Yes, for things | One map in which each pixel has a class and, for things, an instance ID | Panoptic FPN, UPSNet, EfficientPS | Augmented reality, robotics, full scene understanding |
| Promptable (open-vocabulary) | Whatever you click, box or name in a prompt | Yes, per prompt | Masks for the prompted object or concept | SAM, SAM 2, SAM 3 | Interactive editing, faster data labeling, tracking objects in video |
Also, keep in mind that your AI image segmentation workflow might take a variety of forms depending on the task you’re performing or the kind of dataset you’re using.Beyond the three classic types, open-vocabulary segmentation has emerged as a fast-growing approach that can segment objects described by arbitrary text prompts, even categories not seen during training.
Semantic Segmentation
Semantic segmentation involves classifying each pixel in an image into a specific (predefined) class or category. The goal is to assign a label to every pixel, showing the object class it belongs to. Semantic segmentation provides a holistic understanding of the image content and is used wherever the class of each region matters more than telling individual objects apart. For example, in an image of a city, pixels belonging to roads, buildings, trees, and cars would be assigned different labels.
Instance Segmentation
Instance segmentation works by not only classifying each pixel but also identifying individual instances of objects within the image. This means that pixels belonging to different instances of the same object class are assigned different labels. For instance, in an image with multiple people, the system would assign a unique label to each person, distinguishing them from others. Instance segmentation is commonly used in more complex scenarios, such as autonomous driving, where identifying each car or pedestrian individually is critical, and medical imaging, where individual cells or lesions need to be counted and measured separately.
Mask R-CNN, the best-known instance model, works by extending the Faster R-CNN object detector with an extra branch that predicts a mask for each detected object, so every object comes back with a box, a class and a mask.
Take the following image for example:
Below is the result of both semantic and instance segmentation applied to the image:
Panoptic Segmentation
Panoptic segmentation combines both semantic and instance segmentation. It aims to segment both semantic regions within an image and individual instances (or objects) in a single pass. It classifies each pixel into a semantic category and assigns a unique instance ID to each object instance for differentiation. One major advantage of panoptic segmentation is that it provides a comprehensive analysis of the image, making it suitable for advanced applications like augmented reality and robotics.
The 2018 paper that defined the task also introduced the panoptic quality (PQ) metric, which scores performance on stuff and things together in a single number, so semantic and instance results no longer have to be judged separately.
AI Segmentation Models Compared: U-Net, DeepLab, Mask R-CNN and SAM
Most AI segmentation in production still runs on a handful of well-documented models. The older ones learn a fixed list of classes from labeled masks, while the Segment Anything family is promptable, so one model can segment objects it was never explicitly trained on.
| Model | Published | Segmentation type | What you give it | What it is known for |
|---|---|---|---|---|
| U-Net | 2015 | Semantic, first for biomedical images | An image | A contracting path that captures context and a symmetric expanding path for precise localization; trains well on very few annotated images; segmented a 512×512 image in under a second on a 2015 GPU |
| DeepLab | 2016 | Semantic | An image | Atrous convolution and atrous spatial pyramid pooling (ASPP) to segment objects at several scales; 79.7% mIOU on the PASCAL VOC 2012 test set |
| Mask R-CNN | 2017 | Instance | An image | Adds a mask branch to the Faster R-CNN detector with little overhead, running at about 5 frames per second |
| Segment Anything (SAM) | 2023 | Promptable, images | Points, boxes or a rough mask | Trained on SA-1B (more than 1 billion masks on 11 million images); zero-shot results often competitive with fully supervised models |
| SAM 2 | 2024 | Promptable, images and video | Points, boxes or masks, on images or video frames | A transformer with streaming memory for real-time video; 6x faster than SAM on images and needs 3x fewer interactions than earlier methods on video |
| SAM 3 | 2025 | Promptable concept segmentation, images and video | A short noun phrase, an example image, or both | Finds, segments and tracks every instance of a concept; its authors report double the accuracy of existing systems on concept prompts, and Meta released the weights |
Which one to pick depends on the job. If you have labeled masks for a fixed set of classes and one kind of image, a trained U-Net or DeepLab model is still the standard choice, especially in medical imaging. If you need to count and separate objects, use an instance model in the Mask R-CNN family. If you need masks for arbitrary objects without collecting training data, start with SAM 2, or SAM 3 when you want to describe the object in words instead of clicking on it.
Foundation Models and the Segment Anything Approach
One of the most significant recent shifts in the field is the rise of promptable foundation models for segmentation. Instead of training a separate model for every task, these models are pre-trained on massive datasets and then guided at inference time using prompts such as points, boxes, or text. This lets a single model segment objects it has never explicitly been trained on, a capability known as zero-shot segmentation.
Meta AI’s Segment Anything Model (SAM) helped popularize this approach, and its successor, SAM 2 extends promptable segmentation from static images to video. SAM 2 uses a transformer architecture with a streaming memory component, which makes it more accurate and 6x faster than the original on image segmentation while tracking objects consistently across video frames.
SAM 3, published in November 2025, changes what a prompt can be. Instead of clicking on one object, you give it a short phrase such as “red umbrella” or an example image, and it returns a mask and a unique ID for every matching instance in an image or video. Meta calls this promptable concept segmentation.
For developers, foundation models lower the barrier to entry: rather than assembling large annotated datasets and training from scratch, teams can fine-tune a pre-trained model on a smaller, domain-specific dataset. This is especially valuable in specialized fields like medical imaging, where high-quality labeled data is scarce and expensive to produce.
Why AI Image Segmentation is Important
Improved Accuracy and Efficiency
AI image segmentation automatically identifies and separates objects in images with great accuracy. This saves time compared to the traditional approach, which is slow and often prone to mistakes. Automating this task makes analyzing images faster and more reliable.
Cost Savings in Image Editing and Analysis
AI tools can handle tasks like removing backgrounds, cutting out objects, or adjusting colors automatically. This reduces the need for expensive software or time-consuming manual work, saving money for both businesses and individuals.
Better Decision-Making and Insights
AI segmentation helps identify and organize objects in images, providing useful insights. For example:
- Healthcare: Helps doctors detect and diagnose diseases more accurately using medical images.
- Self-Driving Cars: Helps vehicles understand their surroundings and make safe driving decisions.
Scalability for Large Datasets
AI segmentation works efficiently with large datasets, making it ideal for tasks like analyzing satellite images, processing surveillance footage, or managing medical imaging. Its ability to scale is key for handling massive amounts of visual data.
How Cloudinary Uses AI Segmentation in Image Transformations
In Cloudinary, segmentation runs behind several image transformations: a model finds the subject or the object you name, and the transformation then keeps it, removes it, turns it into a mask or regenerates it. You don’t train or host a model; you add a parameter to the image’s delivery URL.
| Transformation | What the model finds | What you get back |
|---|---|---|
| e_background_removal | The primary foreground object or objects | The subject on a transparent background |
| e_extract | The areas you describe in natural language | The described area on a transparent background, the inverse, or a grayscale mask |
| e_gen_remove | The objects named in the prompt, or regions you specify | The image with those objects replaced by realistic generated pixels |
| e_gen_replace | The object named in from_ | The same scene with that object swapped for what you describe in to_ |
| g_auto:<object> (object-aware cropping) | The bounding box of a named object | A crop that keeps that object in frame |
Background Removal
Cloudinary’s documentation describes its background removal as a combination of neural networks trained on a large dataset to create precise segmentation maps of salient objects, then refine those maps to separate the edges of the foreground from the background. For subjects with fine detail at the edges, such as fur or hair, add the fine edges option, e_background_removal:fineedges_y. Input images are limited to 6144 x 6144 pixels, and larger ones are scaled down before processing.
Extraction and Masks
e_extract is segmentation you steer with words. Describe what to keep and everything else becomes transparent. Add invert_true to make the described area transparent instead, multiple_true to catch every instance of the prompt, or mode_mask to get a grayscale mask that you can combine with e_mask, e_multiply, e_overlay or e_screen:
https://res.cloudinary.com/demo/image/upload/
The effect changes only the alpha channel, so the original RGB data stays intact even where the image turns fully transparent. Large images are processed at a maximum of 2048 x 2048 pixels and then upscaled back to their original size, which can affect quality.
Generative Remove and Replace
e_gen_remove and e_gen_replace locate the object you name, then fill its area with generated pixels. Use multiple_true to remove every instance of a prompt, remove-shadow_true to take an object’s shadow with it, and preserve-geometry_true with e_gen_replace to fill exactly the same shape with the replacement. Both effects work best on simple, clearly visible objects and advise against using them on faces or hands.
Object-aware Cropping
Object-aware cropping is the detection side of the same idea. With the Cloudinary AI Content Analysis add-on, g_auto:sink tells a crop to keep the sink in the frame. It works from bounding boxes rather than pixel masks, and the add-on’s models include lvis, a Large Vocabulary Instance Segmentation model that covers thousands of general objects. Delivery URLs that use the add-on must be signed or generated eagerly, unless you allow unsigned add-on transformations in the Console’s security settings.
Background removal, extract and the generative effects each have a special transformation count, and the first request may return a 423 response while the derived image is generated, so you can create it in advance with an eager transformation. To see a mask for yourself, open a free Cloudinary account and run e_extract with mode_mask on one of your own images.
Leverage AI to tag and categorize your video content effortlessly. Get started with Cloudinary and simplify your media organization.
Frequently Asked Questions
What is segmentation in AI?
Segmentation in AI usually means image segmentation: a model assigns every pixel of an image to an object or region and produces masks that follow each object’s outline. It is used to separate subjects from backgrounds, measure structures in medical scans and help vehicles read road scenes. In marketing, the same phrase can mean AI customer segmentation, which groups people rather than pixels.
What is a segmentation model?
A segmentation model is a neural network trained to output a mask instead of a single label or a box. Well-known examples are U-Net and DeepLab for semantic segmentation and Mask R-CNN for instance segmentation. Promptable models such as SAM 2 and SAM 3 segment whatever you click on or name, without being trained on your specific classes.
How do I segment an image?
For a one-off image, use a promptable model: Meta’s Segment Anything Playground (aidemos.meta.com/segment-anything) runs it in the browser. In code, load a pretrained model such as SAM 2 from its published weights, or call a hosted transformation such as Cloudinary’s e_extract with a text prompt. For a fixed set of classes at scale, fine-tune a U-Net or DeepLab model on your own labeled masks.
What is the difference between semantic and instance segmentation?
Semantic segmentation gives every pixel a class label, so all the cars in a street photo share a single “car” region. Instance segmentation finds each object separately, so each car gets its own mask and ID. Panoptic segmentation combines the two in one output.
What is panoptic segmentation?
Panoptic segmentation labels every pixel in an image with a class and also gives each countable object its own instance ID. It covers background regions such as sky or road and individual objects such as people and cars in a single map. The task was defined in a 2018 paper by Kirillov and colleagues, which also introduced the panoptic quality (PQ) metric used to score it.
What is the Segment Anything Model (SAM)?
SAM is Meta’s promptable segmentation model, published in 2023 and trained on SA-1B, a dataset of more than 1 billion masks on 11 million images. You give it a point, a box or a rough mask, and it returns the mask of that object, even for kinds of objects it never saw in training. SAM 2 (2024) extends it to video, and SAM 3 (2025) adds text and image-example prompts.