cortex-lab / Suite2P

Tools for processing 2P recordings
Other
121 stars 66 forks source link

Original cell coordinates #128

Closed sbugeon closed 6 years ago

sbugeon commented 6 years ago

I want to get the coordinates of the cells detected by Suite2P in the original .tif image. I have found that dat.stat.med (from the output proc.mat file) contains the coordinates in the cropped image, and that dat.ops.xrange and dat.ops.yrange provide the cropped region coordinates.

But, if I check the coordinates in the original image, there is a slight shift that I don't understand and which is opposite in X and Y. For example, a cell which has [125,307] as its original coordinates, will have a dat.stat.med = [87,252] with xrange going from 49 to 461, and yrange going from 47 to 460. So this gives a shift of -11 in X and 8 in Y.

Do you have any idea where this could come from? Is there an easy way to find the original coordinates of the cells?

Thanks a lot for your help on this,

marius10p commented 6 years ago

You are right that med contains the median y and x coordinates for pixels selected as belonging to that cell, in the cropped reference frame. For coordinates we use the image convention here: points have coordinates (y,x). I don't know why you would get such a large difference, are you sure you matched the original cells with the detected ones? Easiest would be to just plot all the detected centroids on top of the mean image of the original movie (mimg1).

We should really be outputting coordinates in the original reference frame. @carsen-stringer

carsen-stringer commented 6 years ago

make sure you're subtracting yrange(1) from med(1) and xrange(1) from med(2), does that fix it?

marius10p commented 6 years ago

mimg is not cropped., so your first image is correct

How did you get your original mean image? There might have been a slow drift during your recording, so that the mean image of the first tiff is shifted with respect to the aligned mean of the entire experiment, which is what mimg contains.

sbugeon commented 6 years ago

This is possible, I have used ImageJ to obtain the original mean image. The drift is quite small in this movie though.

carsen-stringer commented 6 years ago

Here is minimal code that works on our non-cropped mean image, not sure if this helps:

dat=load('F*.mat'); meds=[dat.stat.med]; meds=reshape(meds,2,[]); clf; imagesc(dat.ops.mimg1); hold all; plot(meds(2,:)+dat.ops.xrange(1), meds(1,:)+dat.ops.yrange(1), 'r.');