Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] PygazeAnalyser: Drawing Heatmaps, Scanpaths etc

edited January 2015 in PyGaze

Hi Edwin,

I am currently trying to draw some graphical analyses.
It did not work with 32 bit images but reducing to 24 bit helped when trying to draw heatmaps.
Nevertheless the heatmap was not drawn onto the image but saved in a file with black background.
Same accounts for scanpath and fixations. Images with black backgrounds were produced but also something that looked like a memory allocation error:

alloc: invalid block: 03F6AE90: 90 4

Btw I do also get a warning because the font family 'Ubuntu' is not recognized by windoze :-)

Here's how I try to use the stuff:

readFile = easygui.fileopenbox(msg="Bitte wählen Sie die zu öffnende Datei", filetypes=["*.tsv"])<br>theData = er.read_eyetribe(readFile, "start_trial", "stop_trial", debug=True).
...
fixations = theData[0]['events']['Efix']  # [starttime, endtime, duration, endx, endy]
saccades = theData[0]['events']['Esac']
display = [1036, 812]
imageFile = "somePath"

gp.draw_heatmap(fixations, dispsize=display, imagefile=imageFile, durationweight=True, alpha=0.5, savefilename="saveFilePath")

gp.draw_scanpath(fixations, saccades, dispsize=display, imagefile=imageFile, alpha = 0.5, savefilename = "saveFilePath2")

gp.draw_fixations(fixations, dispsize=display, imagefile=imageFile, durationsize=True, durationcolour=False, alpha=0.5,savefilename="saveFilePath3")

I'd appreciate any hint :-)
Here come the images

source image

image

heatmap

image

scanpath

image

fixations

image

Best regards
Digo

Comments

  • edited 9:33AM

    Thanks for the feedback! Nice to see people using this :)

    In my experience, not all image types are loaded properly. I think JPEGs work best. Could you convert your images?

    As an aside: You could simply install the Ubuntu font, but it's not a requirement. If matplotlib can't find Ubuntu, it will simply revert back to the default option.

    Good luck!

    Edwin

  • edited January 2015

    Thank you so much!
    Having the images converted to .jpg I got all three visualizations working. Note that it was necessary to install Pillow ( see http://stackoverflow.com/questions/24356421/attributeerror-builtin-function-or-method-object-has-no-attribute-iterkeys ). Otherwise I got the error
    AttributeError: 'builtin_function_or_method' object has no attribute 'iterkeys'

    So I am getting very close now. Results look fine except scanpaths which always start at 0/0 (see image). Unfortunately the program crashes with something that looks like a memory allocation error when trying to terminate after using either draw_scanpath or draw_fixations (draw_heatmap does not produce this error).

    alloc: invalid block: 03E55CD8: 58 3

    Btw. I installed the Ubuntu font, but it still isn't recognized.

    Best regards
    Digo


    image

  • edited January 2015

    Hi Digo,

    Thanks for the feedback! I wasn't aware of the matplotlib issue you mention. Did you not have PIL installed, or was Pillow required nonetheless?

    The (0,0) points (top left) are missing data, which is not filtered by the saccade algorithm. And, actually, I rethought the way I construct those scanpaths. They don't really require saccades at all, the fixations alone should be enough. I'll try to reprogram some stuff over the weekend.

    The memory error is probably related to matplotlib. Have you tried closing the figures after creating them? (bottom line of the example below)

    # ...continued from your script above
    
    from matplotlib import pyplot
    
    # fill out your own path
    saveFilePath = "/YOUR/PATH/HERE"
    
    # create a new heatmap
    fig, axes = gp.draw_heatmap(fixations, dispsize=display, imagefile=imageFile, durationweight=True, alpha=0.5, savefilename=saveFilePath)
    
    # add a watermark
    axes.annotate("created using PyGazeAnalyser", (0,0), fontsize=24, color='white', alpha=0.5)
    
    # save your creation
    fig.savefig(saveFilePath)
    
    # close the figure
    pyplot.close(fig)
    

    The Figure and associated Axes instances are native to matplotlib. They are returned so you can do some further image manipulation (annotate texts, add an axis, set a title etc.) by using matplotlib functions. This also means you might want to actively close them afterwards. See the example above for practical info.

    Cheers,
    Edwin

  • edited 9:33AM

    Hi Edwin,

    thanks again. Closing the fig helps! If I got that right it is done using pyplot since figure doesn't have a closing routine:


    import matplotlib.pyplot as plt

    ...

    fig = gp.draw_fixations(fixations, dispsize=display, imagefile=imageFile, durationsize=True, durationcolour=False, alpha=0.5,
    savefilename="saveFilePath")

    plt.close(fig)



    Best regards

    Digo

  • edited 9:33AM

    Apologies, you are completely right! I've updated my post.

    Glad the closing helped solve part of your issue, though! Am still working on the other bit.

Sign In or Register to comment.