'Clips results of attack and copy it to directory with all images.
Args:
attack_name: name of the attack.
is_targeted: if True then attack is targeted, otherwise non-targeted.'

def clip_and_copy_attack_outputs(self, attack_name, is_targeted):

    if is_targeted:
        self._targeted_attack_names.add(attack_name)
    else:
        self._attack_names.add(attack_name)
    attack_dir = os.path.join((self.targeted_attacks_output_dir if is_targeted else self.attacks_output_dir), attack_name)
    for fname in os.listdir(attack_dir):
        if (not (fname.endswith('.png') or fname.endswith('.jpg'))):
            continue
        image_id = fname[:(-4)]
        if (image_id not in self.dataset_max_clip):
            continue
        image_max_clip = self.dataset_max_clip[image_id]
        image_min_clip = self.dataset_min_clip[image_id]
        adversarial_image = np.array(Image.open(os.path.join(attack_dir, fname)).convert('RGB'))
        clipped_adv_image = np.clip(adversarial_image, image_min_clip, image_max_clip)
        output_basename = '{0:08d}'.format(self._output_image_idx)
        self._output_image_idx += 1
        self._output_to_attack_mapping[output_basename] = (attack_name, is_targeted, image_id)
        if is_targeted:
            self._targeted_attack_image_count += 1
        else:
            self._attack_image_count += 1
        Image.fromarray(clipped_adv_image).save(os.path.join(self.all_adv_examples_dir, (output_basename + '.png')))
