Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warping cell and transcript x,y coordinates - unable to shift or warp #127

Open
dr-sayyadhury opened this issue May 17, 2024 · 1 comment
Labels

Comments

@dr-sayyadhury
Copy link

Hi,

I manaaged to register the DAPI image from a xenium output and with an HE stained image of the same slide. However, I am having issues warping my cell centroid xy coordinates and the transcripts points data over the registered images. When I run it and check, nothing really changes. I see a slight shift in the coordinates but its bascially staying at the same place and not warping proplery to the registered images.

The source file for the points data is the dapi image. And below is code. Not sure even which parameters i should fine-tune.

Thank you.

CODE

now warp the cells and transcripts coordinates

Calculate scaled coordinates

cells_xy = cells[['x_centroid', 'y_centroid']].values * scale_factor
transcripts_xy = transcripts[['x_location', 'y_location']].values * scale_factor

Retrieve slide objects from the registrar

dapi_reg = registrar.get_slide('morphology_mod')
he_reg = registrar.get_slide('566_mod') # Assuming 'he_reg' might be used later or it's a mistake here

Warp the coordinates using the slide object for DAPI registration

cells_registered = dapi_reg.warp_xy(cells_xy, )
transcripts_registered = dapi_reg.warp_xy(transcripts_xy)

Optional: Save the registered coordinates back to DataFrame and output to CSV

cells['registered_x'], cells['registered_y'] = cells_registered[:, 0], cells_registered[:, 1]
transcripts['registered_x'], transcripts['registered_y'] = transcripts_registered[:, 0], transcripts_registered[:, 1]

Define paths for saving output

#results_dst_dir = 'path_to_results_directory'
#cells.to_csv(os.path.join(results_dst_dir, 'cells_registered.csv'), index=False)
#transcripts.to_csv(os.path.join(results_dst_dir, 'transcripts_registered.csv'), index=False)

FILE OUTPUT

x_centroid | y_centroid | | registered_x | registered_y
-- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | --
1107.338379 | 1715.022461 107.354164 | 1715.050549

As you can see, after warping, the change is minimal...

@cdgatenbee
Copy link
Collaborator

Hi @dr-sayyadhury,

Since it looks like you want to warp the info associated positions associated with the DAPI image on to the HE image, something to try the would be to use the Slide.warp_xy_from_to method, and/or set reference_img_f="566_mod" when initializing the Valis object. The code above is warping the points to the registered space, not necessarily onto the H&E image. That may actually be the source of this issue, because if the DAPI image is the reference image then the warped points won't be very different than their original position.

The code to do the above would be like this, where I've also set check_for_reflections=True since I noticed that one of the images needs to be "mirrored":

registrar = registration.Valis(src_dir, dst_dir, reference_img_f="566.tif", check_for_reflections=True)
.
.
.

cell_xy_on_he = dapi_reg.warp_xy_from_to(xy= cells_xy, to_slide_obj= he_reg)
transcripts_xy_on_he = dapi_reg.warp_xy_from_to(xy= transcripts_xy, to_slide_obj= he_reg)

Also, could you tell me a bit about what scale_factor is? If the cell positions were found on the full resolution image, then there shouldn't be a need to scale the cell positions, even though the images used for registration are much smaller. But, if scale_factor is converting the positions from biological units to pixel units, then this scaling does need to be done. I'm not sure if that would be the source of this issue, but thought it would be worth mentioning.

If the above options don't work, would you be able to share the files containing the points you'd like to warp? I imagine the files are large, so it wouldn't have to be all of the points, but maybe a small sample that I could use for debugging. You could e-mail them to the same address you sent the images to.

Best,
-Chandler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants