Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 7fef4f65 authored by NADAL Morgane's avatar NADAL Morgane
Browse files

some refactoring + added sklgraph

parent f542dbe1
Branches
No related tags found
No related merge requests found
......@@ -42,9 +42,12 @@ import brick.component.extension as xt_
import brick.component.soma as sm_
import brick.general.feedback as fb_
import brick.processing.input as in_
import brick.processing.plot as po_
# import brick.processing.image_verification as iv_
# from main_prm import *
import brick.processing.SKLGraph as sk_
from sklgraph.skl_fgraph import skl_graph_t
from sklgraph.skl_graph import plot_mode_e
from sklgraph.skl_map import skl_map_t
import os as os_
import sys as sy_
......@@ -54,7 +57,7 @@ import time as tm_
import matplotlib.pyplot as pl_
import numpy as np_
import skimage.io as io_
from skimage.segmentation import relabel_sequential
# from skimage.segmentation import relabel_sequential
import skimage.morphology as mp_
import skimage.measure as ms_
import networkx as nx_
......@@ -110,7 +113,7 @@ image = in_.ImageVerification(image, channel)
# iv_.image_verification(image, channel) # -> PySide2 interface # TODO: must return the modified image!
# /!\ conflicts between some versions of PySide2 and Python3
image = image[:, 700:, 700:] # 512 # 562 # Just for development
image = image[:, 512:, 512:] # 512 # 562 # Just for development
img_shape = image.shape
# pl_.matshow(image[image.shape[0] // 2, :, :])
# pl_.show()
......@@ -122,13 +125,14 @@ img_shape = image.shape
print(f"IMAGE: s.{img_shape} t.{image.dtype} m.{image.min()} M.{image.max()}")
# Intensity relative normalization (between 0 and 1).
# TODO: change Frangi to take the normalization btw 0 and 1 into account
# TODO: change Frangi to take the normalization btw 0 and 1 into account ?
# image_for_soma = in_.IntensityNormalizedImage(image)
# image_for_ext = in_.IntensityNormalizedImage(image)
# image_for_soma = in_.NormalizedImage(image)
# image_for_ext = in_.NormalizedImage(image)
image_for_soma = image
image_for_ext = image
# This normalization is essential for the detection of extension and the connexions to the somas!
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
......@@ -305,4 +309,79 @@ print(f"DONE: {tm_.strftime('%a, %b %d %Y @ %H:%M:%S')}")
if with_plot:
pl_.show()
# glial_graph_3d = sk_.skl_graph_t.FromSkeleton(soma_map) # Travailler apd squelettes (soma pas sous fore de sk)
# Skeletonize the somas to extract the graph of the glial cells
space_dim = 3
array_shape = (80, 80, 50)
threshold_fct = lambda img: 0.75 * image.max()
struct_elm_shape = (3, 3, 3)
soma_w_ext_map = som_nfo['soma_w_ext_lmp']
skeleton = skl_map_t.FromShapeMap(soma_w_ext_map, store_widths=True)
skel_graph = skl_graph_t.FromSkeleton(skeleton)
# --- Some info about the skeleton graph
print(
f"Obj map area={np_.count_nonzero(soma_w_ext_map)}\n\n"
f"Validity={skel_graph.is_valid}\n\n"
f"N nodes={skel_graph.n_nodes}\n"
f"N edges={skel_graph.n_edges}\n"
f"Highest degree={skel_graph.highest_degree}/{skel_graph.highest_degree_w_nodes}\n\n"
f"Length={skel_graph.length}<-{skel_graph.edge_lengths}\n"
f"Width=Hom.{skel_graph.reduced_width()}/Het.{skel_graph.heterogeneous_reduced_width()}<-{skel_graph.edge_reduced_widths()}\n"
f"Area as WxL={skel_graph.reduced_width() * skel_graph.length}\n"
f"Area as WW Length={skel_graph.ww_length}<-{skel_graph.edge_ww_lengths}\n")
# --- Checking correctness of skeleton graph via various rebuilt maps
rebuilt_skel = skel_graph.RebuiltSkeletonMap()
part_map_for_check = skeleton.PartMap()
# Keep next line before its next one
part_map_for_check[part_map_for_check == skeleton.invalid_n_neighbors] = 0
part_map_for_check[part_map_for_check > 3] = 3
print(
f"Rebuilt skeleton = Original one? Part map? "
f"{np_.array_equal(rebuilt_skel > 0, skeleton.map)} "
f"{np_.array_equal(rebuilt_skel, part_map_for_check)}")
if space_dim == 3:
rebuilt_skel = rebuilt_skel.max(axis=2)
# --- Checking correctness of skeleton graph via rebuilt object map
soma_w_ext_map = soma_w_ext_map.astype(np_.uint8)
rebuilt_map = skel_graph.RebuiltObjectMap()
if space_dim == 3:
soma_w_ext_map = soma_w_ext_map.max(axis=2)
rebuilt_map = rebuilt_map.max(axis=2)
# --- Show various images and plot the skeleton graph
# ___, axes = pl_.subplots(1, 3, figsize=(15,15))
# axes[0].matshow(soma_w_ext_map)
# axes[1].matshow(rebuilt_map)
# axes[2].matshow(soma_w_ext_map - rebuilt_map)
# axes[0].set_title("Object")
# axes[1].set_title("Rebuilt")
# axes[2].set_title("Object - Rebuilt")
# for axis in axes:
# axis.set_axis_off()
# pl_.tight_layout(pad=0.3)
# ___, axes = pl_.subplots(1, 3)
# axes[0].matshow(rebuilt_skel + soma_w_ext_map)
# axes[1].matshow(rebuilt_skel + rebuilt_map)
# axes[2].matshow(rebuilt_skel)
# axes[0].set_title("Rebuilt Skel Over Obj")
# axes[1].set_title("Rebuilt Skel Over Rebuilt Obj")
# axes[2].set_title("Rebuilt Skel")
# for axis in axes:
# axis.set_axis_off()
# pl_.tight_layout(pad=0.3)
# if space_dim == 2:
# skel_graph.Plot(mode=plot_mode_e.Networkx, should_block=False)
# skel_graph.Plot(mode=plot_mode_e.Graphviz, should_block=False)
skel_graph.Plot(mode=plot_mode_e.SKL_Curve, w_directions=True, should_block=False)
skel_graph.Plot(should_block=False)
pl_.show()
\ No newline at end of file
......@@ -31,8 +31,8 @@
from __future__ import annotations
import brick.elm_id as id_
from skl_map import LABELIZED_MAP_fct_FOR_DIM
import sklgraph.brick.elm_id as id_
from sklgraph.skl_map import LABELIZED_MAP_fct_FOR_DIM
import itertools as it_
from collections import namedtuple as namedtuple_t
......
......@@ -29,9 +29,9 @@
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL license and that you accept its terms.
import brick.edge as dg_
import brick.node as nd_
import skl_map as sm_
import sklgraph.brick.edge as dg_
import sklgraph.brick.node as nd_
import sklgraph.skl_map as sm_
from typing import List, Tuple
......
......@@ -31,9 +31,9 @@
from __future__ import annotations
import brick.elm_id as id_
import skl_map as sm_
from skl_map import LABELIZED_MAP_fct_FOR_DIM
import sklgraph.brick.elm_id as id_
import sklgraph.skl_map as sm_
from sklgraph.skl_map import LABELIZED_MAP_fct_FOR_DIM
from typing import Callable, Dict, Iterable, List, Tuple
......
......@@ -33,9 +33,9 @@ import matplotlib as mpl_
mpl_.use('TkAgg')
from brick.processing.sklgraph.skl_fgraph import skl_graph_t
from brick.processing.sklgraph.skl_graph import plot_mode_e
from brick.processing.sklgraph.skl_map import skl_map_t
from sklgraph.skl_fgraph import skl_graph_t
from sklgraph.skl_graph import plot_mode_e
from sklgraph.skl_map import skl_map_t
import pathlib as ph_
import sys as sy_
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment