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

Tile coordinates #22

Open
gabemarx opened this issue Jan 20, 2021 · 3 comments
Open

Tile coordinates #22

gabemarx opened this issue Jan 20, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@gabemarx
Copy link

Hello,

I was wondering if there is any feature that would enable me to get information on the coordinates of each tile so I can relate it back to the WSI in analysis. The output csv currently just tells me the relative row and column but I am finding it difficult to use that in a meaningful way.

Best,
Gabe

@manuel-munoz-aguirre
Copy link
Owner

Hi Gabe,
Currently, there is no built-in feature to save the pixel tile coordinates in the output file. But since the tile sizes and row/column coordinates are included in the output csv, you can calculate the tile position (upper left corner of each tile) from the output file (at the level of output-downsample):

import pandas as pd
import numpy as np

tiles = pd.read_csv("tile_selection.tsv", sep = "\t")

# Calculate width position in output
tiles['width_position'] = pd.Series(tiles.groupby('Row').apply(lambda x: np.cumsum(x['Width']).shift(1, fill_value = 0)).values)

# Calculate height position in output
heights = [0]
h = 0
for i in range(1, tiles.shape[0]):
    if tiles['Row'][i] != tiles['Row'][i-1]:
        h += tiles['Height'][i-1]
    heights.append(h)
tiles['height_position'] = pd.Series(heights)

You can (approximately) relate these to the original WSI pixel coordinates through the downsampling factor used (the exact value can be seen when running PyHIST with --info verbose).

@manuel-munoz-aguirre manuel-munoz-aguirre added the enhancement New feature or request label Apr 23, 2021
@manuel-munoz-aguirre manuel-munoz-aguirre added this to the Feature roadmap milestone Apr 23, 2021
@franfcunha
Copy link

You could also change __create_tiles function, namely the value of imgtile_out to a string format that could be more easily interpreted afterwards. I did it by passing the counter i to the np.unravel_index() function and then added the vertical and horizontal subscript in the tile name. In my case I am writing tiles from the base level (downsample=1), if it is not your case you could also add some integer value to the tile_name to get a reference to the level from which it was sampled...

@swvanderlaan
Copy link

@franfcunha could you potentially share your code on how you did this?

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

No branches or pull requests

4 participants