Esempio n. 1
0
def bettiCurve_pipe1(img_file):
    """
    Pipeline 1: Binarizer --> Height Filtration --> Cubical Persistance --> Betti Curve
    """
    img = cv2.imread(img_file)
    img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    # blur the image to reduce noise
    figure_size = 9  # the dimension of the x and y axis of the kernal.
    img = cv2.blur(img, (figure_size, figure_size))

    shape = img.shape
    images = np.zeros((1, *shape))
    images[0] = img
    bz = Binarizer(threshold=40 / 255)
    binned = bz.fit_transform(images)
    p = make_pipeline(HeightFiltration(direction=np.array([1, 1])),
                      CubicalPersistence(), BettiCurve(n_bins=50))
    return p.fit_transform(binned)
Esempio n. 2
0
def pipeline1(images):
    """
    Binarizer --> Height Filtration, Erosion Filtration, Dilation Filtration --> Cubical Persistance --> Amp, PE
    return: Array of pipelines
    """
    # Pipeline parameters
    bin_thresholds = [np.percentile(images[0], 93) / np.max(images[0])]
    directions = [
        np.array([np.cos(t), np.sin(t)])
        for t in np.linspace(0, 2 * np.pi, 8)[:-1]
    ]
    n_iterations = np.linspace(1, 21, 5).astype(int).tolist()

    features = [('bottleneck', Amplitude(metric='bottleneck', n_jobs=-1)),
                ('PE', PersistenceEntropy(n_jobs=-1))]

    # Make filtrations
    binned_steps = [('binarizer_{}'.format(t), Binarizer(threshold=t,
                                                         n_jobs=-1))
                    for t in bin_thresholds]
    filtrations = [('height_{}'.format(d),
                    HeightFiltration(direction=d, n_jobs=-1))
                   for d in directions]
    filtrations += [('erosion_{}'.format(i),
                     ErosionFiltration(n_iterations=i, n_jobs=-1))
                    for i in n_iterations]
    filtrations += [('dilation_{}'.format(i),
                     DilationFiltration(n_iterations=i, n_jobs=-1))
                    for i in n_iterations]

    # Make pipelines
    cubical_lower = ('cubical', CubicalPersistence(n_jobs=-1))

    partial_pipeline_steps = []
    partial_pipeline_steps.append([cubical_lower])
    partial_pipeline_steps.append([('inverter', Inverter(n_jobs=-1)),
                                   cubical_lower])

    for b, f in itertools.product(binned_steps, filtrations):
        partial_pipeline_steps.append(
            [b, f, ('cubical', CubicalPersistence(n_jobs=-1))])

    feature_pipelines = []
    for s, f in itertools.product(partial_pipeline_steps, features):
        feature_pipelines.append(Pipeline(s + [f]))

    return feature_pipelines
Esempio n. 3
0
def test_binarizer_fit_transform_plot():
    Binarizer().fit_transform_plot(images_2D, sample=0)
Esempio n. 4
0
def test_binarizer_transform(threshold, expected):
    binarizer = Binarizer(threshold=threshold)

    assert_almost_equal(binarizer.fit_transform(expected), expected)
Esempio n. 5
0
def test_binarizer_errors():
    threshold = 'a'
    binarizer = Binarizer(threshold=threshold)
    with pytest.raises(TypeError):
        binarizer.fit(images_2D)
Esempio n. 6
0
def test_binarizer_not_fitted():
    binarizer = Binarizer()
    with pytest.raises(NotFittedError):
        binarizer.transform(images_2D)
Esempio n. 7
0
    np.zeros((7, 8, 4))
],
                     axis=0)

images_3D_float = np.stack([
    2.5 * np.ones((7, 8, 4)),
    3. * np.concatenate([np.ones(
        (7, 4, 4)), np.zeros((7, 4, 4))], axis=1),
    np.zeros((7, 8, 4))
],
                           axis=0)


@pytest.mark.parametrize(
    "transformer",
    [Binarizer(), Inverter(),
     Padder(), ImageToPointCloud()])
def test_invalid_input_shape(transformer):
    X = np.ones((1, 1, 1, 1, 1))
    with pytest.raises(ValueError, match="Input of `fit`"):
        transformer.fit(X)


def test_binarizer_not_fitted():
    binarizer = Binarizer()
    with pytest.raises(NotFittedError):
        binarizer.transform(images_2D)


def test_binarizer_errors():
    threshold = 'a'
Esempio n. 8
0
                                                    random_state=42)

# IMAGE FUNCTION

# st.sidebar.selectbox('Select Digit', options = ('0','1','2','3','4','5','6','7','8','9','10'))

# Bianizer

im_idx = np.flatnonzero(y_train == str(
    st.sidebar.selectbox('Select Digit',
                         options=('0', '1', '2', '3', '4', '5', '6', '7', '8',
                                  '9', '10'))))[0]

im = X_train[im_idx][None, :, :]

binarizer = Binarizer(threshold=0.4)

im_binarized = binarizer.fit_transform(im)

binplot = binarizer.plot(im_binarized)

binplot.update_layout(template='plotly_dark')

# Radial Filtration

radial_filtration = RadialFiltration(center=np.array([20, 6]))

im_filtration = radial_filtration.fit_transform(im_binarized)

radplot = radial_filtration.plot(im_filtration, colorscale="jet")