def __resize_batch_helper(item, inputfolder, outputfolder, order=1, append_resolution_to_filename=True, **kwargs_to_ignore): inputfile, voxel_size = item metadata = Metadata() metadata.set_voxel_size(voxel_size) stack = Stack(filename=inputfolder + inputfile) zoom = np.array(stack.metadata['Voxel size arr']) / np.array( metadata['Voxel size arr']) stack.resize(zoom=zoom, order=order) stack.metadata.set_voxel_size(metadata['Voxel size arr']) path = os.path.dirname(inputfile) strres = str(metadata['Voxel size']).replace(' ', ' ').replace( ' ', ' ').replace('[ ', '[').replace(' ', '_') if path == '': if append_resolution_to_filename: outputname = outputfolder + inputfile[: -4] + '_voxel_size_' + strres + '.tif' else: outputname = outputfolder + path + 'voxel_size_' + strres + '/' + inputfile.split( '/')[-1] else: outputname = outputfolder + path + '_voxel_size_' + strres + '/' + inputfile.split( '/')[-1] stack.save(outputname) stack.metadata.save(outputname[:-4] + '.csv')
def __compute_accuracy_measures_batch_helper(item, inputfolder, reffolder, outputfolder, **kwargs_to_ignore): if not reffolder.endswith('/'): reffolder += '/' parts = item.split('/') name = parts[-1] if len(parts) > 1: base = parts[-2] else: base = '' stack = Stack(filename=inputfolder + item) if 'isPSF' not in stack.metadata.index or str( stack.metadata['isPSF']) == 'False': if os.path.exists(reffolder + item): refstack = Stack(filename=reffolder + item) elif os.path.exists(reffolder + name): refstack = Stack(filename=reffolder + name) elif os.path.exists(reffolder + base + '/' + name): refstack = Stack(filename=reffolder + base + '/' + name) elif os.path.exists(reffolder + name.split('_voxel_size')[0] + '.tif'): refstack = Stack(filename=reffolder + name.split('_voxel_size')[0] + '.tif') else: raise ValueError('No ground truth found for cell ' + item + '!') input_voxel_size = stack.metadata['Voxel size arr'] zoom = np.array(stack.metadata['Voxel size arr']) / np.array( refstack.metadata['Voxel size arr']) stack.resize(zoom=zoom) stats = stack.compute_accuracy_measures(refstack) stack.metadata.set_voxel_size(input_voxel_size) for c in stack.metadata.index: try: stats[c] = stack.metadata[c] except ValueError: stats[c] = str(stack.metadata[c]) stats['Name'] = item filelib.make_folders([os.path.dirname(outputfolder + item)]) stats.to_csv(outputfolder + item[:-4] + '.csv', sep='\t')