def create_modular_single_targets_with_background(number_of_single_targets_with_background):
        if (os.path.isdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY)):
            pass
        else:
            os.mkdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY)

        if (os.path.isdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY + "/modular_single_targets_with_background")):
            raise Exception("Cannot create Modular Single Targets With Background: Save directory already exists")
        if (os.path.isdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY + "/modular_single_targets_with_background_answers")):
            raise Exception("Cannot create Modular Single Targets With Background Answers: Save directory already exists")

        os.mkdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY + "/modular_single_targets_with_background")
        os.mkdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY + "/modular_single_targets_with_background_answers")

        cpu_count = multiprocessing.cpu_count()
        pics_per_process = (number_of_single_targets_with_background / cpu_count) + 1
        start_time = timeit.default_timer()

        jobs = []
        for index in range(cpu_count):
            starting_index = index * int(pics_per_process)
            image_generation_process = multiprocessing.Process(target=ModularSyntheticDatasetMaker.run_modular_single_targets_with_background_generator, args=(pics_per_process, starting_index))
            jobs.append(image_generation_process)
            image_generation_process.start()

        for job in jobs:
            job.join()

        Logger.log("Modular Single Targets With Background saved at: " + Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY + "/modular_single_targets_with_background")
        Logger.log("Modular Single Targets With Background Answers saved at: " + Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY + "/modular_single_targets_with_background_answers\n")

        print("====================================")
        print("Total number of modular single targets with background generated:", len(os.listdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY + "/modular_single_targets_with_background")))
        print("Total elapsed time (sec):", timeit.default_timer() - start_time)
        print("====================================")
Beispiel #2
0
    def create_modular_single_targets_with_background(
            number_of_single_targets_with_background):
        if (os.path.isdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY)):
            pass
        else:
            os.mkdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY)

        if (os.path.isdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY +
                          "/modular_single_targets_with_background")):
            raise Exception(
                "Cannot create Modular Single Targets With Background: Save directory already exists"
            )
        if (os.path.isdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY +
                          "/modular_single_targets_with_background_answers")):
            raise Exception(
                "Cannot create Modular Single Targets With Background Answers: Save directory already exists"
            )

        os.mkdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY +
                 "/modular_single_targets_with_background")
        os.mkdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY +
                 "/modular_single_targets_with_background_answers")

        cpu_count = multiprocessing.cpu_count()
        pics_per_process = (number_of_single_targets_with_background /
                            cpu_count) + 1
        start_time = timeit.default_timer()

        jobs = []
        for index in range(cpu_count):
            starting_index = index * int(pics_per_process)
            image_generation_process = multiprocessing.Process(
                target=ModularSyntheticDatasetMaker.
                run_modular_single_targets_with_background_generator,
                args=(pics_per_process, starting_index))
            jobs.append(image_generation_process)
            image_generation_process.start()

        for job in jobs:
            job.join()

        Logger.log("Modular Single Targets With Background saved at: " +
                   Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY +
                   "/modular_single_targets_with_background")
        Logger.log(
            "Modular Single Targets With Background Answers saved at: " +
            Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY +
            "/modular_single_targets_with_background_answers\n")

        print("====================================")
        print(
            "Total number of modular single targets with background generated:",
            len(
                os.listdir(Settings.SAVE_PATH + Settings.ANSWERS_DIRECTORY +
                           "/modular_single_targets_with_background")))
        print("Total elapsed time (sec):", timeit.default_timer() - start_time)
        print("====================================")
Beispiel #3
0
 def run_modular_target_maps_generator(number_of_target_maps,
                                       number_of_targets_on_each_map,
                                       process_number):
     for index in range(number_of_target_maps):
         target_map = ModularTargetMap(number_of_targets_on_each_map)
         target_map.create_modular_target_map()
         Logger.log("Current process: " +
                    str((process_number / number_of_target_maps) + 1) +
                    "\n")
         target_map.record_modular_target_map(process_number + index + 1)
