code: def apply(self, sample: Sample) -> Sample:
      assert (
          self.data_params.downscale_factor > 0
      )  # Not instantiated yet
      codec = self.data_params.codec
      # final preparation
      if self.mode in {PipelineMode.TRAINING, PipelineMode.EVALUATION}:
          text = np.array(
              codec.encode(sample.targets)
              if sample.targets
              else np.zeros((0,), dtype="int32")
          )
      else:
          text = None
  
      line = sample.inputs
  
      # gray or binary input, add missing axis
      if len(line.shape) == 2:
          line = np.expand_dims(line, axis=-1)
  
      # Validate if the line is valid for training
      if not self.is_valid_line(
          text,
          len(line) // self.data_params.downscale_factor,
          len(line),
          sample.meta.get("id", "Unknown Sample ID"),
      ):
          return sample.new_invalid()
  
      if text is not None:
          sample = sample.new_targets(
              {
                  "gt": np.asarray(text),
                  "gt_len": np.asarray([len(text)]),
                  "fold_id": np.asarray(
                      [sample.meta.get("fold_id", -1)]
                  ),
              }
          )
  
      return sample.new_inputs(
          {
              "img": line.astype(np.uint8),
              "img_len": np.asarray([len(line)]),
          }
      )
  
file_path: calamari/calamari_ocr/ocr/dataset/imageprocessors/preparesample.py
imports: import logging
  from dataclasses import dataclass, field
  from typing import Type
  import numpy
  from paiargparse import pai_dataclass, pai_meta
  from tfaip.data.pipeline.definitions import PipelineMode, Sample
  from tfaip.data.pipeline.processor.dataprocessor import DataProcessorParams, MappingDataProcessor
label_desc: Use image node_id 3 for calling the PrepareSample obj's underlying member method code with example usage: obj.apply(sample) and returns: sample, sample