Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Making a heat map for eye tracking data

1,119 views
Skip to first unread message

Hugh Thompson

unread,
Feb 15, 2011, 3:34:03 PM2/15/11
to
Hello,

I'm using an eye tracker to get point of gaze coordinates on an image. I've found fixation dwells and stuff like that, but I'm really interested in creating a heat map.

So basically, I have this bunch of coordinates that correspond to where the participant is looking at in the image. I can plot all the coordinates on the image, but that is really confusing, what I want to do is show the areas of high and low density using different colors, as is typically done for eye tracking data (see the image here for example http://b2bleadblog.com/2005/02/landing_page_ha_1.html).

I'm not exactly sure what would be the best way to determine the density of pixels in an image region. I've read about regionprops, but from what I understood that only works for binary images. Also, I don't want to do this for an image, rather a set of pixels plotted on an image. I'm also not sure how I can display the results so that it is semi-transparent as in the link here. The heat map function in matlab does not seem to relate to what I want to do at all.

Any help about what functions I could use or at what I should be looking at would be much appreciated!

Hugh

Ashish Uthama

unread,
Feb 16, 2011, 11:08:41 AM2/16/11
to
Hugh,

Could you say more about the data you have?

Are these just a set of X-Y coordinate? Or do you have X-Y coordinates
with another value associated with it? (Perhaps the mean amount of time
on that point?).

If its just coordinates, then you could define the heat value of each
pixel as the number of cooridnates/hits in a NxN block in its vicinity.
You could use NLFILTER or code a nested FOR loop.


For transparency, you could use multiple approaches:
http://blogs.mathworks.com/steve/2009/02/18/image-overlay-using-transparency/
http://www.mathworks.com/help/techdoc/visualize/f3-6010.html

Oliver Woodford

unread,
Feb 16, 2011, 12:56:04 PM2/16/11
to

Hi Hugh

The first thing you want to do is create a gaze density image from your gaze points. This image should be the same resolution as the image you want to lay it over. This process is called kernel density estimation. You'd probably choose a gaussian kernel. This might do the trick:
http://www.mathworks.com/matlabcentral/fileexchange/19280-bivariant-kernel-density-estimation-v2-0

Then you want to combine this density image (density) with your image (im), and pass it to SC for rendering, thus:

sc(cat(3, density, im), 'prob');

To save the output you just do:

A = sc(cat(3, density, im), 'prob');
imwrite(A, 'output.png');

There is another colormap called prob_jet which you could also try:

sc(cat(3, density, im), 'prob_jet');

SC can be dowloaded here:
http://www.mathworks.com/matlabcentral/fileexchange/16233-sc-powerful-image-rendering

HTH,
Oliver

Hugh Thompson

unread,
Feb 16, 2011, 10:38:03 PM2/16/11
to
Thank you Ashish and Oliver. I believe this is exactly what I need!

Thanks again,
Hugh

"Oliver Woodford" wrote in message <ijh33k$nm5$1...@fred.mathworks.com>...

Hugh Thompson

unread,
Feb 17, 2011, 11:47:05 AM2/17/11
to
Oliver?

Things seem to be working very well with the code you suggested. What I've done so far is

%this gets the x and y coordinates of the eye tracking data
[new_image_coor_horz new_image_coor_vert] = EyetrackerPlotGazeCoor(excelFile, rangeTF, rangeCoor, maxValue, image)

%I concatenated the coordinates so they become an nx2 array
coordinates = horzcat(new_image_coor_horz, new_image_coor_vert);

p = gkde2(coordinates);

%this is the picture I want to overlay the heat map on
im = imread('pic_good.png');

A = sc(cat(3, p.pdf, im), 'prob');

I get the error in the last line, and I understand why but I don't know how to fix it. Cat won't work since p.pdf is 50x50 and my image is 454x1072x3. You mentioned before that the density should be the same resolution as the image I want to lay it over, but how would I modify this code to make that happen? Or am I completely missing something here?

Many thanks once more,
Hugh

"Hugh Thompson" wrote in message <iji56r$jvf$1...@fred.mathworks.com>...

Oliver Woodford

unread,
Feb 17, 2011, 1:11:04 PM2/17/11
to
"Hugh Thompson" wrote:
> Oliver?
>
> Things seem to be working very well with the code you suggested. What I've done so far is
>
> %this gets the x and y coordinates of the eye tracking data
> [new_image_coor_horz new_image_coor_vert] = EyetrackerPlotGazeCoor(excelFile, rangeTF, rangeCoor, maxValue, image)
>
> %I concatenated the coordinates so they become an nx2 array
> coordinates = horzcat(new_image_coor_horz, new_image_coor_vert);
>
> p = gkde2(coordinates);
>
> %this is the picture I want to overlay the heat map on
> im = imread('pic_good.png');
>
> A = sc(cat(3, p.pdf, im), 'prob');
>
> I get the error in the last line, and I understand why but I don't know how to fix it. Cat won't work since p.pdf is 50x50 and my image is 454x1072x3. You mentioned before that the density should be the same resolution as the image I want to lay it over, but how would I modify this code to make that happen? Or am I completely missing something here?
>
> Many thanks once more,
> Hugh

Hi Hugh

Your question is essentially: How do I call the following

p = gkde2(coordinates);

such that p.pdf is a 454 x 1072 matrix?

Well, I have no idea because I didn't write and have never used gkde2. I thought it might be helpful to you, and it seems to be. Perhaps someone else will know the answer. Or perhaps you can read the help text (if there is any) to see what options you might set, or even look at the code.

Best,
Oliver

Surashree

unread,
Mar 27, 2013, 2:24:18 AM3/27/13
to
"Hugh Thompson" wrote in message <ijenvr$573$1...@fred.mathworks.com>...
Hello Hugh,

Could you tell me what your code returns? Does it return x and y coordinates of the position the user is looking at on the screen? If it does, could you email me your code? I really, really need it.

Much thanks.

Surashree

Xin Niu

unread,
Dec 14, 2013, 8:53:05 AM12/14/13
to
I am trying to do the same thing, and encounter same problem.
I found another gaussian kernel density function which may be useful
http://www.mathworks.com/matlabcentral/fileexchange/17204-kernel-density-estimation

I suppose the input MIN_XY and MAX_XY should be the vector to define the size of the output density.
if your image is 1024*768, I guess MIN_XY should be [0,0] MAX_XY=[1024,768]

Xin Niu

unread,
Dec 14, 2013, 9:05:07 AM12/14/13
to
sorry, I made a mistake, the size of density is defined by input n
and it con only be a square with equal length of x and y.





"Hugh Thompson" wrote in message <ijenvr$573$1...@fred.mathworks.com>...

Karishma Singh

unread,
Jul 24, 2016, 9:34:09 PM7/24/16
to
"Hugh Thompson" wrote in message <ijenvr$573$1...@fred.mathworks.com>...

Karishma Singh

unread,
Jul 24, 2016, 9:36:08 PM7/24/16
to
"Hugh Thompson" wrote in message <ijenvr$573$1...@fred.mathworks.com>...
Hi Hugh,
Did you manage to get the desired heatmap with the provided code??
0 new messages