.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples\plot_database.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_database.py: ================= Texture Patchwork ================= .. codeauthor:: Frédéric Richard This example shows how to build a series of simulations of a field model by changing its parameter values at random. This is useful to construct a dataset of textures. .. GENERATED FROM PYTHON SOURCE LINES 50-113 .. image:: /auto_examples/images/sphx_glr_plot_database_001.png :alt: plot database :class: sphx-glr-single-img .. code-block:: default from matplotlib import pyplot as plt import matplotlib.gridspec as gridspec import numpy as np from afbf import tbfield, coordinates ncols = 10 nrows = 10 nbexamples = ncols * nrows # Number of examples. N = 100 # Size of examples. # Mode of simulation for step values (alt, 'unif', 'unifmax', or 'unifrange'). simstep = 'unifmin' # Mode of simulation for step interval bounds (alt, 'nonunif'). simbounds = 'unif' # Define the field to be simulated and coordinates where to simulate. field = tbfield('afbf-smooth') coord = coordinates(N) # Set the mode of simulation for the Hurst function. field.hurst.SetStepSampleMode(mode_cst=simstep, mode_int=simbounds) # Prepare the figure fig = plt.figure(figsize=(nrows, ncols)) gs = gridspec.GridSpec(nrows, ncols) gs.update(wspace=0.05, hspace=0.05) # Set axe spacing. # Generate several examples. for example in range(nbexamples): # Sample new model parameters. np.random.seed(example) field.hurst.ChangeParameters() field.topo.ChangeParameters() # Uncomment to show field parameters. # field.DisplayParameters() # Compute field features. field.ComputeFeatures() # Uncomment to show some field features. # print('Hurst index:', field.H) # print('Std deviation (hurst):', field.aniso_indices_hurst[0]) # print('TV-norm (hurst):', field.aniso_sharpness_hurst[0]) # Simulate an example with the current model. np.random.seed(example) field.EvaluateTurningBandParameters() simu = field.Simulate(coord) # Uncomment to display the field simulation. # simu.Display(2) # To handle simu as an ndarray of numpy, set image = np.reshape(simu.values, simu.M) # To further display it with pyplot of matplotlib: i = int(np.floor(example / ncols)) j = int(example - i * ncols) ax = plt.subplot(gs[i, j]) ax.imshow(image, cmap='gray') ax.set_axis_off() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 2 minutes 15.834 seconds) .. _sphx_glr_download_auto_examples_plot_database.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_database.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_database.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_