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)
def test_binarizer_transform(threshold, expected): binarizer = Binarizer(threshold=threshold) assert_almost_equal(binarizer.fit_transform(expected), expected)
# 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") radplot.update_layout(template='plotly_dark')