chord_counts#

Calculates the length of each chord in the input image that contains chords drawn in the void space. It works by labeling each chord and using Scikit image regionprops to measure the length of each chord (number of pixels in the chord).

[1]:
import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
import inspect
inspect.signature(ps.metrics.chord_counts)
[1]:
<Signature (im)>

im#

The input image ontaining chords drawn in the void space. This image can be generated by implementing apply_chords filter on a binary image. We can use blobs generator to generate a test image and draw chords in void space (in x direction by default) using apply_chords.

[2]:
np.random.seed(10)
im = ps.generators.blobs(shape=[500, 500])
im = ps.filters.apply_chords(im)
fig, ax = plt.subplots(1, 1, figsize=[4, 4])
ax.imshow(im, origin='lower', interpolation='none')
ax.axis(False);
../../../_images/examples_metrics_reference_chord_counts_4_0.png

Now the test image is ready to be passed to chord_counts. The method returns a 1D array. Each element in the array corresponds to the length of each chord. A histogram of the chord length array can be plotted:

[3]:
chord_length = ps.metrics.chord_counts(im=im)
fig, ax = plt.subplots(1, 1, figsize=[4, 4])
ax.hist(chord_length, bins=100)
plt.xlabel('chord length along x axis')
plt.ylabel('frequency');
../../../_images/examples_metrics_reference_chord_counts_6_0.png

An alternative to the histogram, we can use numpy.bincount that gives the number of chords of each length and can be plotted using plt.plot. The resulting plot is similar to the histogram plot with a high number of bins:

[4]:
fig, ax = plt.subplots(1, 1, figsize=[4, 4])
ax.plot(np.bincount(chord_length))
plt.xlabel('chord length')
plt.ylabel('the number of chords of each length');
../../../_images/examples_metrics_reference_chord_counts_8_0.png