text: import shutil
  from pathlib import Path
  
  import numpy as np
  import skimage.io
  
  from bsmu.retinal_fundus.models.utils import debug as debug_utils
  
  
  def collect_images(dir: Path):
      print('collect_images', dir)
      for path in dir.iterdir():
          if path.is_dir():
              collect_images(path)
          else:
              file_name = f'MS-{path.name}'
              shutil.copyfile(
                  path,
                  Path(r'D:\Projects\retinal-fundus-models\databases\OUR_IMAGES\normalizedImages-MS') / file_name)
  
  
  def collect_drishtigs_gt_images(dir: Path, dst_dir: Path):
      for path in dir.iterdir():
          if path.is_dir():
              for mask_path in (path / 'SoftMap').iterdir():
                  shutil.copyfile(mask_path, dst_dir / mask_path.name)
  
  
  def preprocess_masks_from_refuge_dataset(dir: Path, dst_dir: Path):
      for path in dir.iterdir():
          if not path.is_file():
              continue
  
          image = skimage.io.imread(str(path))
          debug_utils.print_info(image, 'image')
          print(np.unique(image))
  
          # disk_coords = np.logical_or(image == 128, image == 0)
          disk_coords = image == 0
          image = np.zeros_like(image)
          image[disk_coords] = 255
  
          skimage.io.imsave(str(dst_dir / f'{path.stem}.png'), image)
  
  
  if __name__ == '__main__':
      # collect_images(Path(r'D:\Projects\retinal-fundus-models\databases\OUR_IMAGES\ФОТО_ДЗН_РС'))
      # collect_drishtigs_gt_images(Path(r'D:\Projects\retinal-fundus-models\databases\Drishti-GS1_files\Drishti-GS1_files\Test\Test_GT'),
      #                             Path(r'D:\Projects\retinal-fundus-models\data\optic-disk-cup\drishtigs\temp'))
  
      preprocess_masks_from_refuge_dataset(
          Path(r'C:\MyDiskBackup\Projects\retinal-fundus-models\data\optic-disk-cup\NEW-refuge-masks'),
          Path(r'C:\MyDiskBackup\Projects\retinal-fundus-models\data\optic-disk-cup\NEW-refuge-masks-optic-cup'))
  