BodenmillerGroup / cytomapper

R package for visualization of highly multiplexed imaging data
https://bodenmillergroup.github.io/cytomapper/
31 stars 9 forks source link

y axis coordinate #94

Closed arcolombo closed 2 months ago

arcolombo commented 2 months ago

Hi so if i generate a mask using CP the mask matches the original image as expected.

After i use cytomapper to create the objects issuing

cust_sce <- measureObjects(masks,restack, img_id = "ImageNb") the cust_sce has m.cx and m.cy columns appended to each object. however if i plot the m.cx and m.cy using any spatial software in R (spatstat etc) the y-axis directions are flipped compared to the original. i'm not sure if any has replicated this or if there is a different reference point starting in a different cartesian coordinate system? thank you

Rplot Rplot02

arcolombo commented 2 months ago

i think the issue is with the EBI image 'computeFeatures.moment' which computes the m.cx and m.cy is an odd origin Using this code for any typical mask, i see that the m.cy has a different orientation compared to the original mask

code for reproducing

obj2 = computeFeatures.moment(cust_masks[[id]]) xy2 = data.frame(X=obj2[,'m.cx'],Y=obj2[,'m.cy']) pp2 = st_as_sf(xy2,coords=c('X','Y'))

arcolombo commented 2 months ago

M_nuclei_mask.zip

here is the attached mask and if you call computeFeatures.moment on it, the directions of the coordinates do not match the original mask

nilseling commented 2 months ago

The origin of the coordinate system that EBImage is using (top left corner) is in line with other conventions for coordinate systems (https://scikit-image.org/docs/stable/user_guide/numpy_images.html#coordinate-conventions). Just the coordinate system in R (origin in bottom left corner) does not fit to these conventions. So if you want to visualize the cells' coordinates matching to the image you would need to reverse the y axis (as is done in plotSpatial by default; see flip_y). This has no effect on spatial calculations as they most often rely onn euclidean distances between points.

I'm a bit confused as the mask that you send does not match the images that you posted in your original message. Is that correct?

arcolombo commented 2 months ago

Hi thank you. yes that may have been a different sample as the mask, but the plotSpatial is what i will use. happy to close this. makes sense. thank you

nilseling commented 2 months ago

Ok, great! Closing now.