Open nalmadi opened 3 years ago
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, color = 'black',pbgc = 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.
color: python color value
Allows user to customize image background color; defaulted to black
pbgc(preferred bg color): python color value:
allows trial drwing to be set to custom bg color, defaulted to scanned 2nd pixel if still none on function call
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= color)
*_, width, _ = im.getbbox()
# offset = int((1024 - width) / 2) - 10
trial_location = (10, 375)
background.paste(im, trial_location, im.convert('RGBA'))
im = background.copy()
if pbgc == None:
bg_color = find_background_color(im.copy().convert('1'))
else:
bg_color = pbgc
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!")
Thanks @jhimel22 You should create a pull request for this, if possible.
Since multiple classes are being merged into one, the implementation of the draw_trial should not make assumptions about the specific trial it is drawing. Initially we wanted to create a unified visualization style, but that might not work for every trial since variations in background colors and style are possible. Instead, we want the draw_trial method to allow the user to customize the visualization with various color and style options.