|
def draw_trial(self, image_path, draw_raw_data=False, draw_fixation=True, draw_saccade=False, draw_number=False, |
|
draw_aoi=None, save_image=None): |
|
"""Draws the trial image and raw-data/fixations over the image |
|
circle size indicates fixation duration |
|
|
|
image_path : str |
|
path for trial image file. |
|
|
|
draw_raw_data : bool, optional |
|
whether user wants raw data drawn. |
|
|
|
draw_fixation : bool, optional |
|
whether user wants filtered fixations drawn |
|
|
|
draw_saccade : bool, optional |
|
whether user wants saccades drawn |
|
|
|
draw_number : bool, optional |
|
whether user wants to draw eye movement number |
|
|
|
draw_aoi : pandas.DataFrame, optional |
|
Area of Interests |
|
|
|
save_image : str, optional |
|
path to save the image, image is saved to this path if it parameter exists |
|
""" |
|
|
|
im = Image.open(image_path + self.image) |
|
|
|
if self.eye_tracker == "EyeLink1000": |
|
|
|
background_size = (1024, 768) |
|
background = Image.new('RGB', background_size, color='black') |
|
|
|
*_, width, _ = im.getbbox() |
|
# offset = int((1024 - width) / 2) - 10 |
|
trial_location = (10, 375) |
|
|
|
background.paste(im, trial_location, im.convert('RGBA')) |
|
|
|
im = background.copy() |
|
|
|
|
|
bg_color = find_background_color(im.copy().convert('1')) |
|
|
|
draw = ImageDraw.Draw(im, 'RGBA') |
|
|
|
if draw_aoi and isinstance(draw_aoi, bool): |
|
aoi = find_aoi(image=self.image, img=im) |
|
self.__draw_aoi(draw, aoi, bg_color) |
|
|
|
if isinstance(draw_aoi, pd.DataFrame): |
|
self.__draw_aoi(draw, draw_aoi, bg_color) |
|
|
|
if draw_raw_data: |
|
self.__draw_raw_data(draw) |
|
|
|
if draw_fixation: |
|
self.__draw_fixation(draw, draw_number) |
|
|
|
if draw_saccade: |
|
self.__draw_saccade(draw, draw_number) |
|
|
|
plt.figure(figsize=(17, 15)) |
|
plt.imshow(np.asarray(im), interpolation='nearest') |
|
|
|
if save_image is not None: |
|
# Save the image with applied offset |
|
|
|
image_name = save_image + \ |
|
str(self.participant_id) + \ |
|
"-t" + \ |
|
str(self.trial_id) + \ |
|
"-offsetx" + \ |
|
str(self.get_offset()[0]) + \ |
|
"y" + \ |
|
str(self.get_offset()[1]) + \ |
|
".png" |
|
|
|
plt.savefig(image_name) |
|
|
|
print(image_name, "saved!") |