petersaj / AP_histology

Histology processing
61 stars 21 forks source link

transform coordinates detect by ImagJ #13

Closed chongtianyifa closed 2 years ago

chongtianyifa commented 2 years ago

Hi, thanks for the great pipline. I sucessfully registered some images (2720*1752) to the CCF. However, I got negative histology_points_atlas_y values when I use AP_histology2ccf function. Error cameout in AP_histology2ccf (line 40). The histology_points was generated by ImageJ. Could you help me fix this issue? histology_points.csv histology_ccf.zip

petersaj commented 2 years ago

Hi - to check: looks like you've got two aligned slices, which slice were these points taken from? When I try it, I get out-of-range values if I enter them for the first slice, and in-range values if I enter them for the second slice.

In case that's the issue, to clarify: the histology_points for AP_histology2ccfneeds to be a cell array with x/y values for each corresponding slice. For two slices, that'd be histology_points = {[slice 1 xs, slice 1 ys],[slice 2 xs, slice 2 yx]} (if a slice doesn't have any points, that entry would just be empty).

So for your data, if I take the 'XStart' and 'YStart' values from your histology_points.csv as [x,y], I get negative CCF values for this: ccf_points = AP_histology2ccf({[x,y],[]},slice_im_path) (i.e. points are from first slice) but this gives in-range values: ccf_points = AP_histology2ccf({[],[x,y]},slice_im_path) (i.e. points are from second slice)

chongtianyifa commented 2 years ago

Hi, thanks for the help. I put the coordinates in the wrong order!

I have some other questions. One is what does histology_ccf.mat store? My understanding is that it contains the image value and annotation of each pixel in the transformed template image and also the corresponding coordinates in the standard altas space of each pixel. If so, the image size should be the same as the selected plane during manual registration. However, I found that the size is still 800*1140 even when I choose a template with an angle (should more points be extracted?). Also, if we already have the corresponding coordinates in the standard altas space of each pixel, we don't need to use 'transformPointsForward' anymore as we can directly get the corresponding points by indexing using histology_ccf.

Another question is how I can transform the coordinates in ccf into um unit as we used for injection. I suppose it should be something like this: bregma = allenCCFbregma(); ap=(ccf_points_cat(:,1)-bregma(1))0.01; ml=(ccf_points_cat(:,2)-bregma(2))0.01; dv=(ccf_points_cat(:,3)-bregma(3))0.01; I saw a similiar script in allenCCF package: ap = -(slice_num-bregma(1)+offset)atlas_resolution. what is the offset?

Finally, I might found an error in your demo script: ccf_points_areas = st(ccf_points_areas,:).safe_name; It should be ccf_points_areas = st(ccf_points_av,:).safe_name ?

Thanks again for taking some much time.

petersaj commented 2 years ago

Great, no problem then.

The histology_ccf.mat stores untransformed information - for each histology slice, it saves the corresponding template/annotated CCF slice, and the CCF coordinates for each pixel in that slice. Those images are all the same size because it samples across the max dimensions closest to the slice plane, which is a little arbitrary but covers the bases. I know it's redundant to save slices of the CCF rather than just having the atlas loaded in and grab data from that as-needed, it's something I've considered changing.

The transform goes from histology to CCF by getting the pixel coordinate on the image, warping that onto the CCF slice (saved in histology_ccf.mat), then getting the CCF coordinate in the corresponding pixel (by indexing the coordinates in histology_ccf.mat).

For transforming injection coordinates from CCF to um relative to bregma: that depends on what you're using it for and/or how accurate you want to be. Your code would work, except the CCF is tilted and scaled relative to an average brain with a leveled lambda/bregma, so it would be a little off everywhere and more off the deeper and farther from bregma you were. I apply that tilt and scaling in my trajectory explorer (https://github.com/petersaj/neuropixels_trajectory_explorer), so it might not be too much to write something that transforms CCF to microns, though it would still be an approximation.

Thanks for finding that typo - fixed!

chongtianyifa commented 2 years ago

Thanks for the answer. I also found that the sampling along the selected plane is arbitrary (not have to be 800x1140) as I got a template slice with a size of 1140x1140 by selecting a horizontal slice.

You may want to change the example of histology points in AP_histology2ccf.m: {[100,200]},{[]} to {[100,200],[]}.

petersaj commented 2 years ago

The sampling should extend to the limits of the closest orthogonal dimensions (e.g. horizontal should extend to the max AP and ML width). From your size though I saw that there was a typo that was causing the AP limit to be wrong in horizontal slices and the cerebellum was getting cut off, so I've just fixed that. I haven't known of anyone using this for horizontal slices, so hopefully that's all working fine now, but let me know if there are other issues.

Also fixed the example histology points in that doc, thanks for catching.