text: from typing import Union
  
  import numpy as np
  
  from divnoising.data_loader.mnist_dloader import MNISTNoisyLoader
  
  
  def random_crop(img, crop_size):
      C, H, W = img.shape
      assert H >= crop_size and W >= crop_size
      s_h = 0
      if H > crop_size:
          s_h = np.random.choice(np.arange(H - crop_size))
      s_w = 0
      if W > crop_size:
          s_w = np.random.choice(np.arange(W - crop_size))
  
      return img[:, s_h:s_h + crop_size, s_w:s_w + crop_size]
  
  
  class MNISTClasfNoisyLoader(MNISTNoisyLoader):
      """
      Instead of actual noise levels, it returns noise index: a value from {0,1,2,...,len(config.data.noise_levels)}
      """
      def __init__(self,
                   fpath_dict: dict,
                   label_fname: Union[str, None] = None,
                   return_character_labels: bool = False,
                   random_crop_sz=0) -> None:
          super().__init__(fpath_dict, label_fname=label_fname, return_character_labels=return_character_labels)
          self._crop_sz = random_crop_sz
  
      def __getitem__(self, index):
          img, *_ = super().__getitem__(index)
          if self._crop_sz > 0:
              img = random_crop(img, self._crop_sz)
          return img, self.get_noise_index(index)
  