Ejemplo n.º 1
0
    newInd = np.arange(nrUniqueVals) + counter
    newVals = total_labels[newInd]
    tmp2 = np.zeros((tmp.shape))
    for ind2, val in enumerate(uniqueVals):
        tmp2[tmp == val] = newVals[ind2]
    counter = counter + nrUniqueVals
    ncut_labels[:, :, ind] = tmp2
lMax = np.max(ncut_labels)

orig_ncut_labels = ncut_labels.copy()
ima_ncut_labels = ncut_labels.copy()


#
"""Data Processing"""
orig, dims = check_data(nii.get_data(), cfg.force_original_precision)
# Save min and max truncation thresholds to be used in axis labels
orig, pMin, pMax = truncate_range(orig, percMin=cfg.perc_min,
                                  percMax=cfg.perc_max)
# Continue with scaling the original truncated image and recomputing gradient
orig = scale_range(orig, scale_factor=cfg.scale, delta=0.0001)
gra = set_gradient_magnitude(orig, cfg.gramag)
if cfg.export_gramag:
    export_gradient_magnitude_image(gra, nii.get_filename(), nii.affine)

# Reshape ima (more intuitive for voxel-wise operations)
ima = np.ndarray.flatten(orig)
gra = np.ndarray.flatten(gra)

#
"""Plots"""
Ejemplo n.º 2
0
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from matplotlib.widgets import Slider, Button, LassoSelector
from matplotlib import path
from nibabel import load
from segmentator.utils import map_ima_to_2D_hist, prep_2D_hist
from segmentator.utils import truncate_range, scale_range, check_data
from segmentator.utils import set_gradient_magnitude
from segmentator.utils import export_gradient_magnitude_image
from segmentator.gui_utils import sector_mask, responsiveObj
from segmentator.config_gui import palette, axcolor, hovcolor

#
"""Data Processing"""
nii = load(cfg.filename)
orig, dims = check_data(nii.get_data(), cfg.force_original_precision)
# Save min and max truncation thresholds to be used in axis labels
if np.isnan(cfg.valmin) or np.isnan(cfg.valmax):
    orig, pMin, pMax = truncate_range(orig,
                                      percMin=cfg.perc_min,
                                      percMax=cfg.perc_max)
else:  # TODO: integrate this into truncate range function
    orig[orig < cfg.valmin] = cfg.valmin
    orig[orig > cfg.valmax] = cfg.valmax
    pMin, pMax = cfg.valmin, cfg.valmax

# Continue with scaling the original truncated image and recomputing gradient
orig = scale_range(orig, scale_factor=cfg.scale, delta=0.0001)
gra = set_gradient_magnitude(orig, cfg.gramag)
if cfg.export_gramag:
    export_gradient_magnitude_image(gra, nii.get_filename(), cfg.gramag,