CsatiZoltan / CristalX

Identification and analysis of polycrystalline microstructures
https://cristalx.readthedocs.io
GNU Lesser General Public License v3.0
6 stars 7 forks source link

Random colors for grains, but with a given seed #45

Open CsatiZoltan opened 3 years ago

CsatiZoltan commented 3 years ago

When plotting the same grain configuration twice, the displayed colors are different because colors are randomly allocated to each grain. This is not only annoying when making comparisons, but it can also deceive people who do not know about the random color allocation. The solution is to use a given seed for the random number generator. Then the same colors are used for subsequent plotting.

from numpy.random import default_rng
rng = default_rng(seed)  # uses the PCG64 generator
vals = rng.random((m, n))

See also #9.

Implement it in the analysis module as show_label_image.