Beispiel #4
0
 def run_modular_single_targets_with_background_generator(
         number_of_single_targets_with_background, process_number):
     for index in range(number_of_single_targets_with_background):
         single_target = ModularTargetWithBackground()
         single_target.create_modular_target_with_background()
         Logger.log("Current process: " +
                    str((process_number /
                         number_of_single_targets_with_background) + 1) +
                    "\n")
         single_target.record_modular_target_with_background(
             process_number + index + 1)
    def create_specified_target_with_background(self):
        resized_target_image = self.target_image.resize((self.new_target_width, self.new_target_height))
        self.background = BackgroundGenerator(Settings.BACKGROUND_DIRECTORY_PATH).generate_specific_background(resized_target_image.width + 20, resized_target_image.height + 20)
        self.background.paste(resized_target_image, (10, 10), resized_target_image)

        Logger.log("Target's Dimension in pixels: " + str(self.new_target_dimension + 20)
                   + "\nTarget's Dimension in inches: " + str(float(self.new_target_dimension + 20) / Settings.PPSI)
                   + "\nshape_type: " + self.shape_type
                   + "\nshape_color: (" + str(self.shape_color[0]) + ", " + str(self.shape_color[1]) + ", " + str(self.shape_color[2]) + ")"
                   + "\nalphanumeric_value: " + self.letter
                   + "\nalphanumeric_color: (" + str(self.letter_color[0]) + ", " + str(self.letter_color[1]) + ", " + str(self.letter_color[2]) + ")"
                   + "\norientation in degree from north: " + str(self.rotation)
                   + "\ncardinal orientation: " + CardinalDirectionConverter.convert_to_cardinal_direction(self.rotation)
                   + "\ntarget_center_coordinates: " + str(10+(self.new_target_width / 2)) + ", " + str(10 + (self.new_target_height / 2)) + "\n")

        return self.background
 def run_modular_target_maps_generator(number_of_target_maps, number_of_targets_on_each_map, process_number):
     for index in range(number_of_target_maps):
         target_map = ModularTargetMap(number_of_targets_on_each_map)
         target_map.create_modular_target_map()
         Logger.log("Current process: " + str((process_number / number_of_target_maps) + 1) + "\n")
         target_map.record_modular_target_map(process_number + index + 1)
 def run_modular_single_targets_with_background_generator(number_of_single_targets_with_background, process_number):
     for index in range(number_of_single_targets_with_background):
         single_target = ModularTargetWithBackground()
         single_target.create_modular_target_with_background()
         Logger.log("Current process: " + str((process_number / number_of_single_targets_with_background) + 1) + "\n")
         single_target.record_modular_target_with_background(process_number + index + 1)
    def create_modular_target_map(self):
        """
        Create a map with a specified number of modular targets.

        1. Pick an image from path_to_backgrounds as the background.
        2. Generate a modular target.
        3. Pick a random location for the target.
        4. With a list of the ranges of previously generated targets,
           Check if the random location overlaps with other targets.
           If so, pick another random location until the newly generated
           location does not overlap or the number of attempts runs out.
           If the attempts runs out, give up on that round.
        5. Store the range of the confirmed modular target into the list.
        6. Continue to generate targets until the number of modular targets
           is reached. The given-up rounds are counted.
        7. Output the actually targets created and the background itself.
        """
        occupied_spaces = []
        index_number_of_targets = 1

        while index_number_of_targets <= self.number_of_targets:

            modular_target = ModularTarget()

            raw_target_image = modular_target.create_modular_target()
            new_target_dimension = random.randint(Settings.TARGET_SIZE_RANGE_IN_PIXELS[0], Settings.TARGET_SIZE_RANGE_IN_PIXELS[1])

            if raw_target_image.width >= raw_target_image.height:
                new_target_width = new_target_dimension
                new_target_height = new_target_dimension * raw_target_image.height / raw_target_image.width
            else:
                new_target_height = new_target_dimension
                new_target_width = new_target_dimension * raw_target_image.width / raw_target_image.height

            target_image = raw_target_image.resize((new_target_width, new_target_height))

            reroll_needed = True
            attempts_to_reroll = 0

            while reroll_needed == True and attempts_to_reroll < 5:
                reroll_needed = False
                random_x_initial = random.randint(10, self.background.width - target_image.width - 10) - 10
                random_y_initial = random.randint(10, self.background.height - target_image.height - 10) - 10
                random_x_final = random_x_initial + target_image.width + 10
                random_y_final = random_y_initial + target_image.height + 10
                x_taking = [random_x_initial, random_x_final]
                y_taking = [random_y_initial, random_y_final]

                if len(occupied_spaces) > 0:
                    for index_1 in range(0, len(occupied_spaces)):
                        if (x_taking[0] >= occupied_spaces[index_1][0]) and (x_taking[0] <= occupied_spaces[index_1][2]):
                            if (y_taking[0] >= occupied_spaces[index_1][1]) and (y_taking[0] <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height / 4)) >= occupied_spaces[index_1][1]) and ((y_taking[0] + (target_image.height / 4)) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (((y_taking[0] + y_taking[1]) / 2) >= occupied_spaces[index_1][1]) and (((y_taking[0] + y_taking[1]) / 2) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height * 3 / 4)) >= occupied_spaces[index_1][1]) and ((y_taking[0] + (target_image.height * 3 / 4)) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (y_taking[1] >= occupied_spaces[index_1][1]) and (y_taking[1] <= occupied_spaces[index_1][3]):
                                reroll_needed = True

                        if ((x_taking[0] + (target_image.width / 4)) >= occupied_spaces[index_1][0]) and ((x_taking[0] + (target_image.width / 4)) <= occupied_spaces[index_1][2]):
                            if (y_taking[0] >= occupied_spaces[index_1][1]) and (y_taking[0] <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height / 4)) >= occupied_spaces[index_1][1]) and ((y_taking[0] + (target_image.height / 4)) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (((y_taking[0] + y_taking[1]) / 2) >= occupied_spaces[index_1][1]) and (((y_taking[0] + y_taking[1]) / 2) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height * 3 / 4)) >= occupied_spaces[index_1][1]) and ((y_taking[0] + (target_image.height * 3 / 4)) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (y_taking[1] >= occupied_spaces[index_1][1]) and (y_taking[1] <= occupied_spaces[index_1][3]):
                                reroll_needed = True

                        if (((x_taking[0] + x_taking[1]) / 2) >= occupied_spaces[index_1][0]) and (((x_taking[0] + x_taking[1]) / 2) <= occupied_spaces[index_1][2]):
                            if (y_taking[0] >= occupied_spaces[index_1][1]) and (y_taking[0] <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height / 4)) >= occupied_spaces[index_1][1]) and ((y_taking[0] + (target_image.height / 4)) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (((y_taking[0] + y_taking[1]) / 2) >= occupied_spaces[index_1][1]) and (((y_taking[0] + y_taking[1]) / 2) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height * 3 / 4)) >= occupied_spaces[index_1][1]) and ((y_taking[0] + (target_image.height * 3 / 4)) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (y_taking[1] >= occupied_spaces[index_1][1]) and (y_taking[1] <= occupied_spaces[index_1][3]):
                                reroll_needed = True

                        if ((x_taking[0] + (target_image.width * 3 / 4)) >= occupied_spaces[index_1][0]) and ((x_taking[0] + (target_image.width * 3 / 4)) <= occupied_spaces[index_1][2]):
                            if (y_taking[0] >= occupied_spaces[index_1][1]) and (y_taking[0] <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height / 4)) >= occupied_spaces[index_1][1]) and ((y_taking[0] + (target_image.height / 4)) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (((y_taking[0] + y_taking[1]) / 2) >= occupied_spaces[index_1][1]) and (((y_taking[0] + y_taking[1]) / 2) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height * 3 / 4)) >= occupied_spaces[index_1][1]) and ((y_taking[0] + (target_image.height * 3 / 4)) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (y_taking[1] >= occupied_spaces[index_1][1]) and (y_taking[1] <= occupied_spaces[index_1][3]):
                                reroll_needed = True

                        if (x_taking[1] >= occupied_spaces[index_1][0]) and (x_taking[1] <= occupied_spaces[index_1][2]):
                            if (y_taking[0] >= occupied_spaces[index_1][1]) and (y_taking[0] <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height / 4)) >= occupied_spaces[index_1][1]) and ((y_taking[0] + (target_image.height / 4)) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (((y_taking[0] + y_taking[1]) / 2) >= occupied_spaces[index_1][1]) and (((y_taking[0] + y_taking[1]) / 2) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height * 3 / 4)) >= occupied_spaces[index_1][1]) and ((y_taking[0] + (target_image.height * 3 / 4)) <= occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (y_taking[1] >= occupied_spaces[index_1][1]) and (y_taking[1] <= occupied_spaces[index_1][3]):
                                reroll_needed = True

                attempts_to_reroll = attempts_to_reroll + 1

            if reroll_needed == False:

                occupied_spaces.append([random_x_initial - 10, random_y_initial - 10, random_x_final + 10, random_y_final + 10])
                self.target_list.append([modular_target, (random_x_initial + random_x_final)/2, (random_y_initial + random_y_final)/2])

                self.background.paste(target_image, (random_x_initial, random_y_initial), target_image)
                index_number_of_targets = index_number_of_targets + 1
                self.total_targets_output = self.total_targets_output + 1
            else:
                index_number_of_targets = index_number_of_targets + 1

        if self.total_targets_output < self.number_of_targets:
            Logger.log("Total Number of Actual Target Output: " + str(self.total_targets_output) + "\n"
                       + "The background is not able to contain the number of targets requested." + "\n")
        else:
            Logger.log("Total Number of Actual Target Output: " + str(self.total_targets_output) + "\n")

        return self.total_targets_output
Beispiel #9
0
    def create_modular_target_map(self):
        """
        Create a map with a specified number of modular targets.

        1. Pick an image from path_to_backgrounds as the background.
        2. Generate a modular target.
        3. Pick a random location for the target.
        4. With a list of the ranges of previously generated targets,
           Check if the random location overlaps with other targets.
           If so, pick another random location until the newly generated
           location does not overlap or the number of attempts runs out.
           If the attempts runs out, give up on that round.
        5. Store the range of the confirmed modular target into the list.
        6. Continue to generate targets until the number of modular targets
           is reached. The given-up rounds are counted.
        7. Output the actually targets created and the background itself.
        """
        occupied_spaces = []
        index_number_of_targets = 1

        while index_number_of_targets <= self.number_of_targets:

            modular_target = ModularTarget()

            raw_target_image = modular_target.create_modular_target()
            new_target_dimension = random.randint(
                Settings.TARGET_SIZE_RANGE_IN_PIXELS[0],
                Settings.TARGET_SIZE_RANGE_IN_PIXELS[1])

            if raw_target_image.width >= raw_target_image.height:
                new_target_width = new_target_dimension
                new_target_height = new_target_dimension * raw_target_image.height / raw_target_image.width
            else:
                new_target_height = new_target_dimension
                new_target_width = new_target_dimension * raw_target_image.width / raw_target_image.height

            target_image = raw_target_image.resize(
                (new_target_width, new_target_height))

            reroll_needed = True
            attempts_to_reroll = 0

            while reroll_needed == True and attempts_to_reroll < 5:
                reroll_needed = False
                random_x_initial = random.randint(
                    10, self.background.width - target_image.width - 10) - 10
                random_y_initial = random.randint(
                    10, self.background.height - target_image.height - 10) - 10
                random_x_final = random_x_initial + target_image.width + 10
                random_y_final = random_y_initial + target_image.height + 10
                x_taking = [random_x_initial, random_x_final]
                y_taking = [random_y_initial, random_y_final]

                if len(occupied_spaces) > 0:
                    for index_1 in range(0, len(occupied_spaces)):
                        if (x_taking[0] >= occupied_spaces[index_1][0]) and (
                                x_taking[0] <= occupied_spaces[index_1][2]):
                            if (y_taking[0] >= occupied_spaces[index_1][1]
                                ) and (y_taking[0] <=
                                       occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height / 4)) >=
                                    occupied_spaces[index_1][1]) and (
                                        (y_taking[0] +
                                         (target_image.height / 4)) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (((y_taking[0] + y_taking[1]) / 2) >=
                                    occupied_spaces[index_1][1]) and (
                                        ((y_taking[0] + y_taking[1]) / 2) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height * 3 / 4))
                                    >= occupied_spaces[index_1][1]) and (
                                        (y_taking[0] +
                                         (target_image.height * 3 / 4)) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (y_taking[1] >= occupied_spaces[index_1][1]
                                ) and (y_taking[1] <=
                                       occupied_spaces[index_1][3]):
                                reroll_needed = True

                        if ((x_taking[0] + (target_image.width / 4)) >=
                                occupied_spaces[index_1][0]) and (
                                    (x_taking[0] + (target_image.width / 4)) <=
                                    occupied_spaces[index_1][2]):
                            if (y_taking[0] >= occupied_spaces[index_1][1]
                                ) and (y_taking[0] <=
                                       occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height / 4)) >=
                                    occupied_spaces[index_1][1]) and (
                                        (y_taking[0] +
                                         (target_image.height / 4)) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (((y_taking[0] + y_taking[1]) / 2) >=
                                    occupied_spaces[index_1][1]) and (
                                        ((y_taking[0] + y_taking[1]) / 2) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height * 3 / 4))
                                    >= occupied_spaces[index_1][1]) and (
                                        (y_taking[0] +
                                         (target_image.height * 3 / 4)) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (y_taking[1] >= occupied_spaces[index_1][1]
                                ) and (y_taking[1] <=
                                       occupied_spaces[index_1][3]):
                                reroll_needed = True

                        if (((x_taking[0] + x_taking[1]) / 2) >=
                                occupied_spaces[index_1][0]) and (
                                    ((x_taking[0] + x_taking[1]) / 2) <=
                                    occupied_spaces[index_1][2]):
                            if (y_taking[0] >= occupied_spaces[index_1][1]
                                ) and (y_taking[0] <=
                                       occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height / 4)) >=
                                    occupied_spaces[index_1][1]) and (
                                        (y_taking[0] +
                                         (target_image.height / 4)) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (((y_taking[0] + y_taking[1]) / 2) >=
                                    occupied_spaces[index_1][1]) and (
                                        ((y_taking[0] + y_taking[1]) / 2) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height * 3 / 4))
                                    >= occupied_spaces[index_1][1]) and (
                                        (y_taking[0] +
                                         (target_image.height * 3 / 4)) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (y_taking[1] >= occupied_spaces[index_1][1]
                                ) and (y_taking[1] <=
                                       occupied_spaces[index_1][3]):
                                reroll_needed = True

                        if ((x_taking[0] + (target_image.width * 3 / 4)) >=
                                occupied_spaces[index_1][0]) and (
                                    (x_taking[0] +
                                     (target_image.width * 3 / 4)) <=
                                    occupied_spaces[index_1][2]):
                            if (y_taking[0] >= occupied_spaces[index_1][1]
                                ) and (y_taking[0] <=
                                       occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height / 4)) >=
                                    occupied_spaces[index_1][1]) and (
                                        (y_taking[0] +
                                         (target_image.height / 4)) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (((y_taking[0] + y_taking[1]) / 2) >=
                                    occupied_spaces[index_1][1]) and (
                                        ((y_taking[0] + y_taking[1]) / 2) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height * 3 / 4))
                                    >= occupied_spaces[index_1][1]) and (
                                        (y_taking[0] +
                                         (target_image.height * 3 / 4)) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (y_taking[1] >= occupied_spaces[index_1][1]
                                ) and (y_taking[1] <=
                                       occupied_spaces[index_1][3]):
                                reroll_needed = True

                        if (x_taking[1] >= occupied_spaces[index_1][0]) and (
                                x_taking[1] <= occupied_spaces[index_1][2]):
                            if (y_taking[0] >= occupied_spaces[index_1][1]
                                ) and (y_taking[0] <=
                                       occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height / 4)) >=
                                    occupied_spaces[index_1][1]) and (
                                        (y_taking[0] +
                                         (target_image.height / 4)) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (((y_taking[0] + y_taking[1]) / 2) >=
                                    occupied_spaces[index_1][1]) and (
                                        ((y_taking[0] + y_taking[1]) / 2) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if ((y_taking[0] + (target_image.height * 3 / 4))
                                    >= occupied_spaces[index_1][1]) and (
                                        (y_taking[0] +
                                         (target_image.height * 3 / 4)) <=
                                        occupied_spaces[index_1][3]):
                                reroll_needed = True
                            if (y_taking[1] >= occupied_spaces[index_1][1]
                                ) and (y_taking[1] <=
                                       occupied_spaces[index_1][3]):
                                reroll_needed = True

                attempts_to_reroll = attempts_to_reroll + 1

            if reroll_needed == False:

                occupied_spaces.append([
                    random_x_initial - 10, random_y_initial - 10,
                    random_x_final + 10, random_y_final + 10
                ])
                self.target_list.append([
                    modular_target, (random_x_initial + random_x_final) / 2,
                    (random_y_initial + random_y_final) / 2
                ])

                self.background.paste(target_image,
                                      (random_x_initial, random_y_initial),
                                      target_image)
                index_number_of_targets = index_number_of_targets + 1
                self.total_targets_output = self.total_targets_output + 1
            else:
                index_number_of_targets = index_number_of_targets + 1

        if self.total_targets_output < self.number_of_targets:
            Logger.log(
                "Total Number of Actual Target Output: " +
                str(self.total_targets_output) + "\n" +
                "The background is not able to contain the number of targets requested."
                + "\n")
        else:
            Logger.log("Total Number of Actual Target Output: " +
                       str(self.total_targets_output) + "\n")

        return self.total_targets_output