Ejemplo n.º 1
0
def _place_on_screen(stimuli_identifier: str,
                     stimulus_set: StimulusSet,
                     target_visual_degrees: int,
                     source_visual_degrees: int = None):
    converted_stimuli_id = f"{stimuli_identifier}--target{target_visual_degrees}--source{source_visual_degrees}"
    source_visual_degrees = _determine_visual_degrees(source_visual_degrees,
                                                      stimulus_set)

    target_dir = root_path / converted_stimuli_id
    target_dir.mkdir(parents=True, exist_ok=False)
    image_converter = ImageConverter(target_dir=target_dir)

    converted_image_paths = {}
    for image_id, image_degrees in tqdm(zip(stimulus_set['image_id'],
                                            source_visual_degrees),
                                        total=len(stimulus_set),
                                        desc='convert image degrees'):
        converted_image_path = image_converter.convert_image(
            image_path=stimulus_set.get_image(image_id),
            source_degrees=image_degrees,
            target_degrees=target_visual_degrees)
        converted_image_paths[image_id] = converted_image_path
    converted_stimuli = StimulusSet(stimulus_set.copy(
        deep=True))  # without copy, it will link to the previous stim set
    converted_stimuli.image_paths = converted_image_paths
    converted_stimuli.identifier = converted_stimuli_id
    converted_stimuli['degrees'] = target_visual_degrees
    converted_stimuli.original_paths = copy.deepcopy(stimulus_set.image_paths)
    return converted_stimuli
Ejemplo n.º 2
0
 def __call__(self, stimuli):
     target_dir = os.path.join(
         self._directory, stimuli.name,
         f"target_{self.target_degrees}deg_{self.target_pixels}pix")
     os.makedirs(target_dir, exist_ok=True)
     image_paths = {
         image_id: self.convert_image(stimuli.get_image(image_id),
                                      image_degrees=degrees,
                                      target_dir=target_dir)
         for image_id, degrees in zip(stimuli['image_id'],
                                      stimuli['degrees'])
     }
     converted_stimuli = StimulusSet(
         stimuli
     )  # .copy() for some reason keeps the link to the old metadata
     converted_stimuli.name = f"{stimuli.name}-{self.target_degrees}degrees_{self.target_pixels}"
     converted_stimuli['degrees'] = self.target_degrees
     converted_stimuli.image_paths = image_paths
     converted_stimuli.original_paths = {
         converted_stimuli.image_paths[image_id]:
         stimuli.image_paths[image_id]
         for image_id in stimuli['image_id']
     }
     return converted_stimuli