Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# get scale for the tile and adjust centroids points
ts_metadata = ts.getMetadata()
scale = ts_metadata['magnification'] / args.superpixel_mag
x_centroids = [x / scale for x in x_centroids]
y_centroids = [y / scale for y in y_centroids]
# get requested tile
tile_info = \
ts.getSingleTile(tile_position=tile_position,
format=large_image.tilesource.TILE_FORMAT_NUMPY,
**superpixel_kwargs)
im_tile = tile_info['tile'][:, :, :3]
# perform color normalization
im_nmzd = htk_cnorm.reinhard(im_tile, args.reference_mu_lab,
args.reference_std_lab, src_mu=src_mu_lab,
src_sigma=src_sigma_lab)
im_height, im_width = im_nmzd.shape[:2]
left = tile_info['gx'] / scale
top = tile_info['gy'] / scale
patch_size = int(args.patchSize / scale)
# get width and height
width = tile_info['width']
height = tile_info['height']
n_superpixels = len(x_centroids)
tile_features = []
tile_position=tile_position,
format=large_image.tilesource.TILE_FORMAT_NUMPY,
**it_kwargs)
im_tile = tile_info['tile'][:, :, :3]
csv_dict['ROIShape'] = im_tile.shape[:2]
prep_time = time.time() - start_time
csv_dict['PreparationTime'] = round(prep_time, 3)
# =========================================================================
# =================Img Normalization & Color Deconv========================
# =========================================================================
print('\n>> Color Deconvolving ... \n')
start_time = time.time()
im_nmzd = htk_cnorm.reinhard(
im_tile,
REFERENCE_MU_LAB,
REFERENCE_STD_LAB,
src_mu=src_mu_lab,
src_sigma=src_sigma_lab
)
# perform color decovolution
if args.deconv_method == 'ruifrok':
w = cli_utils.get_stain_matrix(args)
im_stains = htk_cdeconv.color_deconvolution(
im_nmzd, w).Stains.astype(np.float)[:, :, :2]
elif args.deconv_method == 'macenko':
src_mu_lab=None, src_sigma_lab=None):
# get slide tile source
ts = large_image.getTileSource(slide_path)
# get requested tile
tile_info = ts.getSingleTile(
tile_position=tile_position,
format=large_image.tilesource.TILE_FORMAT_NUMPY,
**it_kwargs)
# get tile image
im_tile = tile_info['tile'][:, :, :3]
# perform color normalization
im_nmzd = htk_cnorm.reinhard(im_tile,
args.reference_mu_lab,
args.reference_std_lab,
src_mu=src_mu_lab,
src_sigma=src_sigma_lab)
# perform color decovolution
w = cli_utils.get_stain_matrix(args)
im_stains = htk_cdeconv.color_deconvolution(im_nmzd, w).Stains
im_nuclei_stain = im_stains[:, :, 0].astype(np.float)
# segment nuclear foreground
im_nuclei_fgnd_mask = im_nuclei_stain < args.foreground_threshold
# segment nuclei