xdesign.plot
¶
Contains functions for visualizing Phantom
and
ImageQuality
metrics.
- DEFAULT_COLOR_MAP
matplotlib.colors.Colormap
The color map used to choose property colors.
- DEFAULT_COLOR
matplotlib.colors
The face color of geometry.
- POLY_COLOR
matplotlib.colors
The face color of polygons.
- DEFAULT_EDGE_COLOR
matplotlib.colors
The color of geometry edges.
- POLY_EDGE_COLOR
matplotlib.colors
The color of polygon edges.
- LABEL_COLOR
matplotlib.colors
The color of number labels on phantom plots.
- POLY_LINEWIDTH
float
The edge width for polygons. See
matplotlib.patches.Patch.set_linewidth()
.- CURVE_LINEWIDTH
float
The edge width for curves. See
matplotlib.patches.Patch.set_linewidth()
.- PLOT_STYLES :
A list of 126 unique line styles.
Module author: Daniel J Ching <carterbox@users.noreply.github.com>
Classes:
Phantom Plotting Functions:
|
Displays the geometry and the discrete property function of the given |
|
Return a discrete map of the property in the phantom. |
|
Plot a |
|
Plot a |
|
Plot a |
|
Plot a |
Metrics Plotting Functions:
|
Plot the coverage anisotropy using 2D glyphs. |
|
Plot full reference metrics of ImageQuality data. |
|
Plot the MTF. |
|
Plot the 2D frequency plot for the NPS. |
|
Plot the NEQ. |
|
Returns a list of pie glyphs at coordinates xy representing values |
- xdesign.plot.combine_grid(Amin, A, Bmin, B)[source]¶
Add grid B to grid A by aligning min corners and clipping B
- Parameters
Amin, Bmin (int tuple) – The coordinates of the minimum corner of A and B
A, B (numpy.ndarray) – The two arrays to add to each other
- Returns
AB (numpy.ndarray) – The combined grid
- Raises
ValueError – If A and B are do not have the same number of dimensions
- xdesign.plot.discrete_geometry(geometry, psize, ratio=9)[source]¶
Draw the geometry onto a patch the size of its bounding box.
- Parameters
geometry (
geometry.Entity
) – A geometric object with dim, bounding_box, and contains methodspsize (float [cm]) – The real size of the pixels in the discrete image
ratio (int (default: 9)) – The supersampling ratio for antialiasing. 1 means no antialiasing
- Returns
corner (1darray [cm]) – The min corner of the patch
patch (ndarray) – The discretized geometry in it’s bounding box
- Raises
ValueError – If ratio is less than 1 or psize is less than or equal to 0.
- xdesign.plot.discrete_phantom(phantom, size, ratio=9, uniform=True, prop='linear_attenuation')[source]¶
Return a discrete map of the property in the phantom.
The values of overlapping
phantom.Phantom
are additive.- Parameters
phantom (
phantom.Phantom
)size (scalar) – The side length in pixels of the resulting 1 by 1 cm image.
ratio (scalar, optional (default: 9)) – The antialiasing works by supersampling. This parameter controls how many pixels in the larger representation are averaged for the final representation. e.g. if ratio = 9, then the final pixel values are the average of 81 pixels.
uniform (boolean, optional (default: True)) – When set to False, changes the way pixels are averaged from a uniform weights to gaussian weigths.
prop (str, optional (default: linear_attenuation)) – The name of the property to discretize
- Returns
image (
numpy.ndarray
) – The discrete representation of thePhantom
that is size x size. 0 if phantom has no geometry or material property.- Raises
ValueError – If size is less than or equal to 0
- xdesign.plot.get_pie_glyphs(xy, values, color='coverage', trace_normal=1, **kwargs)[source]¶
Returns a list of pie glyphs at coordinates xy representing values
The areas of the pie sectors are proportional to the elements of the vector that the glyph represents. The default color of the Glyph is determined by the sum of the values divided by the trace_normal and the
plot.DEFAULT_COLOR_MAP
.- Parameters
xy ((M, 2) float) – Locations of glyph centers
values ((M, N) float) – Bin sizes for each glyph
color (string) –
- coverage
The color is determined by the sum of the values.
- standard deviation
The color is standard deviation of the bins
- Kullback-Leibler
The color is the Kullback-Leibler devation
- random
The color is randomly assigned from the DEFAULT_COLOR_MAP.
trace_normal (float) – A scalar used to normalize the trace for coloring the glyph.
kwargs (dict) – Arguments passed to the patches constructor
See also
- xdesign.plot.multiroll(x, shift, axis=None)[source]¶
Roll an array along each axis.
- Parameters
x (array_like) – Array to be rolled.
shift (sequence of int) – Number of indices by which to shift each axis.
axis (sequence of int, optional) – The axes to be rolled. If not given, all axes is assumed, and len(shift) must equal the number of dimensions of x.
- Returns
y (numpy array, with the same type and size as x) – The rolled array.
Notes
The length of x along each axis must be positive. The function does not handle arrays that have axes with length 0.
See also
Example
Here’s a two-dimensional array:
>>> x = np.arange(20).reshape(4,5) >>> x array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19]])
Roll the first axis one step and the second axis three steps:
>>> multiroll(x, [1, 3]) array([[17, 18, 19, 15, 16], [ 2, 3, 4, 0, 1], [ 7, 8, 9, 5, 6], [12, 13, 14, 10, 11]])
That’s equivalent to:
>>> np.roll(np.roll(x, 1, axis=0), 3, axis=1) array([[17, 18, 19, 15, 16], [ 2, 3, 4, 0, 1], [ 7, 8, 9, 5, 6], [12, 13, 14, 10, 11]])
Not all the axes must be rolled. The following uses the axis argument to roll just the second axis:
>>> multiroll(x, [2], axis=[1]) array([[ 3, 4, 0, 1, 2], [ 8, 9, 5, 6, 7], [13, 14, 10, 11, 12], [18, 19, 15, 16, 17]])
which is equivalent to:
>>> np.roll(x, 2, axis=1) array([[ 3, 4, 0, 1, 2], [ 8, 9, 5, 6, 7], [13, 14, 10, 11, 12], [18, 19, 15, 16, 17]])
References
- xdesign.plot.plot_angle_intensity(angle, intensity, background_color=(0.3, 0.3, 0.3))[source]¶
Plot the phase angle and intensity in the same plot using 2D glyphs.
The glyphs are 120 degree pie glyphs whose orientation and hue are determined by the angle and whose brightness are determined by the intensity.
- xdesign.plot.plot_coverage_anisotropy(coverage_map, **kwargs)[source]¶
Plot the coverage anisotropy using 2D glyphs.
- Parameters
kwargs – Keyword arguments for the Glyphs.
See also
metrics.coverage_approx()
,Glyph
- xdesign.plot.plot_curve(curve, axis=None, alpha=None, c=None)[source]¶
Plot a
Curve
to the given axis.- Parameters
curve (
Curve
) – A Curve to plot on the given axis.axis (
matplotlib.axis.Axis
, optional) – The axis where the Curve should be plotted. None creates a new axis.alpha (
float
, optional) – The plot opaqueness. 0 is transparent. 1 is opaque.c (
matplotlib.colors
, optional) – The color of the plotted curve.
- xdesign.plot.plot_geometry(geometry, axis=None, alpha=None, c=None, z=0.0, t=0.0001)[source]¶
Plot a
Entity
on the given axis.- Parameters
geometry (
Entity
) – A geometry to plot on the given axis.axis (
matplotlib.axis.Axis
, optional) – The axis where the geometry should be plotted. None creates a new axis.alpha (
float
, optional) – The plot opaqueness. 0 is transparent. 1 is opaque.c (
matplotlib.colors
, optional) – The color of the plotted geometry.
- xdesign.plot.plot_mesh(mesh, axis=None, alpha=None, c=None)[source]¶
Plot a
Mesh
to the given axis.- Parameters
mesh (
Mesh
) – A Mesh to plot on the given axis.axis (
matplotlib.axis.Axis
, optional) – The axis where the Mesh should be plotted. None creates a new axis.alpha (
float
, optional) – The plot opaqueness. 0 is transparent. 1 is opaque.c (
matplotlib.colors
, optional) – The color of the plotted Mesh.
- xdesign.plot.plot_metrics(imqual)[source]¶
Plot full reference metrics of ImageQuality data.
- Parameters
imqual (ImageQuality) – The data to plot.
References
Colors taken from this gist
- xdesign.plot.plot_nps(X, Y, NPS)[source]¶
Plot the 2D frequency plot for the NPS. Return the figure reference.
- xdesign.plot.plot_phantom(phantom, axis=None, labels=None, c_props=[], c_map=None, i=- 1, z=0.0, t=0.0001)[source]¶
Plot a
Phantom
to the given axis.- Parameters
phantom (
Phantom
) – A phantom to be plotted.axis (
matplotlib.axis.Axis
) – The axis where the phantom should be plotted. None creates a new axis.labels (bool, optional) – True : Each
Phantom
given a unique number.c_props (list of str, optional) – List of
Phantom
properties to use for colormapping the geometries. [] colors the geometries by type.c_map (function, optional) – A function which takes the list of prop(s) for a
Phantom
as input and returns a matplolib color specifier. [5]
- xdesign.plot.plot_polygon(polygon, axis=None, alpha=None, c=None)[source]¶
Plot a
Polygon
to the given axis.- Parameters
polygon (
Polygon
) – A Polygon to plot on the given axis.axis (
matplotlib.axis.Axis
, optional) – The axis where the Polygon should be plotted. None creates a new axis.alpha (
float
, optional) – The plot opaqueness. 0 is transparent. 1 is opaque.c (
matplotlib.colors
, optional) – The color of the plotted Polygon.