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
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
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
Thanks again,
Hugh
"Oliver Woodford" wrote in message <ijh33k$nm5$1...@fred.mathworks.com>...
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>...
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