HE TMA Core Extraction
[1]:
# import other modules
import skimage.io
import numpy as np
import pandas as pd
from pathlib import Path
from tqdm import tqdm
# check versions and environment executable
import sys
sys.version
sys.executable
[1]:
'/opt/conda/envs/miaaim-dev/bin/python'
Read Core Labels and Export Individual ROIs
[2]:
# set path to data folder
data_folder = Path("/opt/miaaim-20220912-TMA4/data")
# set the path to the imaging data
path_to_modality = data_folder.joinpath("20220912-TMA4-he.ndpi")
# read he high resolution (series 0)
he = skimage.io.imread(path_to_modality)
# read coordinates at 4x downsampling
crop_coords = pd.read_csv(data_folder.joinpath("20220912-TMA4-he-labels-4x.csv"))
[3]:
# iterate over and export cores from labelling
for c in tqdm(range(crop_coords.shape[0])):
# get coordinates and name of ROI from TMA labelling
x,y,w,h,n = crop_coords.loc[c,['X','Y','Width','Height', 'Name']].values
# crop core and transform by factor of 4
heCrop = he[y*4:y*4+h*4,x*4:x*4+w*4].copy()
# transform to align with IMC data
heCrop = np.fliplr(np.flipud(heCrop))
# get core folder name
heCoreFolder = data_folder.joinpath(f"{n}/input/he")
if not heCoreFolder.exists():
heCoreFolder.mkdir()
# export image as tiff
skimage.io.imsave(heCoreFolder.joinpath(f"{n}.tiff"),heCrop)
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 55/55 [00:43<00:00, 1.26it/s]