Skip to main content
. 2024 Jul 1;14(13):1402. doi: 10.3390/diagnostics14131402
Algorithm 1 Constructing an oversampled balanced dataset
  • Input: 

    main_dir: Directory containing class folders with images

  • Output: 

    Oversampled balanced dataset

  •   1:

    Identify and enumerate all classes in main_dir

  •   2:

    Count the number of images per class

  •   3:

    max_class_count maximum image count across classes

  •   4:

    oversample_target3×max_class_count

  •   5:

    for each class c do

  •   6:

        image_count count of images in class c

  •   7:

        if image_count<oversample_target then

  •   8:

            Oversample class c up to oversample_target using transform

  •   9:

        end if

  • 10:

        for i1 to oversample_target do

  • 11:

            index(i1)modimage_count

  • 12:

            image_path path of index-th image in class c

  • 13:

            Load image from image_path

  • 14:

            Apply preprocess to the image

  • 15:

            if image_count<max_class_count then

  • 16:

               Apply balance to augment the image

  • 17:

            end if

  • 18:

            Apply transform to the image

  • 19:

            Return image and class label

  • 20:

        end for

  • 21:

    end for