From 3ff4cecf86e9a24db75619491da27c16950805e8 Mon Sep 17 00:00:00 2001 From: monadal <morgane.nadal@inria.fr> Date: Mon, 9 Mar 2020 17:41:56 +0100 Subject: [PATCH] changed label into relabel + max - modified Filtered Maps --- brick/__init__.py | 0 brick/component/extension.py | 3 ++- brick/component/soma.py | 3 ++- nutrimorph.py | 28 +++++++++++++--------------- 4 files changed, 17 insertions(+), 17 deletions(-) delete mode 100644 brick/__init__.py diff --git a/brick/__init__.py b/brick/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/brick/component/extension.py b/brick/component/extension.py index 4b88e1d..dc6c556 100644 --- a/brick/component/extension.py +++ b/brick/component/extension.py @@ -191,8 +191,9 @@ class extension_t(glial_cmp_t): if region.area <= min_area_c: region_sites = (lmp == region.label).nonzero() result[region_sites] = 0 + lmp[region_sites] = 0 - return result + return result, lmp @staticmethod def FineMapFromCoarseMap(coarse_map: array_t) -> array_t: diff --git a/brick/component/soma.py b/brick/component/soma.py index c081bce..43fd4ec 100644 --- a/brick/component/soma.py +++ b/brick/component/soma.py @@ -169,8 +169,9 @@ class soma_t(glial_cmp_t): if region.area <= min_area: region_sites = (lmp == region.label).nonzero() result[region_sites] = 0 + lmp[region_sites] = 0 - return result + return result, lmp @staticmethod def ContourMap(map_: array_t) -> array_t: diff --git a/nutrimorph.py b/nutrimorph.py index d47cfbf..3df86f9 100644 --- a/nutrimorph.py +++ b/nutrimorph.py @@ -53,6 +53,7 @@ import matplotlib.pyplot as pl_ import numpy as np_ import skimage.io as io_ import skimage.measure as ms_ +from skimage.segmentation import relabel_sequential print(sy_.argv, sy_.argv.__len__()) @@ -81,7 +82,6 @@ exec(open(sy_.argv[1]).read()) soma_t = sm_.soma_t extension_t = xt_.extension_t - print(f"STARTED: {tm_.strftime('%a, %b %d %Y @ %H:%M:%S')}") start_time = tm_.time() @@ -93,12 +93,12 @@ image = io_.imread(data_path) # Image size verification - simple version without user interface image = in_.ImageVerification(image, channel) -# TODO make a user friendly interface (PySide2) BUT bug with the importation of Shiboken2 on Windows8.1 +# TODO make a user friendly interface (PySide2) BUT bug with the importation of Shiboken2 on Windows8.1. image = image[:, 512:, 512:] # 562 img_shape = image.shape -pl_.matshow(image[image.shape[0] // 2,:,:]) -pl_.show() +# pl_.matshow(image[image.shape[0] // 2, :, :]) +# pl_.show() # # max_img = image.max() # image.fill(image.min()) @@ -110,7 +110,6 @@ image_for_soma = in_.NormalizedImage(image) image_for_ext = in_.NormalizedImage(image) print(f"NRM-IMG: t.{image_for_soma.dtype} m.{image_for_soma.min():.2f} M.{image_for_soma.max():.2f}") - # --- Initialization som_nfo = {} ext_nfo = {} @@ -126,9 +125,11 @@ axes = {} print("\n--- Soma Detection") som_nfo["map"] = soma_t.Map(image_for_soma, soma_low_c, soma_high_c, soma_selem_c) -som_nfo["map"] = soma_t.FilteredMap(som_nfo["map"], min_area_c) -#TODO: change label into relabel + max -som_nfo["lmp"], n_somas = ms_.label(som_nfo["map"], return_num=True) +som_nfo["map"], som_lmp = soma_t.FilteredMap(som_nfo["map"], min_area_c) +# som_nfo["lmp"], n_somas= ms_.label(som_nfo["map"], return_num=True) +som_nfo["lmp"] = relabel_sequential(som_lmp)[0] # Use relabel instead of label to optimize the algorithm. +n_somas = som_nfo["lmp"].max() + som_nfo["dist_to_closest"], som_nfo["influence_map"] = soma_t.InfluenceMaps( som_nfo["lmp"] ) @@ -143,16 +144,17 @@ print(f"\nElapsed Time={tm_.strftime('%Hh %Mm %Ss', elapsed_time)}") if with_plot: fb_.PlotSomas(somas, som_nfo, axes) - # -- Extentions print("\n--- Extension Detection") enhanced_ext, ext_scales = extension_t.EnhancedForDetection(image_for_ext, in_parallel=in_parallel) ext_nfo["coarse_map"] = extension_t.CoarseMap(enhanced_ext, ext_low_c, ext_high_c) -ext_nfo["coarse_map"] = extension_t.FilteredCoarseMap(ext_nfo["coarse_map"]) +ext_nfo["coarse_map"], ext_lmp = extension_t.FilteredCoarseMap(ext_nfo["coarse_map"]) ext_nfo["map"] = extension_t.FineMapFromCoarseMap(ext_nfo["coarse_map"]) ext_nfo["map"][som_nfo["map"] > 0] = 0 -ext_nfo["lmp"], n_extensions = ms_.label(ext_nfo["map"], return_num=True) +# ext_nfo["lmp"], n_extensions = ms_.label(ext_nfo["map"], return_num=True) +ext_nfo["lmp"] = relabel_sequential(ext_lmp)[0] # Use relabel instead of label to optimize the algorithm. +n_extensions = ext_nfo["lmp"].max() extensions = tuple( extension_t().FromMap(ext_nfo["lmp"], ext_scales, uid) @@ -165,11 +167,9 @@ print(f"\nElapsed Time={tm_.strftime('%Hh %Mm %Ss', elapsed_time)}") if with_plot: fb_.PlotExtensions(extensions, ext_nfo, img_shape) - # -- Preparation for Connections dijkstra_costs = in_.DijkstraCosts(image, som_nfo["map"], ext_nfo["map"]) - # -- Soma-Extention print("\n--- Soma <-> Extension") @@ -205,7 +205,6 @@ print(f"\nElapsed Time={tm_.strftime('%Hh %Mm %Ss', elapsed_time)}") if with_plot: fb_.PlotSomasWithExtensions(somas, som_nfo, "all") - # -- Extention-Extention print("\n--- Extension <-> Extension") @@ -248,7 +247,6 @@ print(f"\nElapsed Time={tm_.strftime('%Hh %Mm %Ss', elapsed_time)}") if with_plot: fb_.PlotSomasWithExtensions(somas, som_nfo, "with_ext_of_ext") - # -- Summary print("\n") for soma in somas: -- GitLab