File: image.rst

package info (click to toggle)
python-rosettasciio 0.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 144,644 kB
  • sloc: python: 36,638; xml: 2,582; makefile: 20; ansic: 4
file content (57 lines) | stat: -rw-r--r-- 1,974 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
.. _image-format:

Image formats
-------------

RosettaSciIO can read and write data to `all the image formats
<https://imageio.readthedocs.io/en/stable/formats/index.html>`_ supported by
`imageio <https://imageio.readthedocs.io/en/stable/>`_, which uses the 
`Python Image Library (PIL/pillow) <https://pillow.readthedocs.io/en/stable/>`_.
This includes ``.jpg``, ``.gif``, ``.png``, ``.pdf``, ``.tif``, etc.
It is important to note that these image formats only support 8-bit files, and
therefore have an insufficient dynamic range for most scientific applications.
It is therefore highly discouraged to use any general image format to store data
for analysis purposes (with the exception of the :ref:`tiff-format`, which uses
the separate ``tiffile`` library).

.. note::
   To read this format, the optional dependency ``imageio`` is required.

API functions
^^^^^^^^^^^^^

.. automodule:: rsciio.image
   :members:

Examples of saving arguments
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

When saving an image, a scalebar can be added to the image and the formatting,
location, etc. of the scalebar can be set using the ``scalebar_kwds``
arguments:

.. code-block:: python

    >>> from rsciio.image import file_writer
    >>> file_writer('file.jpg', signal, scalebar=True)
    >>> file_writer('file.jpg', signal, scalebar=True, scalebar_kwds={'location':'lower right'})

.. note::
   To add ``scalebar``, the optional dependency ``matplotlib-scalebar`` is
   required.

In the example above, the image is created using
:py:func:`~.matplotlib.pyplot.imshow`, and additional keyword arguments can be
passed to this function using ``imshow_kwds``. For example, this can be used
to save an image displayed using the matplotlib colormap ``viridis``:

.. code-block:: python

    >>> file_writer('file.jpg', signal, imshow_kwds=dict(cmap='viridis'))


The resolution of the exported image can be adjusted:

.. code-block:: python

    >>> file_writer('file.jpg', signal, output_size=512)