Segmentation
Image Segmentation
Dividing an image into meaningful regions. Autonomous driving, medical imaging.
Image Segmentation
Dividing an image into meaningful regions. Autonomous driving, medical imaging.
Segmentation (Image Segmentation) is a computer vision technique that classifies an image at the pixel level and divides it into meaningful regions. Going beyond simply classifying whether an object is present in an image (Classification) or locating it with a bounding box (Detection), it distinguishes the exact boundaries of objects at the pixel level.
Segmentation is divided into three types. Semantic Segmentation classifies all objects of the same class identically (e.g., all cars are the same color). Instance Segmentation distinguishes individual objects even within the same class (e.g., car 1, car 2). Panoptic Segmentation combines the two approaches to distinguish both background and objects.
There are several representative segmentation models. U-Net originated in medical imaging and is known for its encoder-decoder structure and Skip Connection. The DeepLab series introduced Atrous Convolution and ASPP. Mask R-CNN is a representative Instance Segmentation model that adds a segmentation branch to object detection. Recently, SAM (Segment Anything Model) introduced prompt-based segmentation.
The range of real-world applications is very broad. In autonomous driving, it distinguishes roads, lanes, pedestrians, and vehicles in real time. In medical imaging, it precisely separates tumors and organs in CT/MRI. In satellite imagery, it analyzes buildings, roads, and green areas. In video editing, it is used for background removal and object separation.
This is a U-Net example using PyTorch and the Segmentation Models library.
import torch
import segmentation_models_pytorch as smp
import albumentations as A
from albumentations.pytorch import ToTensorV2
# U-Net 모델 정의 (ResNet34 백본)
model = smp.Unet(
encoder_name="resnet34",
encoder_weights="imagenet",
in_channels=3,
classes=21 # PASCAL VOC 클래스 수
)
# 데이터 증강 파이프라인
transform = A.Compose([
A.Resize(256, 256),
A.HorizontalFlip(p=0.5),
A.RandomBrightnessContrast(p=0.2),
A.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]),
ToTensorV2()
])
# 손실 함수: Dice Loss + Cross Entropy
dice_loss = smp.losses.DiceLoss(mode='multiclass')
ce_loss = torch.nn.CrossEntropyLoss()
def combined_loss(pred, target):
return 0.5 * dice_loss(pred, target) + 0.5 * ce_loss(pred, target)
# 추론
model.eval()
with torch.no_grad():
output = model(image_tensor) # (B, C, H, W)
pred_mask = output.argmax(dim=1) # (B, H, W)
# IoU 계산
def iou_score(pred, target, num_classes):
ious = []
for cls in range(num_classes):
pred_cls = (pred == cls)
target_cls = (target == cls)
intersection = (pred_cls & target_cls).sum()
union = (pred_cls | target_cls).sum()
if union > 0:
ious.append(intersection / union)
return torch.tensor(ious).mean()
| Model | mIoU (PASCAL VOC) | Parameter | Inference speed |
|---|---|---|---|
| U-Net (ResNet34) | ~75% | 24M | ~30 FPS (GPU) |
| DeepLabV3+ | ~82% | 41M | ~15 FPS (GPU) |
| Mask R-CNN | ~79% (Instance) | 44M | ~5 FPS (GPU) |
| SegFormer-B4 | ~84% | 64M | ~10 FPS (GPU) |
| SAM (ViT-H) | Excellent Zero-shot | 636M | ~1 FPS (GPU) |
"We deployed a segmentation model that achieved an mIoU of 0.85 or higher in medical image analysis. We boosted performance with Dice Loss and Data Augmentation."
In English, you would say "We deployed a segmentation model achieving mIoU above 0.85 for medical imaging." Terms such as "pixel-wise classification", "instance segmentation", and "semantic parsing" are also frequently used. As evaluation metrics, mention mIoU (mean Intersection over Union), Dice Score, and Pixel Accuracy.