convert
¶
|
Create and return a temporary directory. |
|
Load an image. |
|
Convert a Matplotlib figure to a 3D numpy array with RGBA channels. |
TemporaryDirectory
¶
-
class
fury.convert.
TemporaryDirectory
(suffix=None, prefix=None, dir=None)[source]¶ Bases:
object
Create and return a temporary directory. This has the same behavior as mkdtemp but can be used as a context manager. For .. rubric:: Example
- with TemporaryDirectory() as tmpdir:
…
Upon exiting the context, the directory and everything contained in it are removed.
load_image¶
matplotlib_figure_to_numpy¶
-
fury.convert.
matplotlib_figure_to_numpy
(fig, dpi=100, fname=None, flip_up_down=True, transparent=False)[source]¶ Convert a Matplotlib figure to a 3D numpy array with RGBA channels.
- Parameters
fig (obj) – A matplotlib figure object
dpi (int, optional) – Dots per inch
fname (str, optional) – If
fname
is given then the array will be saved as a png to this position.flip_up_down (bool, optional) – The origin is different from matlplotlib default and VTK’s default behaviour (default True).
transparent (bool, optional) – Make background transparent (default False).
- Returns
arr – a numpy 3D array of RGBA values
- Return type
ndarray
Notes
The safest way to read the pixel values from the figure was to save them using savefig as a png and then read again the png. There is a cleaner way found here http://www.icare.univ-lille1.fr/drupal/node/1141 where you can actually use fig.canvas.tostring_argb() to get the values directly without saving to the disk. However, this was not stable across different machines and needed more investigation from what time permited.