pysparse.utils package

Submodules

pysparse.utils.const module

pysparse.utils.scalenorm module

pysparse.utils.scalenorm.normalization(x)[source]
pysparse.utils.scalenorm.scale(X, sto=[0, 1], sfrom=None, istrunc=True, rich=False)[source]

Scale data.

\[x \in [a, b] --> y \in [c, d] \]
\[y = (d-c)*(x-a) / (b-a) + c. \]
Parameters:
  • X (array_like) – The data to be scaled.
  • sto (tuple, list, optional) – Specifies the range of data after beening scaled. Default [0, 1].
  • sfrom (tuple, list, optional) – Specifies the range of data. Default [min(X), max(X)].
  • istrunc (bool) – Specifies wether to truncate the data to [a, b], For example, If sfrom == [a, b] and ‘istrunc’ is true, then X[X < a] == a and X[X > b] == b.
  • rich (bool) – If you want to see what the data is scaled from and scaled to, then you should set it to true
Returns:

  • out (ndarray) – Scaled data array.
  • sfrom, sto (list or tuple) – If rich is true, they will also be returned

pysparse.utils.show module

pysparse.utils.show.showdict(D, rcsize=None, stride=None, plot=True, bgcolorv=0, cmap=None, title=None, xlabel=None, ylabel=None)[source]

Trys to show image blocks in one image.

Parameters:
  • D (array_like) – Blocks to be shown, a bH-bW-bC-bN numpy ndarray.
  • rcsize (int tuple or None, optional) – Specifies how many rows and cols of blocks that you want to show, e.g. (rows, cols). If not given, rcsize=(rows, clos) will be computed automaticly.
  • stride (int tuple or None, optional) – The step size (blank pixels nums) in row and col between two blocks. If not given, stride=(1,1).
  • plot (bool, optional) – True for ploting, False for silent and returns a H-W-C numpy ndarray for showing.
  • bgcolorv (float or None, optional) – The background color, 1 for white, 0 for black. Default, 0.
Returns:

out – A H-W-C numpy ndarray for showing.

Return type:

ndarray or bool

See also

odctdict.()

Examples

>>> D = pys.odctdict((M, N))
>>> showdict(D, bgcolor='k')

Module contents