# phase_fraction¶

## Import packages¶

[1]:

import matplotlib.pyplot as plt
import numpy as np
import porespy as ps

ps.visualization.set_mpl_style()
np.random.seed(10)


## Generate image for testing¶

[5]:

im_1 = ps.generators.blobs(shape=[500, 500])
im_2 = ps.generators.blobs(shape=[500, 500])
phases = im_1*1.0 + im_2*2.0
fig, ax = plt.subplots(1, 1, figsize=[4, 4])
ax.imshow(phases);


## Apply metric function¶

Output is an array of the amount of voxels with the specified label. phase_fraction normalizes the number of voxels in each phase by the total number of voxels by default. Note: phase_fraction of void phase in this case indicates porosity of the image.

[6]:

x = ps.metrics.phase_fraction(phases)
print(x)

{0.0: 0.24339999999999998, 1.0: 0.24814, 2.0: 0.268848, 3.0: 0.239612}


It’s also possible to return total number of voxels in each phase:

[8]:

x = ps.metrics.phase_fraction(phases, normed=False)
print(x)

{0.0: 60850, 1.0: 62035, 2.0: 67212, 3.0: 59903}