Exemplo n.º 1
0
def test_scale_range():
    """Test range scaling."""
    # Given
    data = np.random.random(100) - 0.5
    data.ravel()[np.random.choice(data.size, 10, replace=False)] = 0.
    data.ravel()[np.random.choice(data.size, 5, replace=False)] = np.nan
    s = 42.  # scaling factor
    expected = [0., s]  # min and max
    # When
    output = scale_range(data, scale_factor=s, delta=0.01, discard_zeros=False)
    # Then
    assert all([np.nanmin(output) >= expected[0],
                np.nanmax(output) < expected[1]])
Exemplo n.º 2
0
def test_scale_range():
    """Test range scaling."""
    # Given
    data = np.random.random(100) - 0.5
    data.ravel()[np.random.choice(data.size, 10, replace=False)] = 0.
    data.ravel()[np.random.choice(data.size, 5, replace=False)] = np.nan
    s = 42.  # scaling factor
    expected = [0., s]  # min and max
    # When
    output = scale_range(data, scale_factor=s, delta=0.01, discard_zeros=False)
    # Then
    assert all(
        [np.nanmin(output) >= expected[0],
         np.nanmax(output) < expected[1]])
Exemplo n.º 3
0
    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"""
print("Preparing GUI...")
# Plot 2D histogram
fig = plt.figure(facecolor='0.775')
ax = fig.add_subplot(121)
Exemplo n.º 4
0
#
"""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,
                                    nii.affine)
# Reshape for voxel-wise operations
ima = np.copy(orig.flatten())
gra = gra.flatten()

#
"""Plots"""
print("Preparing GUI...")
# Plot 2D histogram
fig = plt.figure(facecolor='0.775')
ax = fig.add_subplot(121)