Skip to content

Commit

Permalink
Added porosity to fractal_noise to fix #963
Browse files Browse the repository at this point in the history
  • Loading branch information
amirDahari1 committed Jun 4, 2024
1 parent b804d7a commit 9809ff1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 61 deletions.
104 changes: 46 additions & 58 deletions examples/generators/reference/fractal_noise.ipynb

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions src/porespy/generators/_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

def fractal_noise(
shape,
porosity: float = None,
frequency: float = 0.05,
octaves: int = 4,
gain: float = 0.5,
Expand All @@ -15,13 +16,16 @@ def fractal_noise(
uniform: bool = True,
):
r"""
Generate fractal noise which can be thresholded to create binary
images with realistic structures across scales.
Generate fractal noise with realistic structures across scales.
Parameters
----------
shape : array_like
The size of the image to generate, can be 2D or 3D.
porosity : float
If specified, this will convert the noise distribution to uniform
(no need to set uniform to ``True``), and then threshold the image
to the specified value prior to returning.
frequency : scalar, default=0.05
Controls the overall scale of the generated noise, with larger
values giving smaller structures.
Expand Down Expand Up @@ -98,6 +102,8 @@ def fractal_noise(
perlin.perturb.perturbType = PerturbType.NoPerturb
perlin.seed = seed
result = perlin.genAsGrid(shape)
if uniform:
if porosity or uniform:
result = all_to_uniform(result, scale=[0, 1])
if porosity:
result = result < porosity
return result

0 comments on commit 9809ff1

Please sign in to comment.