def make_realiad_dataset(
    root: str | Path,
    split: str | Split | None = None,
    extensions: Sequence[str] | None = None,
    metadata: dict | None = None,
) -> DataFrame:
    """Create Real-IAD samples by parsing the JSON metadata.

    Args:
        root (Path | str): Path to dataset root directory
        split (str | Split | None, optional): Dataset split (train or test)
            Defaults to ``None``.
        extensions (Sequence[str] | None, optional): Valid file extensions
            Defaults to ``None``.
        metadata (dict | None, optional): JSON metadata containing dataset organization.
            Defaults to ``None``.

    Returns:
        DataFrame: Dataset samples with columns:
            - image_path: Path to image file
            - mask_path: Path to mask file (if available)
            - label_index: Numeric label (0=normal, 1=abnormal)
            - split: Dataset split (train/test)
    """
    if extensions is None:
        extensions = IMG_EXTENSIONS

    root = validate_path(root)

    if metadata is None:
        msg = "JSON metadata is required for RealIAD dataset"
        raise ValueError(msg)

    samples_list = []

    # Use train/test splits from JSON metadata
    if split is not None:
        split_key = "train" if split == Split.TRAIN else "test"
        if split_key not in metadata:
            msg = f"Split {split_key} not found in JSON metadata"
            raise ValueError(msg)
        samples = metadata[split_key]
    else:
        # If no split specified, use all samples
        samples = metadata.get("train", []) + metadata.get("test", [])

    for sample in samples:
        # Create sample data with only essential columns
        sample_data = {
            "image_path": str(root / sample["image_path"]),
            "mask_path": str(root / sample["mask_path"]) if sample.get("mask_path") else "",
            "label_index": LabelName.NORMAL if sample["anomaly_class"] == "OK" else LabelName.ABNORMAL,
            "split": "train" if sample in metadata.get("train", []) else "test",
        }
        samples_list.append(sample_data)

    samples = DataFrame(samples_list)

    # Set task type
    samples.attrs["task"] = "classification" if (samples["mask_path"] == "").all() else "segmentation"

    return samples
Create Real-IAD samples by parsing the JSON metadata.

    Args:
        root (Path | str): Path to dataset root directory
        split (str | Split | None, optional): Dataset split (train or test)
            Defaults to ``None``.
        extensions (Sequence[str] | None, optional): Valid file extensions
            Defaults to ``None``.
        metadata (dict | None, optional): JSON metadata containing dataset organization.
            Defaults to ``None``.

    Returns:
        DataFrame: Dataset samples with columns:
            - image_path: Path to image file
            - mask_path: Path to mask file (if available)
            - label_index: Numeric label (0=normal, 1=abnormal)
            - split: Dataset split (train/test)
    
src/anomalib/data/datasets/image/realiad.py