def test_radial_transform(center, images, expected): radial = RadialFiltration(center=center) print(radial.fit_transform(images)) assert_almost_equal(radial.fit_transform(images), expected)
def test_radial_not_fitted(): radial = RadialFiltration() with pytest.raises(NotFittedError): radial.transform(images_2D)
def test_radial_errors(): center = 'a' radial = RadialFiltration(center=center) with pytest.raises(TypeError): radial.fit(images_2D)
def test_radial_fit_transform_plot(): RadialFiltration().fit_transform_plot(images_2D, sample=0)
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') # PLOTS st.subheader("") st.write(binplot) st.subheader("Figure 1. Binarized Plot") st.subheader("") st.subheader("")
X[X <= .4] = 0 X[X > .4] = 1 X = X.reshape((40000, 28, 28)) X_bin = X # X_index = np.zeros((40000, 28, 28)) # for i in tqdm(range(40000)): # img = X[i] # x_arr, y_arr = np.nonzero(img) # X_index[i] = np.array([x_arr, y_arr]).T hf = HeightFiltration() df = DilationFiltration() rf = RadialFiltration(np.array([8, 15])) X_used = X_bin y_used = y ## Create the Filtrations X_hf = hf.fit_transform(X_used, y_used) X_df = df.fit_transform(X_used, y_used) X_rf = rf.fit_transform(X_used, y_used) fig = plt.figure() fig.set_size_inches((12, 9)) a = fig.add_subplot(2, 2, 1) a.set_title("Height filtration") imgplot = plt.imshow(X_hf[4], cmap="viridis") a = fig.add_subplot(2,2, 2) a.set_title("Dilation filtration")
pio.renderers.default = 'plotly_mimetype' images_2D = np.stack([np.ones((3, 4)), np.concatenate([np.ones((3, 2)), np.zeros((3, 2))], axis=1), np.zeros((3, 4))], axis=0) images_3D = np.stack([np.ones((3, 4, 2)), np.concatenate([np.ones((3, 2, 2)), np.zeros((3, 2, 2))], axis=1), np.zeros((3, 4, 2))], axis=0) @pytest.mark.parametrize("transformer", [HeightFiltration(), RadialFiltration(), DilationFiltration(), ErosionFiltration(), SignedDistanceFiltration(), DensityFiltration()]) 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_height_not_fitted(): height = HeightFiltration() with pytest.raises(NotFittedError): height.transform(images_2D) def test_height_errors():