HS2P is an open-source project largely based on CLAM tissue segmentation and patching code.
install requirements via pip3 install -r requirements.txt
If you want to benefit from wandb logging, you need to follow these simple steps:
export WANDB_API_KEY=<your_personal_key>
config/
(set enable
to True
)slide_id,slide_path
slide_id_1,path/to/slide_1.tif
slide_id_2,path/to/slide_2.tif
...
You can optionally provide paths to pre-computed segmentation masks under the 'segmentation_mask_path' column
slide_id,slide_path,segmentation_mask_path
slide_id_1,path/to/slide_1.tif,path/to/slide_1_mask.tif
slide_id_2,path/to/slide_2.tif,path/to/slide_2_mask.tif
...
config/extraction/
A good starting point is to use the default configuration file config/extraction/default.yaml
where parameters are documented.
python3 patch_extraction.py --config-file </path/to/config/file>
masks/
will contain a downsampled view of the slide with tissue segmentation overlayed
visualization/
will contain a downsampled view of the slide where extracted patches are highlighted
tiles.csv
contain patching information for each slide that ended up having patches extracted:
slide_id,tile_size,spacing,level,level_dim,x,y,contour
slide_id_1,2048,0.5,0,"(10496, 20992)",752,5840,0
...
Extracted patches will be saved as x_y.jpg
where x
and y
represent the true location in the slide at level 0:
0.25
and you extract [256, 256] patches at spacing 0.25
, two consecutive patches will be distant from 256
pixels (either along x
or y
axis)0.25
and you extract [256, 256] patches at spacing 0.5
, two consecutive patches will be distant from 512
pixels (either along x
or y
axis)see above
slide_id,slide_path,annotation_mask_path
slide_id_1,path/to/slide_1.tif,path/to/slide_1_annot_mask.tif
slide_id_2,path/to/slide_2.tif,path/to/slide_2_annot_mask.tif
...
In the same way as for patch extraction, you can optionally provide paths to pre-computed segmentation masks under the 'segmentation_mask_path' column.
config/sampling/
A good starting point is to use the default configuration file config/sampling/default.yaml
where parameters are documented.
python3 patch_sampling.py --config-file </path/to/config/file>
annotation_mask/
will contain a downsampled view of the slide with corresponding annotation mask overlayed
segmentation_mask/
will contain a downsampled view of the slide with tissue segmentation overlayed
visualization/
will contain a downsampled view of the slide where sampled patches are highlighted
sampled_patches.csv
contain information for each patch that ended up being extracted:
slide_id,category,x,y,pct
slide_id_1,category_1,3488,2512,0.8203125
...
Again, extracted patches will be saved as x_y.jpg
where x
and y
represent the true location in the slide at level 0.
If the generated visualization are noisy, you'll need to change libpixman
version. Running the following command should fix this issue:
wget https://www.cairographics.org/releases/pixman-0.40.0.tar.gz
tar -xf pixman-0.40.0.tar.gz
cd pixman-0.40.0
./configure
make
make install
export LD_PRELOAD=/usr/local/lib/libpixman-1.so.0.40.0