code: def make_kolektor_dataset(
      root: str | Path,
      train_split_ratio: float = 0.8,
      split: str | Split | None = None,
  ) -> DataFrame:
      """Create Kolektor samples by parsing the Koelktor data file structure.
  
      The files are expected to follow the structure:
          image files:
              path/to/dataset/item/image_filename.jpg
              path/to/dataset/kos01/Part0.jpg
          mask files:
              path/to/dataset/item/mask_filename.bmp
              path/to/dataset/kos01/Part0_label.bmp
  
      This function creates a dataframe to store the parsed information based on the following format:
      |---|--------------------|--------|-------|---------|---------------------|--------------------|-------------|
      |   |    path            | item   | split | label   |  image_path         | mask_path          | label_index |
      |---|--------------------|--------|-------|---------|---------------------|--------------------|-------------|
      | 0 |   KolektorSDD      | kos01  | test  |  Bad    | /path/to/image_file | /path/to/mask_file |      1      |
      |---|--------------------|--------|-------|---------|---------------------|--------------------|-------------|
  
      Args:
          root (Path): Path to dataset
          train_split_ratio (float, optional): Ratio to split good images into train/test
              Defaults to 0.8 for train.
          split (str | Split | None, optional): Dataset split (Either train or test). Defaults to None.
  
      Examples:
          The following example shows how to get training samples from Kolektor Dataset:
  
          >>> root = Path('./KolektorSDD/')
  
          >>> samples = make_kolektor_dataset(root, train_split_ratio=0.8)
          >>> print(samples.head())
                  path      item   split  label        image_path                        mask_path             label_index
          0    KolektorSDD  kos01  train  Good  KolektorSDD/kos01/Part0.jpg  KolektorSDD/kos01/Part0_label.bmp      0
          1    KolektorSDD  kos01  train  Good  KolektorSDD/kos01/Part1.jpg  KolektorSDD/kos01/Part1_label.bmp      0
          2    KolektorSDD  kos01  train  Good  KolektorSDD/kos01/Part2.jpg  KolektorSDD/kos01/Part2_label.bmp      0
          3    KolektorSDD  kos01   test  Good  KolektorSDD/kos01/Part3.jpg  KolektorSDD/kos01/Part3_label.bmp      0
          4    KolektorSDD  kos01  train  Good  KolektorSDD/kos01/Part4.jpg  KolektorSDD/kos01/Part4_label.bmp      0
  
      Returns:
          DataFrame: an output dataframe containing the samples of the dataset.
      """
  
      root = Path(root)
  
      # Get list of images and masks
      samples_list = [
          (str(root),) + f.parts[-2:]
          for f in root.glob(r"**/*")
          if f.suffix == ".jpg"
      ]
      masks_list = [
          (str(root),) + f.parts[-2:]
          for f in root.glob(r"**/*")
          if f.suffix == ".bmp"
      ]
  
      if not samples_list:
          raise RuntimeError(f"Found 0 images in {root}")
  
      # Create dataframes
      samples = DataFrame(
          samples_list, columns=["path", "item", "image_path"]
      )
      masks = DataFrame(
          masks_list, columns=["path", "item", "image_path"]
      )
  
      # Modify image_path column by converting to absolute path
      samples["image_path"] = (
          samples.path + "/" + samples.item + "/" + samples.image_path
      )
      masks["image_path"] = (
          masks.path + "/" + masks.item + "/" + masks.image_path
      )
  
      # Sort samples by image path
      samples = samples.sort_values(by="image_path", ignore_index=True)
      masks = masks.sort_values(by="image_path", ignore_index=True)
  
      # Add mask paths for sample images
      samples["mask_path"] = masks.image_path.values
  
      # Use is_good func to configure the label_index
      samples["label_index"] = samples["mask_path"].apply(
          is_mask_anomalous
      )
      samples.label_index = samples.label_index.astype(int)
  
      # Use label indexes to label data
      samples.loc[(samples.label_index == 0), "label"] = "Good"
      samples.loc[(samples.label_index == 1), "label"] = "Bad"
  
      # Add all 'Bad' samples to test set
      samples.loc[(samples.label == "Bad"), "split"] = "test"
  
      # Divide 'good' images to train/test on 0.8/0.2 ratio
      train_samples, test_samples = train_test_split(
          samples[samples.label == "Good"],
          train_size=train_split_ratio,
          random_state=42,
      )
      samples.loc[train_samples.index, "split"] = "train"
      samples.loc[test_samples.index, "split"] = "test"
  
      # Reorder columns
      samples = samples[
          [
              "path",
              "item",
              "split",
              "label",
              "image_path",
              "mask_path",
              "label_index",
          ]
      ]
  
      # assert that the right mask files are associated with the right test images
      assert (
          samples.loc[samples.label_index == 1]
          .apply(
              lambda x: Path(x.image_path).stem
              in Path(x.mask_path).stem,
              axis=1,
          )
          .all()
      ), "Mismatch between anomalous images and ground truth masks. Make sure the mask files  \
          follow the same naming convention as the anomalous images in the dataset (e.g. image: 'Part0.jpg', \
          mask: 'Part0_label.bmp')."
  
      # Get the dataframe for the required split
      if split:
          samples = samples[samples.split == split].reset_index(
              drop=True
          )
  
      return samples
  
imports: from __future__ import annotations
  import logging
  from pathlib import Path
  import albumentations
  import numpy
  from cv2 import imread
  from pandas import DataFrame
  from sklearn.model_selection import train_test_split
  from anomalib.data.base import AnomalibDataModule, AnomalibDataset
  from anomalib.data.task_type import TaskType
  from anomalib.data.utils import DownloadInfo, InputNormalizationMethod, Split, TestSplitMode, ValSplitMode, download_and_extract, get_transforms
label_desc: Use image node_id 2 for calling a global function with example usage: make_kolektor_dataset(root, train_split_ratio, split) and returns: samples