Discussion:
Making a heat map for eye tracking data
(too old to reply)
Hugh Thompson
2011-02-15 20:34:03 UTC
Permalink
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
2011-02-16 16:08:41 UTC
Permalink
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
2011-02-16 17:56:04 UTC
Permalink
Post by Hugh Thompson
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
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
2011-02-17 03:38:03 UTC
Permalink
Thank you Ashish and Oliver. I believe this is exactly what I need!

Thanks again,
Hugh
Post by Oliver Woodford
Post by Hugh Thompson
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
Hi Hugh
http://www.mathworks.com/matlabcentral/fileexchange/19280-bivariant-kernel-density-estimation-v2-0
sc(cat(3, density, im), 'prob');
A = sc(cat(3, density, im), 'prob');
imwrite(A, 'output.png');
sc(cat(3, density, im), 'prob_jet');
http://www.mathworks.com/matlabcentral/fileexchange/16233-sc-powerful-image-rendering
HTH,
Oliver
Hugh Thompson
2011-02-17 16:47:05 UTC
Permalink
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
Post by Hugh Thompson
Thank you Ashish and Oliver. I believe this is exactly what I need!
Thanks again,
Hugh
Post by Oliver Woodford
Post by Hugh Thompson
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
Hi Hugh
http://www.mathworks.com/matlabcentral/fileexchange/19280-bivariant-kernel-density-estimation-v2-0
sc(cat(3, density, im), 'prob');
A = sc(cat(3, density, im), 'prob');
imwrite(A, 'output.png');
sc(cat(3, density, im), 'prob_jet');
http://www.mathworks.com/matlabcentral/fileexchange/16233-sc-powerful-image-rendering
HTH,
Oliver
Oliver Woodford
2011-02-17 18:11:04 UTC
Permalink
Post by Hugh Thompson
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
2013-03-27 06:24:18 UTC
Permalink
Post by Hugh Thompson
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
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
2013-12-14 13:53:05 UTC
Permalink
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
2013-12-14 14:05:07 UTC
Permalink
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.
Post by Hugh Thompson
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
Karishma Singh
2016-07-25 01:34:03 UTC
Permalink
Post by Hugh Thompson
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
Karishma Singh
2016-07-25 01:36:04 UTC
Permalink
Post by Hugh Thompson
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
Hi Hugh,
Did you manage to get the desired heatmap with the provided code??
Loading...