Mask augmentation for segmentation

2023-12-08 02:52

本文主要是介绍Mask augmentation for segmentation,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

For instance and semantic 语义的 segmentation tasks, you need to augment both the input image and one or more output masks.

  1. You import the required libraries.
  2. You define an augmentation pipeline.
  3. You read images and masks from the disk.
  4. You pass an image and one or more masks to the augmentation pipeline and receive augmented images and masks.

Steps 1 and 2. Import the required libraries and define an augmentation pipeline.

import albumentations as A
import cv2transform = A.Compose([A.RandomCrop(width=256, height=256),A.HorizontalFlip(p=0.5),A.RandomBrightnessContrast(p=0.2),
])

Step 3. Read images and masks from the disk.¶

  • Reading an image
image = cv2.imread("/path/to/image.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  • For semantic segmentation, you usually read one mask per image. Albumentations expects the mask to be a NumPy array. The height and width of the mask should have the same values as the height and width of the image.
mask = cv2.imread("/path/to/mask.png")
  • For instance segmentation, you sometimes need to read multiple masks per image. Then you create a list that contains all the masks.
mask_1 = cv2.imread("/path/to/mask_1.png")
mask_2 = cv2.imread("/path/to/mask_2.png")
mask_3 = cv2.imread("/path/to/mask_3.png")
masks = [mask_1, mask_2, mask_3]

Step 4. Pass image and masks to the augmentation pipeline and receive augmented images and masks.¶

 If the image has one associated mask, you need to call transform with two arguments: image and mask. In image you should pass the input image, in mask you should pass the output mask. transform will return a dictionary with two keys: image will contain the augmented image, and mask will contain the augmented mask.

transformed = transform(image=image, mask=mask)
transformed_image = transformed['image']
transformed_mask = transformed['mask']

 An image and a mask before and after augmentation. Inria Aerial Image Labeling dataset Inria航空图像标签数据集 contains aerial photos as well as their segmentation masks. Each pixel of the mask is marked as 1 if the pixel belongs to the class building and 0 otherwise.

If the image has multiple associated masks, you should use the masks argument instead of mask. In masks you should pass a list of masks.

transformed = transform(image=image, masks=masks)
transformed_image = transformed['image']
transformed_masks = transformed['masks']

这篇关于Mask augmentation for segmentation的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/468297

相关文章

_get_gt_mask、cat_mask、_get_other_mask

import torch# 定义获取标签掩码的函数def _get_gt_mask(logits, target):print("原始 logits:\n", logits)print("目标 target:\n", target)# 将 target 拉平为一维张量target = target.reshape(-1)print("拉平后的 target:\n", target)# 创建一个和

Segmentation简记-Multi-stream CNN based Video Semantic Segmentation for Automated Driving

创新点 1.RFCN & MSFCN 总结 网络结构如图所示。输入视频得到图像分割结果。 简单粗暴

Segmentation简记5-AuxNet: Auxiliary tasks enhanced Semantic Segmentation for Automated Driving

创新点 1.分割网络为主任务,深度估计网络为辅任务 2.loss的设计 总结如图所示 网络结构如图所示 其实很容易理解。 backbone是基于ResNet50 分割网络是基于FCN8 深度估计网络与分割网络类似,最后一层是回归深度层。 最有意思的是两种任务的loss的合并。 分割的loss很常见:cross entropy 深度loss:mean absolute error 算法一:

DS简记1-Real-time Joint Object Detection and Semantic Segmentation Network for Automated Driving

创新点 1.更小的网络,更多的类别,更复杂的实验 2. 一体化 总结 终于看到一篇检测跟踪一体化的文章 网络结构如下: ResNet10是共享的Encoder,yolov2 是检测的Deconder,FCN8 是分割的Deconder。 其实很简单,论文作者也指出:Our work is closest to the recent MultiNet. We differ by focus

Segmentation简记3-UPSNet: A Unified Panoptic Segmentation Network

Segmentation简记3-UPSNet: A Unified Panoptic Segmentation Network 创新点总结实验 创新点 1.统一的全景分割网络 总结 uber的作品 网络结构如下: 还是比较简洁的。 Backbone 采用了原始mask rcnn。 Instance Segmentation Head 使用了最大的特征图,包括bbox回归,分

Segmentation简记2-RESIDUAL PYRAMID FCN FOR ROBUST FOLLICLE SEGMENTATION

创新点 与resnet结合,五层/level的分割由此带来的梯度更新问题,设计了两种方案。 总结 有点意思。看图吧,很明了。 细节图: 全流程图: 实验 Res-Seg-Net-horz: 在UNet上堆叠5个细节图中的结构,没有上采样层。 Res-Seg-Net-non-fixed: 普通方式的更新 Res-Seg-Net-fixed: 每一层的更新,只依据距离它最近的一

3D Deeply Supervised Network for Automatic Liver Segmentation from CT Volumes

下面博主详细翻译了该篇论文,可以当做详尽的参考,并认真学习。 【参考】论文笔记:3D Deeply Supervised Network for Automatic Liver Segmentation from CT 数据集: MICCAI-SLiver07[1] 数据预处理: 作者没有讲数据预处理的过程。 CRF 轮廓精细修正: 参考上述博主博客。 参考文献: [1]Heimann,

Liver Segmentation in CT based on ResUNet with 3D Probabilistic and Geometric Post Process

一、摘要 本文提出了使用具有3D概率和几何后期处理功能的ResUNet的新型肝分割框架。 我们的语义分割模型ResUNet在U-Net的上采样和下采样部分添加了残差单元和批处理规范化层,以构建更深的网络。 为了快速收敛,我们提出了一种新的损失函数DCE,该函数由Dice损失和交叉熵损失线性组合。 我们使用连续的几个CT图像作为训练和测试的输入,以探索更多的上下文信息。 基于ResUNet的初始分割

Deep Learning Techniques for Medical Image Segmentation: Achievements and Challenges

前言: 该篇文章较为全面但稍偏简单的介绍医学图像分割的常见数据集、各种神经网络,以及常见的训练技巧等问题。 一、重点摘录 2.5D approaches are inspired by the fact that 2.5D has the richer spatial information of neighboing pixels wiht less computational costs t

img_Mask

<!DOCTYPE HTML><html lang="en-US"><head><meta charset="gb2312"><title>jQuery鼠标悬浮遮罩显示分享按钮</title><style>.pinit {position:relative;display:inline-block;}.pinit .pinit-overlay {position:absolute;t