Heatmap with datagaze
in PyGaze
Hi guys, im having problem with the code for generating heatmap
def draw_heatmap(fixations, dispsize, imagefile=None, durationweight=True, alpha=0.5, savefilename=None): # FIXATIONS fix = parse_fixations(fixations) # IMAGE fig, ax = draw_display(dispsize, imagefile=imagefile) # HEATMAP # Gaussian gwh = 200 gsdwh = gwh/6 gaus = gaussian(gwh,gsdwh) # matrix of zeroes strt = gwh/2 heatmapsize = dispsize[1] + 2*strt, dispsize[0] + 2*strt heatmap = numpy.zeros(heatmapsize, dtype=float) # create heatmap for i in range(0,len(fix['dur'])): # get x and y coordinates #x and y - indexes of heatmap array. must be integers x = strt + int(fix['x'][i]) - int(gwh/2) y = strt + int(fix['y'][i]) - int(gwh/2) # correct Gaussian size if either coordinate falls outside of # display boundaries if (not 0 < x < dispsize[0]) or (not 0 < y < dispsize[1]): hadj=[0,gwh];vadj=[0,gwh] if 0 > x: hadj[0] = abs(x) x = 0 elif dispsize[0] < x: hadj[1] = gwh - int(x-dispsize[0]) if 0 > y: vadj[0] = abs(y) y = 0 elif dispsize[1] < y: vadj[1] = gwh - int(y-dispsize[1]) # add adjusted Gaussian to the current heatmap try: heatmap[y:y+vadj[1],x:x+hadj[1]] += gaus[vadj[0]:vadj[1],hadj[0]:hadj[1]] * fix['dur'][i] except: # fixation was probably outside of display pass else: # add Gaussian to the current heatmap heatmap[y:y+gwh,x:x+gwh] += gaus * fix['dur'][i] # resize heatmap heatmap = heatmap[strt:dispsize[1]+strt,strt:dispsize[0]+strt] # remove zeros lowbound = numpy.mean(heatmap[heatmap>0]) heatmap[heatmap<lowbound] = numpy.NaN # draw heatmap on top of image ax.imshow(heatmap, cmap='jet', alpha=alpha) # FINISH PLOT # invert the y axis, as (0,0) is top left on a display ax.invert_yaxis() # save the figure if a file name was provided if savefilename != None: fig.savefig(savefilename) return fig
I don't understand variables 'gwh' , 'gsdwh', 'strt' , 'hadj', 'vadj' stand for. Why we need to use them
Thanks in advance
Comments
Hi,
Can you share the link to the script that uses that function? Then I can try to figure out what they do based on the context. My guess is that
gwhandgwsdhare needed to define a Gaussian kernel.strtis needed to extract the gaussian in one dimension, andhadjandvadjstand for horizontal and vertical adjustment, and are mark the border of the Gaussian in pixel coordinates.But as I said, if you share the script, I can try to give more detailed answeres.
Eduard