def test_get_region_dict(self): ts = large_image.getTileSource(os.path.join(TEST_DATA_DIR, 'Easy1.png')) result = cli_utils.get_region_dict([-1, -1, -1, -1], 2000, ts) expected = {} assert result == expected, "Expected {}, got {}".format( expected, result) result = cli_utils.get_region_dict([100, 110, 250, 240], 500, ts) expected = dict(region=dict(left=100, top=110, width=250, height=240)) assert result == expected, "Expected {}, got {}".format( expected, result)
def main(args): # Read Input Image print('>> Reading input image') print(args.inputImageFile) ts = large_image.getTileSource(args.inputImageFile) im_input = ts.getRegion(format=large_image.tilesource.TILE_FORMAT_NUMPY, **utils.get_region_dict(args.region, args.maxRegionSize, ts))[0] # Create stain matrix print('>> Creating stain matrix') w = utils.get_stain_matrix(args) print w # Perform color deconvolution print('>> Performing color deconvolution') im_stains = htk_cd.color_deconvolution(im_input, w).Stains # write stain images to output print('>> Outputting individual stain images') print args.outputStainImageFile_1 skimage.io.imsave(args.outputStainImageFile_1, im_stains[:, :, 0]) print args.outputStainImageFile_2 skimage.io.imsave(args.outputStainImageFile_2, im_stains[:, :, 1]) print args.outputStainImageFile_3 skimage.io.imsave(args.outputStainImageFile_3, im_stains[:, :, 2])
def main(args): utils.create_dask_client(args) ts = large_image.getTileSource(args.inputImageFile) make_label_image = args.outputLabelImage is not None region = utils.get_region_dict( args.region, *(args.maxRegionSize, ts) if make_label_image else ()).get('region') ppc_params = ppc.Parameters( **{k: getattr(args, k) for k in ppc.Parameters._fields}) results = ppc.count_slide( args.inputImageFile, ppc_params, region, args.tile_grouping, make_label_image, ) if make_label_image: stats, label_image = results # Colorize label image. Colors from the "coolwarm" color map color_map = np.empty((4, 3), dtype=np.uint8) color_map[ppc.Labels.NEGATIVE] = 255 color_map[ppc.Labels.WEAK] = 60, 78, 194 color_map[ppc.Labels.PLAIN] = 221, 220, 220 color_map[ppc.Labels.STRONG] = 180, 4, 38 # Cleverly index color_map label_image = color_map[label_image] skimage.io.imsave(args.outputLabelImage, label_image) else: stats, = results with open(args.returnParameterFile, 'w') as f: for k, v in zip(stats._fields, stats): f.write('{} = {}\n'.format(k, v))
def main(args): utils.create_dask_client(args) ts = large_image.getTileSource(args.inputImageFile) kwargs = dict(format=large_image.tilesource.TILE_FORMAT_NUMPY) makeLabelImage = args.outputLabelImage is not None kwargs.update(utils.get_region_dict( args.region, *(args.maxRegionSize, ts) if makeLabelImage else () )) if makeLabelImage: tile = ts.getRegion(**kwargs)[0] results, labelImage = positive_pixel_count_single_tile( args, tile, makeLabelImage=True) skimage.io.imsave(args.outputLabelImage, labelImage) else: results = [] total_tiles = ts.getSingleTile(**kwargs)['iterator_range']['position'] for position in range(0, total_tiles, args.tile_grouping): results.append(delayed(positive_pixel_count_tiles)( args, kwargs, position, min(args.tile_grouping, total_tiles - position))) results = delayed(combine)(results).compute() r = results total_all_positive = sum(r[k] for k in results_num_keys) output = ( [(k, r[k]) for k in results_keys] + [('IntensityAverage', sum(r[k] for k in results_i_keys) / total_all_positive), ('RatioStrongToTotal', float(r['NumberStrongPositive']) / total_all_positive), ('IntensityAverageWeakAndPositive', (r['IntensitySumWeakPositive'] + r['IntensitySumPositive']) / (r['NumberWeakPositive'] + r['NumberPositive']))] ) with open(args.returnParameterFile, 'w') as f: for k, v in output: f.write('{} = {}\n'.format(k, v))