Heat map generation

I have a superposition of images from distinct trajectories and I want to create a heat map from them. I want to know if it possible from image create such hingP_20210308_195206

I want to obtain something like this

. I want to obtain something of all the trajectories and not individual, that’s why I don’t want to work with stacks

However if someone knows how to do it from stacks of images I appreciate it too
Thanks

Hi @danramirez

I think if you try to create a heatmap from the first image you show, you will end up with a very innacurate representation, as it doesn’t look like you can tell where there are overlapping tracks. Regardless, one way would be to simply invert the image, maybe drop a median filter then apply a new LUT:

138549f6fa99ec2aa34fb42e63c865192fa56a8b-1

This is really not a great solution for a number of reasons, but if you have the XYt coordinates, another way to approach this is to create a blank image (the same size as your original), then for each XY position, draw a circle selection around the point and add the value of 1 to it. The areas where your object frequents will have higher values. You can then blur or spatially filter your image to smooth the edges if desired.

Here’s a snippet to give you an idea what I mean:

r=100;
x=newArray(100,120,140,160,180,200,200,200,220,220);
y=newArray(250,250,250,250,250,250,280,300,300,280);
newImage("Untitled", "8-bit black", 500, 500, 1);
for (i = 0; i < x.length; i++) {
run("Specify...", "width="+r+" height="+r+" x="+x[i]+" y="+y[i]+" oval centered");
run("Add...", "value=1");
}
run("Select None");
run("Median...", "radius=20");
run("Enhance Contrast...", "saturated=0");
run("royal");

I’ve taken this approach in the past for invertebrate tracking (right at the bottom of this post):

Hi,
As you say It doesnt show me the overlapping, but it shows me where it spent time the fly. because I do not have the x and y coordinates the second choice you give me its complicated because i am a newbie in image j. I think for my purposes the image that you show me its more than ok. I aprecciated if you could tell me How did you do it? to do it myself

Thanks A LOT
my masters degree on this

What format is the original data in?
If you have individual images with single points for the location of the fly at any given time, and each of those points is a 1 (and all other values are 0), you should be able to create a Sum Projection (add all of the images together). The final 2D image should have higher values where the paths overlap at that point.
Pretty close to:

If all you have is a flat image showing the results of the pathing as a mask, then you probably do not have enough information for much of a heatmap.
You might be able to blur and apply a LUT to achieve something similar, but if a tracked object sat still for the entire duration, your heatmap would be incorrect as it would not show the (fly?) staying at that point for a long time.

If you’re only interested in the coverage of the fly (IE. how much of the well does the fly explore) then indeed the idea suggested above helps to answer the question (although it will be highly dependent upon sampling time). As both I and @Research_Associate point out however if you’re trying to indicate in any way how much time is spent at each position, you likely cannot get an accurate answer from these images.

Regardless, the steps I followed with a greyscale image were:

  • Invert the Image [Edit > Invert]
  • Median Filter to smooth the image [Process > Filter > Median] (on your screen grab I used ~20px). NOTE: This is really an aesthetic step and not justifiable quantitatively.
  • Set the LUT [Image > Lookup Tables > royal] (again, this is not a great LUT to as it lacks perceptual linearity, I was just copying your example - more info on better choices here)

However please do not take this as a recommended approach. If you need more help, it would be worth providing access to a small subset of the original data (not a photo of a screen).

2 Likes

I have the x and y coordinates from each trajectory of flies. I want to create and overlapping image per treatment. And if I get you right, the best option is the one you suggest of create a new image. I’ll give it a try.

thanks

1 Like