def generate_phantom(porosity, noise_parameter, threshold_levels=None): print(f'Porosity: {porosity:.2f}') print(f'Noise parameter: {noise_parameter}') phantom = avg.blobs(shape=shape, porosity=porosity, random_seed=random_seed) print(f'Generated porosity: {1 - np.sum(phantom)/phantom.size:.2f}') phantom[helper.get_floating_solids(phantom)] = False helper.show_2d_sections(phantom, x=x_slice, y=y_slice, z=z_slice) phantom_recon = moe.process_image( phantom, number_of_angles, reconstruct_filter='ramp', noise_parameter=noise_parameter, noise_method=noise_method, source_blurring=source_blurring, detector_blurring=detector_blurring ) helper.show_2d_sections(phantom_recon, x=x_slice, y=y_slice, z=z_slice) # plt.figure(figsize=(20, 20)) # plt.imshow(phantom_recon[0, :, :], cmap='gray') phantom_recon -= np.min(phantom_recon) phantom_recon /= np.max(phantom_recon) phantom_recon = (phantom_recon * 255).astype(np.uint8) phantom_recon_bin, otsu_level = helper.binarize_image(phantom_recon) helper.show_2d_sections(phantom_recon_bin, x=x_slice, y=y_slice, z=z_slice) recon_bin_porosity = 1 - np.sum(phantom_recon_bin)/phantom_recon_bin.size show_phantoms_stats(phantom, phantom_recon, otsu_level) floating_solids = helper.get_floating_solids(phantom_recon_bin) closed_pores = helper.get_closed_pores(phantom_recon_bin) floating_solids_count = np.sum(floating_solids) closed_pores_count = np.sum(closed_pores) print(f'Floating solids: {floating_solids_count}') print(f'Closed pores: {closed_pores_count}') print('\n') if threshold_levels is not None: for threshold_level in threshold_levels: phantom_recon_bin[phantom_recon < threshold_level] = False phantom_recon_bin[phantom_recon >= threshold_level] = True helper.show_2d_sections(phantom_recon_bin, x=x_slice, y=y_slice, z=z_slice) floating_solids = helper.get_floating_solids(phantom_recon_bin) closed_pores = helper.get_closed_pores(phantom_recon_bin) print(f'Threshold level: {threshold_level}') print(f'Binarized porosity: {1 - np.sum(phantom_recon_bin)/phantom_recon_bin.size:.2f}') print(f'Floating solids: {np.sum(floating_solids)}') print(f'Closed pores: {np.sum(closed_pores)}') print('\n') plt.show() return recon_bin_porosity, floating_solids_count, closed_pores_count
import helper import anisotropic_volume_generator as avg import model_of_experiment as moe from scipy import ndimage # %% recalculate = False # %% sample = helper.get_data_from_file( '/Users/grimax/Desktop/tmp/porous sample/sample.h5', 'Reconstruction') bin_sample_path = '/Users/grimax/Desktop/tmp/porous sample/bin_sample.h5' if recalculate: bin_sample = helper.binarize_image(sample) helper.save_data_to_file(bin_sample_path, 'Binarized', bin_sample) bin_sample = helper.get_data_from_file(bin_sample_path, 'Binarized', 'bool') porosity = helper.calc_porosity(bin_sample) bin_sample_filled = helper.fill_floating_solids_and_closed_pores(bin_sample) helper.calc_porosity(bin_sample_filled) sample_filtered_path = '/Users/grimax/Desktop/tmp/porous sample/sample_filtered.h5' if recalculate: sample_filtered = helper.filter_image(sample, 9) helper.save_data_to_file(sample_filtered_path, 'Filtered', sample_filtered) # %%
phantom_recon_180_sart_noise_30) recon_blurring_shape, recon_blurring_min, recon_blurring_max, recon_blurring_mean, recon_blurring_std = helper.get_stats( phantom_recon_180_hamming_noise_30_blurring) recon_blurring_sart_shape, recon_blurring_sart_min, recon_blurring_sart_max, recon_blurring_sart_mean, recon_blurring_sart_std = helper.get_stats( phantom_recon_180_sart_noise_30_blurring) # %% helper.plot_column(phantom_recon_180_hamming_noise_30) helper.plot_column(phantom_recon_180_sart_noise_30) helper.plot_column(phantom_recon_180_hamming_noise_30_blurring) helper.plot_column(phantom_recon_180_sart_noise_30_blurring) # %% bin_recon = helper.binarize_image(phantom_recon_180_hamming_noise_30) bin_recon_sart = helper.binarize_image(phantom_recon_180_sart_noise_30) bin_recon_blurring = helper.binarize_image( phantom_recon_180_hamming_noise_30_blurring) bin_recon_blurring_sart = helper.binarize_image( phantom_recon_180_sart_noise_30_blurring) # %% helper.show_2d_sections(bin_recon, x=x_slice, y=y_slice, z=z_slice) helper.show_2d_sections(bin_recon_sart, x=x_slice, y=y_slice, z=z_slice) helper.show_2d_sections(bin_recon_blurring, x=x_slice, y=y_slice, z=z_slice) helper.show_2d_sections(bin_recon_blurring_sart, x=x_slice, y=y_slice,
max_v = 2**bits data_int = helper.image_digitize(data, bits) # %% id="Ij2yrjqCyJZ1" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} outputId="10c0e1d6-e287-4e19-b6c5-db169460dbcf" with h5py.File(f'{file_dir}sample_int.h5', mode='w') as file_to_save: file_to_save.create_dataset('Reconstruction', data=data_int, compression='lzf') # %% id="Tlan_ddGy4JE" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 611} outputId="0b4c5713-3ff9-4a19-8bef-fafe347e9325" plt.figure(figsize=(5, 5)) plt.imshow(data_int[:, :, 0]) plt.colorbar() # %% data_bin, _ = helper.binarize_image(data_int) plt.figure(figsize=(5, 5)) plt.imshow(data_bin[:, :, 0]) # %% data_bin_erosion = helper.erosion(data_bin) data_bin_dilation = helper.dilation(data_bin) data_bin_edges = np.ones( data_bin.shape) - data_bin_erosion - ~data_bin_dilation fig, axes = plt.subplots(1, 3, figsize=(15, 5)) axes[0].imshow(data_bin_erosion[:, :, 0]) axes[1].imshow(data_bin_dilation[:, :, 0]) axes[2].imshow(data_bin_edges[:, :, 0]) # %%
noise_parameter=30, noise_method='poisson', detector_blurring=True) phantom_recon_shape, phantom_recon_min, phantom_recon_max, phantom_recon_mean, phantom_recon_std = helper.get_stats( phantom_recon) helper.show_2d_sections(phantom_recon, x=x_slice, y=y_slice, z=z_slice) helper.show_histogram(phantom_recon, xmin=phantom_recon_min, xmax=phantom_recon_max, log=True) # %% helper.scatter_plot(phantom_recon, phantom, 'phantom_recon vs phantom') # %% phantom_recon_bin, _ = helper.binarize_image(phantom_recon) floating_solids = helper.get_floating_solids(phantom_recon_bin) print(f'Floating solids: {np.sum(floating_solids)}') # helper.show_2d_sections(phantom_recon_bin, x=x_slice, y=y_slice, z=z_slice) # %% helper.scatter_plot(phantom_recon, phantom_recon_bin, 'phantom_recon vs phantom_recon_bin') # %% phantom_recon_bin_filled = helper.fill_floating_solids_and_closed_pores( phantom_recon_bin) floating_solids_bin_filled = helper.get_floating_solids( phantom_recon_bin_filled) print(f'Floating solids: {np.sum(floating_solids_bin_filled)}')