def new_tiles( files, param_specs, param_io, param_show=dict(), param=dict(), ): _logger.debug( "Start creation of normal maps with settings:\nparam_specs:\t{},\nparam_io:\t{},\nparam_show:\t{},\nparam:\t{}" .format(param_specs, param_io, param_show, param)) # settings ------------------------------------------------------------ # ----------------------------------------------------------------------- img_in, img_out, _, _ = shdw.utils.imgio.get_data(files, param_specs, param_io, param_show=param_show) for item_list in img_in: for index, item in enumerate(item_list): _logger.debug("Processing image '{}'".format(item.path)) img = shdw.utils.imgtools.expand_image_dim(item.data) try: tiles = param["tiles"] except KeyError: tiles = img.shape img = img[0:tiles[0], 0:tiles[1], :] _logger.info(shdw.utils.imgtools.get_array_info(img)) img_out(item.path, img, index=index)
def new_mlp_classification_stats( files, param_specs, param_io, param_label=dict(), param_show=dict(), param=dict() ): _logger.info("Start creation of maximum likelihood classification map with settings:\nparam_specs:\t{},\nparam_io:\t{},\nparam_label:\t{},\nparam_show:\t{},\nparam:\t{}".format(param_specs, param_io, param_label, param_show, param)) # settings ------------------------------------------------------------ # ----------------------------------------------------------------------- img_in, img_out, _, _ = shdw.utils.imgio.get_data(files, param_specs, param_io, param_label=param_label, param_show=param_show) stats = [None]*len(param["channels"]) for channel in range(len(param["channels"])): stats[channel] = [None]*len(param_label) for label in range(len(param_label)): stats[channel][label] = shdw.tools.welford.Welford() for item in img_in: label_masks = shdw.utils.imgtools.get_label_mask(item[param_specs.index("label")].data, param_label.values()) img = item[param_specs.index("msi")].data for channel in range(len(param["channels"])): for label in range(len(param_label.keys())): stats[channel][label].update(img[label_masks[...,label], channel]) return stats
def new_mlp_mv_classification_map( stats, files, param_specs, param_io, param_label=dict(), param_class=list(), param_show=dict(), param=dict() ): _logger.info("Start creation of maximum likelihood classification map with settings:\nparam_specs:\t{},\nparam_io:\t{},\nparam_label:\t{},\nparam_show:\t{},\nparam:\t{}".format(param_specs, param_io, param_label, param_show, param)) # settings ------------------------------------------------------------ # ----------------------------------------------------------------------- img_in, img_out, _, _ = shdw.utils.imgio.get_data(files, param_specs, param_io, param_label=param_label, param_show=param_show) eval_labeled_img = [ shdw.tools.evaluation.EvalLabeledImg(list(param_label.values()), index=param_class), shdw.tools.evaluation.ConfusionMap(list(param_label.values()), index=param_class) ] for item in img_in: labeled_img = get_labeled_img_from_stats( stats, item[param_specs.index("msi")].data ) img_out(item[0].path, shdw.utils.imgtools.project_data_to_img(labeled_img, dtype=np.uint8, factor=255)) label = item[param_specs.index("label")].data eval_labeled_img[0].update(labeled_img, label) eval_labeled_img[1].update(labeled_img, label)
def save_image(dest, img): _logger.info("[SAVE] '{}'".format(dest)) if str(dest).endswith(".tif"): tifffile.imwrite(dest, img) else: PIL.Image.fromarray(img).write(dest)
def read_image(path): _logger.info("[READ] '{}'".format(path)) if str(path).endswith(".tif"): img = tifffile.imread(path) else: img = np.asarray(PIL.Image.open(path)) return img
def new_gaussian_map(files, param_specs, param_io, param_label=dict(), param_show=dict(), param=dict()): _logger.info( "Start creation of maximum likelihood classification map with settings:\nparam_specs:\t{},\nparam_io:\t{},\nparam_label:\t{},\nparam_show:\t{},\nparam:\t{}" .format(param_specs, param_io, param_label, param_show, param)) # settings ------------------------------------------------------------ # ----------------------------------------------------------------------- img_in, img_out, _, _ = shdw.utils.imgio.get_data(files, param_specs, param_io, param_label=param_label, param_show=param_show) for item in img_in: _logger.info("Processing image '{}'".format(item[0].path)) img = item[0].data _logger.info("Result with {}".format( shdw.utils.imgtools.get_array_info(img))) gaussian_map = shdw.utils.imgtools.gaussian_kernel( img.shape[0], img.shape[1], mu=param["stats"][0], sigma=param["stats"][1]) img_out(item[0].path, gaussian_map)
def new_distance_transform_map( files, param_specs, param_io, param_label=dict(), param_show=dict(), param=dict() ): _logger.info("Start creation of maximum likelihood classification map with settings:\nparam_specs:\t{},\nparam_io:\t{},\nparam_label:\t{},\nparam_show:\t{},\nparam:\t{}".format(param_specs, param_io, param_label, param_show, param)) # settings ------------------------------------------------------------ # ----------------------------------------------------------------------- img_in, img_out, _, _ = shdw.utils.imgio.get_data(files, param_specs, param_io, param_label=param_label, param_show=param_show) for item in img_in: _logger.info("Processing image '{}'".format(item[0].path)) edt = np.squeeze( shdw.utils.imgtools.get_distance_transform( item.spec("label").data, param["label_value"], param["threshold"] ), axis=2 ) _logger.info(shdw.utils.imgtools.get_array_info(edt)) img_out(item[0].path, edt)
def write_height_map(img, height, path): data = pandas.DataFrame(height, index=range(img.shape[0] * img.shape[1])) # write to temporary file _logger.info("[SAVE] '{}'".format(path)) shdw.utils.ply.write_ply(path, points=data)
def task_print_user_data(): """Print the user data""" # print user's defined data _logger.info("Print user's defined data") shdw.utils.format.print_data(shdw.config.settings.get_data_dict())
def task_print_user_settings(): """Print the user settings""" # print user's defined settings _logger.info("Print user's defined settings") shdw.utils.format.print_data(shdw.config.settings._SETTINGS)
def copy_image(path, dest): _logger.info("[COPY] '{}'".format(dest)) shutil.copy2(path, dest)
def read_log(path): _logger.info("[READ] '{}'".format(path)) with open(path, "r") as f: return f.read()