Classification vs Detection vs Segmentation in Vision
Classification vs detection vs segmentation compares three computer vision tasks by how much detail they give about an image. Image classification assigns one label to the whole image, object detection draws a labelled bounding box with a confidence score around each object, and segmentation labels every pixel to give exact shapes, at rising labelling and compute cost.
Computer vision teaches machines to understand images and video. Almost every practical vision system, from a phone camera to a factory inspection line, is built on one of three core tasks. Choosing the right one is the first design decision and drives the data you need, the model you train and how you measure success.
Image classification
Classification answers the question “what is in this image?” The model outputs a probability for each class, and the highest is the prediction. Variants include binary (good or defective), multi-class (one of 1000 categories) and multi-label (an image can contain both “rust” and “crack”).
Models are usually convolutional neural networks (CNNs) such as ResNet and EfficientNet, or vision transformers (ViT). They learn filters that detect edges, then textures, then parts and whole objects, as explained in how neural networks work.
- Labels needed: one class per image.
- Metrics: accuracy, precision, recall, F1 score and confusion matrix.
- Uses: sorting products, medical image screening, pass or fail inspection, plant disease identification.
Object detection
Detection answers “what objects are here, and where?” For each object it predicts a class, a confidence score and a bounding box (x, y, width, height). A single image can contain many objects of many classes.
Two families dominate:
- Two stage detectors such as Faster R-CNN first propose candidate regions, then classify and refine each one. They are accurate but slower.
- One stage detectors such as YOLO, SSD and RetinaNet predict boxes and classes in a single pass, fast enough for real time video. Transformer based detectors such as DETR are also widely used.
Box quality is measured by intersection over union (IoU):
A prediction usually counts as correct when IoU is at least 0.5 and the class matches. Overall performance is reported as mean average precision (mAP), averaging precision over classes and, in the COCO benchmark, over IoU thresholds from 0.5 to 0.95.
- Labels needed: a box and class for each object.
- Uses: counting parts on a conveyor, pedestrian detection in vehicles, PPE compliance checks, retail shelf monitoring.
Image segmentation
Segmentation answers “which pixels belong to what?” The output is a mask the same size as the image.
- Semantic segmentation gives each pixel a class (road, car, sky) without separating individual objects. U-Net and DeepLab are classic models.
- Instance segmentation separates each object of the same class with its own mask. Mask R-CNN extends Faster R-CNN with a mask branch.
- Panoptic segmentation combines both: every pixel gets a class, and countable objects also get an instance identity.
Metrics include pixel accuracy, mean IoU across classes and the Dice coefficient, which is popular in medical imaging.
- Labels needed: pixel masks or polygon outlines.
- Uses: tumour boundaries in medical scans, drivable area for autonomous vehicles, measuring crack or corrosion area, satellite land use mapping.
Classification vs detection vs segmentation: comparison
| Feature | Classification | Object detection | Segmentation |
|---|---|---|---|
| Question answered | What is in the image? | What and where (box)? | What and exactly where (pixels)? |
| Output | Class label and probability | Boxes, classes, scores | Pixel mask per class or instance |
| Labelling effort | Lowest | Medium | Highest |
| Compute cost | Lowest | Medium | Highest |
| Typical models | ResNet, EfficientNet, ViT | YOLO, Faster R-CNN, DETR | U-Net, DeepLab, Mask R-CNN |
| Main metric | Accuracy, F1 | mAP at IoU thresholds | Mean IoU, Dice |
| Industrial example | Good or reject part | Count and locate defects | Measure defect area |
- Given
- A detector predicts a box from (40, 30) to (140, 110) pixels for a defect. The labelled ground truth box is from (60, 40) to (160, 120).
- Find
- The IoU, and whether the detection counts as correct at an IoU threshold of 0.5.
- Assumptions
- Boxes are axis aligned; coordinates are (x, y) of the top left and bottom right corners.
- Solution
- Predicted area = 100 × 80 = 8000 px²; true area = 100 × 80 = 8000 px²
Overlap: x from 60 to 140 (80 px), y from 40 to 110 (70 px), area = 5600 px²
Union = 8000 + 8000 − 5600 = 10 400 px²
IoU = 5600 ÷ 10 400 = 0.54 - Answer
- IoU is about 0.54, above 0.5, so the detection counts as a true positive
- Limitations
- At stricter thresholds such as 0.75, used in COCO style evaluation, the same box would count as a miss.
Key formulas for classification vs detection vs segmentation
| Quantity | Formula | Symbols and units |
|---|---|---|
| Intersection over union | IoU = Area of overlap ÷ Area of union | Areas in px², IoU is dimensionless |
| Box area | A = width × height | Width and height in px from the corner coordinates |
| Area of union | Union = A_pred + A_true − Overlap | A_pred, A_true = predicted and ground truth box areas in px² |
How to choose
- Start with the business question. Do you need a decision, a location and count, or an exact shape and size?
- Pick the simplest task that answers it. Classification is cheaper to label and runs on modest hardware.
- Consider the deployment hardware. Real time detection on an edge camera may need a small YOLO style model; segmentation at high resolution needs a GPU.
- Plan the labelling budget. Segmentation labels can cost ten times more than classification labels.
Tasks can also be chained: a detector finds each part, then a classifier grades it, or a detector crops a region that a segmentation model measures.
Practical tips
- Use transfer learning: start from a model pre-trained on ImageNet or COCO and fine tune on your images. It needs far less data.
- Augment data with flips, rotations, brightness changes and crops so the model copes with real conditions.
- Control the lighting and optics in industrial setups; good images beat clever models. See machine vision components for cameras, lenses and lighting.
- Validate on images from the real production line, not only lab samples.
All three tasks are supervised learning problems, so label quality limits model quality. A small, carefully labelled dataset often beats a large, noisy one.
Classification vs detection vs segmentation interview and viva questions
- What does an image classifier output? It outputs a probability for each class and takes the highest as the prediction, giving one label for the whole image.
- How do one stage and two stage detectors differ? Two stage detectors such as Faster R-CNN first propose candidate regions and then classify and refine them, which is accurate but slower. One stage detectors such as YOLO predict boxes and classes in a single pass, fast enough for real time video.
- When does a detection count as correct? Usually when its IoU with the ground truth box is at least 0.5 and the class matches.
- What is the difference between semantic and instance segmentation? Semantic segmentation gives each pixel a class without separating objects, while instance segmentation gives each object of the same class its own mask.
- Which task suits measuring a defect area? Segmentation, because only a pixel mask gives the exact shape and area of a defect. Classification or detection is cheaper when a pass or fail decision or a count is enough.
Frequently asked questions
Which computer vision task should I use for defect inspection?
If you only need a pass or fail decision per part, image classification is enough. If you need to know where each defect is, or count defects, use object detection. If you need the exact shape or area of a defect, for example to measure a scratch length or a corrosion area, use segmentation.
What is the difference between semantic and instance segmentation?
Semantic segmentation assigns a class to every pixel but does not separate objects of the same class, so two touching cars become one car region. Instance segmentation also separates individual objects, giving each car its own mask. Panoptic segmentation combines both for the whole image.
Why is segmentation data more expensive to label?
Classification needs one label per image and detection needs a box per object, which takes seconds. Segmentation needs a precise outline or pixel mask for every object, which can take minutes per image. Tools with assisted labelling reduce the effort but it remains the most costly of the three.
References
- K. He, X. Zhang, S. Ren and J. Sun, Deep Residual Learning for Image Recognition, CVPR, 2016
- J. Redmon et al., You Only Look Once: Unified, Real-Time Object Detection, CVPR, 2016
- O. Ronneberger, P. Fischer and T. Brox, U-Net: Convolutional Networks for Biomedical Image Segmentation, MICCAI, 2015
- K. He, G. Gkioxari, P. Dollár and R. Girshick, Mask R-CNN, ICCV, 2017
- T.-Y. Lin et al., Microsoft COCO: Common Objects in Context, ECCV, 2014
Get one engineering email a week
New articles, worked examples and study notes every week. Free, no spam, unsubscribe any time.