# segmentation_mask_directory_parser

Python API: `luxonis_ml.data.parsers.segmentation_mask_directory_parser`

## Classes

### SegmentationMaskDirectoryParser

Parse a directory with segmentation mask annotations into LDF.

Expected format:

```text
dataset_dir/
├── train/
│   ├── img1.jpg
│   ├── img1_mask.png
│   ├── ...
│   └── _classes.csv
├── valid/
└── test/
```

`_classes.csv` maps pixel values to class names:

```text
Pixel Value, Class
0, background
1, class1
2, class2
```

The parser reads only the class-name column. That column must be named `" Class"` with a leading space, which is the header that
Roboflow writes. The name of the pixel-value column does not matter, because the parser never reads it. The row order gives the
pixel value, so the first row describes pixel value 0.

The parser does not remove the whitespace from the class names. The row `0, background` gives the class name `" background"`, with
the leading space.

The parser reads each mask as an 8-bit grayscale image. Each distinct pixel value becomes one class. The parser takes the class
name from that row of the class-name column.

This is one of the formats that Roboflow can generate.

#### Methods

##### from_dir

```python
def from_dir(dataset_dir: Path) -> tuple[list[Path], list[Path], list[Path]]:
```

Parse all data in a source dataset directory.

Parameters

 * `dataset_dir` (`Path`): Source dataset directory.
 * `**kwargs`: Additional parser-specific arguments.

Returns

 * `tuple[list[Path], list[Path], list[Path]]`: Added images for the train, validation, and test splits.

##### from_split

```python
def from_split(image_dir: Path, seg_dir: Path, classes_path: Path) -> ParserOutput:
```

Parse segmentation mask annotations into LDF records.

Annotations include classification and segmentation.

Parameters

 * `image_dir` (`Path`): Directory with images.
 * `seg_dir` (`Path`): Directory with segmentation masks.
 * `classes_path` (`Path`): CSV file with class names.

Returns

 * `ParserOutput`: Parser output containing annotation records, skeleton metadata, and added images.

##### validate_split

```python
def validate_split(split_path: Path) -> dict[str, Any] | None:
```

Validate whether a split directory has the expected format.

Parameters

 * `split_path` (`Path`): Path to a split directory.

Returns

 * `dict[str, Any] | None`: Keyword arguments for `from_split`, or `None` if the split is not in the expected format.
