Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
size = 250
dim = 3
shape = tuple(size for _ in range(dim))
phantom = avg.blobs(shape=shape, porosity=0.5, random_seed=3)
phantom = helper.fill_floating_solids_and_closed_pores(phantom)

# %%
sample_shape, sample_min, sample_max, sample_mean, sample_std = helper.get_stats(
    phantom)

# %%
x_slice = size // 2
y_slice = size // 2
z_slice = size // 2

helper.show_2d_sections(phantom, x=x_slice, y=y_slice, z=z_slice)

# %%
phantom_recon_180 = moe.process_image(phantom, 180)
helper.show_2d_sections(phantom_recon_180, x=x_slice, y=y_slice, z=z_slice)

# %%
phantom_recon_180_blurring = moe.process_image(phantom,
                                               180,
                                               detector_blurring=True)
helper.show_2d_sections(phantom_recon_180_blurring,
                        x=x_slice,
                        y=y_slice,
                        z=z_slice)

# %%
Ejemplo n.º 3
0
helper.show_histogram(sample_filtered,
                      xmin=sample_f_min,
                      xmax=sample_f_max,
                      log=True)
helper.show_histogram(sample_diff,
                      xmin=sample_diff_min,
                      xmax=sample_diff_max,
                      log=True)

# %%
x_slice = 150
y_slice = 25
z_slice = 25

# %%
helper.show_2d_sections(sample, x=x_slice, y=y_slice, z=z_slice)
helper.show_2d_sections(sample_filtered, x=x_slice, y=y_slice, z=z_slice)
helper.show_2d_sections(sample_diff, x=x_slice, y=y_slice, z=z_slice)
helper.show_2d_sections(bin_sample, x=x_slice, y=y_slice, z=z_slice)
helper.show_2d_sections(bin_sample_filled, x=x_slice, y=y_slice, z=z_slice)
helper.show_2d_sections(bin_sample_filtered, x=x_slice, y=y_slice, z=z_slice)
helper.show_2d_sections(bin_sample_filtered_filled,
                        x=x_slice,
                        y=y_slice,
                        z=z_slice)

# %%
helper.plot_column(sample)
helper.plot_column(sample_filtered)
helper.plot_column(sample_diff)
helper.plot_column(bin_sample)
Ejemplo n.º 4
0
size = 250
dim = 3
shape = tuple(size for _ in range(dim))
phantom = avg.blobs(shape=shape, porosity=0.5, random_seed=3)
phantom = helper.fill_floating_solids_and_closed_pores(phantom)

# %%
sample_shape, sample_min, sample_max, sample_mean, sample_std = helper.get_stats(
    phantom)

# %%
x_slice = size // 2
y_slice = size // 2
z_slice = size // 2

helper.show_2d_sections(phantom, x=x_slice, y=y_slice, z=z_slice)

# %%
phantom_recon_180 = moe.process_image(phantom, 180)
helper.show_2d_sections(phantom_recon_180, x=x_slice, y=y_slice, z=z_slice)

# %%
phantom_recon_180_no_filter_blurring = moe.process_image(
    phantom, 180, detector_blurring=True)
helper.show_2d_sections(phantom_recon_180_no_filter_blurring,
                        x=x_slice,
                        y=y_slice,
                        z=z_slice)

reconstruct_filter = 'hamming'
phantom_recon_180_hamming_blurring = moe.process_image(
Ejemplo n.º 5
0
import model_of_experiment as moe
from scipy import ndimage
import logreg

# %%
size = 250
dim = 3
shape = tuple(size for _ in range(dim))
phantom = avg.blobs(shape=shape, porosity=0.5, random_seed=3)

# %%
x_slice = size // 2
y_slice = size // 2
z_slice = size // 2

helper.show_2d_sections(phantom, x=x_slice, y=y_slice, z=z_slice)

# %%
floating_solids = helper.get_floating_solids(phantom)
print(f'Floating solids: {np.sum(floating_solids)}')
phantom[floating_solids] = False

# %%
phantom_recon = moe.process_image(phantom,
                                  180,
                                  reconstruct_filter='ramp',
                                  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)
Ejemplo n.º 6
0
from scipy import signal
import anisotropic_volume_generator as avg

# %%
sample = helper.get_data_from_file(
    '/Users/grimax/Desktop/tmp/porous sample/sample.h5', 'Reconstruction')
sample_shape, sample_min, sample_max, sample_mean, sample_std = helper.get_stats(
    sample)

# %%
sample_fft = np.fft.fftn(sample)
sample_fft_abs = np.fft.fftshift(np.log(1 + np.abs(sample_fft)))
sample_fft_phase = np.fft.fftshift(np.angle(sample_fft))

# %%
helper.show_2d_sections(sample_fft_abs, x=125, y=125, z=125)
helper.show_2d_sections(sample_fft_phase, x=125, y=125, z=125)

# %%
helper.plot_column(sample_fft_abs, x=125, y=125)

# %%
sigma = 25
gauss_filter = avg.kernel_basis_3d(250, [sigma, sigma, sigma], [0, 0, 0])
gauss_filter /= np.max(gauss_filter)
# helper.show_2d_sections(gauss_filter, x=125, y=125, z=125)
# helper.plot_column(gauss_filter, x=125, y=125)

# %%
gauss_filter_inverse = 1 - gauss_filter
# helper.show_2d_sections(gauss_filter_inverse, x=125, y=125, z=125)