[](https://mybinder.org/v2/gh/guiwitz/microfilm/master?urlpath=lab)
[](https://github.com/guiwitz/microfilm/actions/workflows/test_build.yml)




# microfilm
This package is a collection of tools to display and analyze 2D and 2D time-lapse microscopy images. In particular it makes it straightforward to create figures containing multi-channel images represented in a *composite* color mode as done in the popular image processing software [Fiji](https://imagej.net/software/fiji/). It also allows to easily complete such figures with standard annotations like **labels** and **scale bars**. In case of time-lapse data, the figures are turned into **animations** which can be interactively browsed from a Jupyter notebook, saved in standard movie formats (mp4, gif etc.) and completed with **time counters**. Finally, figures and animations can easily be combined into larger **panels**. These main functionalities are provided by the ```microfilm.microplot``` and ```microfilm.microanim``` modules.
Following the model of [seaborn](https://seaborn.pydata.org/index.html), ```microfilm``` is entirely based on [Matplotlib](https://matplotlib.org/) and tries to provide good defaults to produce good microcopy figures *out-of-the-box*. It however also offers complete access to the Matplotlib structures like axis and figures underlying the ```microfilm``` objects, allowing thus for the creation of arbitrarily complex plots.
## Installation
You can install this package directly with pip using:
```
pip install microfilm
```
To get the latest stage of the package with yet unreleased features use:
```
pip install git+https://github.com/guiwitz/microfilm.git
```
To test the package via the Jupyter interface and the notebooks available [here](notebooks) you can create a conda environment using the [environment.yml](binder/environment.yml) file:
```
conda env create -f environment.yml
```
### Optional installs
If you want to use the ```dataset``` submodule (see below in Additional functionalities) and need to handle multipage tiff files or nd2 files, use:
```
pip install "microfilm[multipage]"
```
or
```
pip install "microfilm[nd2]"
```
If you plan to not just use simple plotting but want to create animations, you need to install:
```
pip install "microfilm[animation]"
```
To install all options use:
```
pip install "microfilm[all]"
```
## Simple plot
It is straightforward to create a ready-to-use plot of a multi-channel image dataset. In the following code snippet, we load a Numpy array of a multi-channel time-lapse dataset with shape ```CTXY``` (three channels). The figure below showing the time-point ```t=10``` is generated in a single command with a few options and saved as a png:
```python
import numpy as np
import skimage.io
from microfilm.microplot import microshow
image = skimage.io.imread('../demodata/coli_nucl_ori_ter.tif')
time = 10
microim = microshow(
images=image[:, time, :, :], fig_scaling=5,
cmaps=['pure_blue','pure_red', 'pure_green'],
unit='um', scalebar_size_in_units=3, scalebar_unit_per_pix=0.065, scalebar_font_size=20,
label_text='A', label_font_size=0.04)
microim.savefig('../illustrations/composite.png', bbox_inches = 'tight', pad_inches = 0, dpi=600)
```
<img src="https://github.com/guiwitz/microfilm/raw/master/illustrations/composite.png" alt="image" width="300">
## Animation
It is then easy to extend a simple figure into an animation as both objects take the same options. Additionally, a time-stamp can be added to the animation. This code generates the movie visible below:
```python
import numpy as np
import skimage.io
from microfilm.microanim import Microanim
image = skimage.io.imread('../demodata/coli_nucl_ori_ter.tif')
microanim = Microanim(data=image, cmaps=['pure_blue','pure_red', 'pure_green'], fig_scaling=5,
unit='um', scalebar_size_in_units=3, scalebar_unit_per_pix=0.065,
scalebar_thickness=0.02, scalebar_font_size=20)
microanim.add_label('A', label_font_size=30)
microanim.add_time_stamp('T', 10, location='lower left', timestamp_size=20)
microanim.save_movie('../illustrations/composite_movie.gif', fps=15)
```
<img src="https://github.com/guiwitz/microfilm/raw/master/illustrations/composite_movie.gif" alt="image" width="300">
## Panels
Both simple figures and animations can be combined into larger panels via the ```microplot.Micropanel``` and ```microanim.Microanimpanel``` objects. For example we can first create two figures ```microim1``` and ```microim2``` and then combine them into ```micropanel```:
```python
from microfilm import microplot
import skimage.io
image = skimage.io.imread('../demodata/coli_nucl_ori_ter.tif')
microim1 = microplot.microshow(images=[image[0, 10, :, :], image[1, 10, :, :]],
cmaps=['Greys', 'pure_magenta'], flip_map=[False, False],
label_text='A', label_color='black')
microim2 = microplot.microshow(images=[image[0, 10, :, :], image[2, 10, :, :]],
cmaps=['Greys', 'pure_cyan'], flip_map=[False, False],
label_text='B', label_color='black')
micropanel = microplot.Micropanel(rows=1, cols=2, figsize=[4,3])
micropanel.add_element(pos=[0,0], microim=microim1)
micropanel.add_element(pos=[0,1], microim=microim2)
micropanel.savefig('../illustrations/panel.png', bbox_inches = 'tight', pad_inches = 0, dpi=600)
```
<img src="https://github.com/guiwitz/microfilm/raw/master/illustrations/panel.png" alt="image" width="300">
And similarly for animations:
```python
from microfilm import microanim
import skimage.io
image = skimage.io.imread('../demodata/coli_nucl_ori_ter.tif')
microanim1 = microanim.Microanim(data=image[[0,1],::], cmaps=['Greys', 'pure_magenta'],
flip_map=[False, False], label_text='A', label_color='black')
microanim2 = microanim.Microanim(data=image[[0,2],::], cmaps=['Greys', 'pure_cyan'],
flip_map=[False, False], label_text='B', label_color='black')
microanim1.add_time_stamp(unit='T', unit_per_frame='3', location='lower-right', timestamp_color='black')
animpanel = microanim.Microanimpanel(rows=1, cols=2, figsize=[4,3])
animpanel.add_element(pos=[0,0], microanim=microanim1)
animpanel.add_element(pos=[0,1], microanim=microanim2)
animpanel.save_movie('../illustrations/panel.gif')
```
<img src="https://github.com/guiwitz/microfilm/raw/master/illustrations/panel.gif" alt="image" width="300">
## Additional functionalities
In addition to these main plotting capabilities, the packages also offers:
- ```microfilm.colorify```: a series of utility functions used by the main functions to create the composite color images. It contains functions to create colormaps, to turn 2D arrays into 3D-RGB arrays with appropriate colormaps etc.
- ```microfilm.dataset```: a module offering a simple common data structure to handle multi-channel time-lapse data from multipage tiffs, series of tiff files, Nikon ND2 files, H5 and Numpy arrays. Requirement to use this module are at the moment very constrained (e.g. dimension order of Numpy arrays, name of H5 content etc.) but might evolve in the future.
## Authors
This package has been created by Guillaume Witz, Microscopy Imaging Center and Science IT Support, University of Bern.
Raw data
{
"_id": null,
"home_page": "https://github.com/guiwitz/microfilm",
"name": "microfilm",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Guillaume Witz",
"author_email": "guillaume.witz@math.unibe.ch",
"download_url": "https://files.pythonhosted.org/packages/4c/d6/77eba72a829355717fd167a057ae86d2e815e3e8bfe59c0e05de0498cd33/microfilm-0.3.0.tar.gz",
"platform": null,
"description": "[](https://mybinder.org/v2/gh/guiwitz/microfilm/master?urlpath=lab)\n[](https://github.com/guiwitz/microfilm/actions/workflows/test_build.yml)\n\n\n\n\n# microfilm\n\nThis package is a collection of tools to display and analyze 2D and 2D time-lapse microscopy images. In particular it makes it straightforward to create figures containing multi-channel images represented in a *composite* color mode as done in the popular image processing software [Fiji](https://imagej.net/software/fiji/). It also allows to easily complete such figures with standard annotations like **labels** and **scale bars**. In case of time-lapse data, the figures are turned into **animations** which can be interactively browsed from a Jupyter notebook, saved in standard movie formats (mp4, gif etc.) and completed with **time counters**. Finally, figures and animations can easily be combined into larger **panels**. These main functionalities are provided by the ```microfilm.microplot``` and ```microfilm.microanim``` modules.\n\nFollowing the model of [seaborn](https://seaborn.pydata.org/index.html), ```microfilm``` is entirely based on [Matplotlib](https://matplotlib.org/) and tries to provide good defaults to produce good microcopy figures *out-of-the-box*. It however also offers complete access to the Matplotlib structures like axis and figures underlying the ```microfilm``` objects, allowing thus for the creation of arbitrarily complex plots.\n\n## Installation\n\nYou can install this package directly with pip using: \n\n```\npip install microfilm\n```\n\nTo get the latest stage of the package with yet unreleased features use:\n\n```\npip install git+https://github.com/guiwitz/microfilm.git\n```\n\nTo test the package via the Jupyter interface and the notebooks available [here](notebooks) you can create a conda environment using the [environment.yml](binder/environment.yml) file:\n\n```\nconda env create -f environment.yml\n```\n\n### Optional installs\n\nIf you want to use the ```dataset``` submodule (see below in Additional functionalities) and need to handle multipage tiff files or nd2 files, use:\n\n```\npip install \"microfilm[multipage]\"\n```\n\nor \n\n```\npip install \"microfilm[nd2]\"\n```\n\nIf you plan to not just use simple plotting but want to create animations, you need to install:\n\n```\npip install \"microfilm[animation]\"\n```\n\nTo install all options use:\n\n```\npip install \"microfilm[all]\"\n```\n\n## Simple plot\n\nIt is straightforward to create a ready-to-use plot of a multi-channel image dataset. In the following code snippet, we load a Numpy array of a multi-channel time-lapse dataset with shape ```CTXY``` (three channels). The figure below showing the time-point ```t=10``` is generated in a single command with a few options and saved as a png:\n\n```python\nimport numpy as np\nimport skimage.io\nfrom microfilm.microplot import microshow\n\nimage = skimage.io.imread('../demodata/coli_nucl_ori_ter.tif')\ntime = 10\n\nmicroim = microshow(\n images=image[:, time, :, :], fig_scaling=5,\n cmaps=['pure_blue','pure_red', 'pure_green'],\n unit='um', scalebar_size_in_units=3, scalebar_unit_per_pix=0.065, scalebar_font_size=20,\n label_text='A', label_font_size=0.04)\n\nmicroim.savefig('../illustrations/composite.png', bbox_inches = 'tight', pad_inches = 0, dpi=600)\n```\n\n<img src=\"https://github.com/guiwitz/microfilm/raw/master/illustrations/composite.png\" alt=\"image\" width=\"300\">\n\n## Animation\n\nIt is then easy to extend a simple figure into an animation as both objects take the same options. Additionally, a time-stamp can be added to the animation. This code generates the movie visible below:\n\n```python\nimport numpy as np\nimport skimage.io\nfrom microfilm.microanim import Microanim\n\nimage = skimage.io.imread('../demodata/coli_nucl_ori_ter.tif')\n\nmicroanim = Microanim(data=image, cmaps=['pure_blue','pure_red', 'pure_green'], fig_scaling=5,\n unit='um', scalebar_size_in_units=3, scalebar_unit_per_pix=0.065,\n scalebar_thickness=0.02, scalebar_font_size=20)\n\nmicroanim.add_label('A', label_font_size=30)\nmicroanim.add_time_stamp('T', 10, location='lower left', timestamp_size=20)\n\nmicroanim.save_movie('../illustrations/composite_movie.gif', fps=15)\n```\n\n<img src=\"https://github.com/guiwitz/microfilm/raw/master/illustrations/composite_movie.gif\" alt=\"image\" width=\"300\">\n\n## Panels\n\nBoth simple figures and animations can be combined into larger panels via the ```microplot.Micropanel``` and ```microanim.Microanimpanel``` objects. For example we can first create two figures ```microim1``` and ```microim2``` and then combine them into ```micropanel```:\n\n```python\nfrom microfilm import microplot\nimport skimage.io\n\nimage = skimage.io.imread('../demodata/coli_nucl_ori_ter.tif')\n\nmicroim1 = microplot.microshow(images=[image[0, 10, :, :], image[1, 10, :, :]],\n cmaps=['Greys', 'pure_magenta'], flip_map=[False, False],\n label_text='A', label_color='black')\nmicroim2 = microplot.microshow(images=[image[0, 10, :, :], image[2, 10, :, :]],\n cmaps=['Greys', 'pure_cyan'], flip_map=[False, False],\n label_text='B', label_color='black')\n\nmicropanel = microplot.Micropanel(rows=1, cols=2, figsize=[4,3])\n\nmicropanel.add_element(pos=[0,0], microim=microim1)\nmicropanel.add_element(pos=[0,1], microim=microim2)\n\nmicropanel.savefig('../illustrations/panel.png', bbox_inches = 'tight', pad_inches = 0, dpi=600)\n```\n\n<img src=\"https://github.com/guiwitz/microfilm/raw/master/illustrations/panel.png\" alt=\"image\" width=\"300\">\n\nAnd similarly for animations:\n\n```python\nfrom microfilm import microanim\nimport skimage.io\n\nimage = skimage.io.imread('../demodata/coli_nucl_ori_ter.tif')\n\nmicroanim1 = microanim.Microanim(data=image[[0,1],::], cmaps=['Greys', 'pure_magenta'],\n flip_map=[False, False], label_text='A', label_color='black')\nmicroanim2 = microanim.Microanim(data=image[[0,2],::], cmaps=['Greys', 'pure_cyan'],\n flip_map=[False, False], label_text='B', label_color='black')\n\nmicroanim1.add_time_stamp(unit='T', unit_per_frame='3', location='lower-right', timestamp_color='black')\n\nanimpanel = microanim.Microanimpanel(rows=1, cols=2, figsize=[4,3])\nanimpanel.add_element(pos=[0,0], microanim=microanim1)\nanimpanel.add_element(pos=[0,1], microanim=microanim2)\n\nanimpanel.save_movie('../illustrations/panel.gif')\n```\n\n<img src=\"https://github.com/guiwitz/microfilm/raw/master/illustrations/panel.gif\" alt=\"image\" width=\"300\">\n\n## Additional functionalities\n\nIn addition to these main plotting capabilities, the packages also offers:\n- ```microfilm.colorify```: a series of utility functions used by the main functions to create the composite color images. It contains functions to create colormaps, to turn 2D arrays into 3D-RGB arrays with appropriate colormaps etc.\n- ```microfilm.dataset```: a module offering a simple common data structure to handle multi-channel time-lapse data from multipage tiffs, series of tiff files, Nikon ND2 files, H5 and Numpy arrays. Requirement to use this module are at the moment very constrained (e.g. dimension order of Numpy arrays, name of H5 content etc.) but might evolve in the future.\n\n## Authors\n\nThis package has been created by Guillaume Witz, Microscopy Imaging Center and Science IT Support, University of Bern.\n",
"bugtrack_url": null,
"license": "BSD 3-Clause",
"summary": "Creating figures and animations for multi-channel images with a focus on microscopy.",
"version": "0.3.0",
"project_urls": {
"Homepage": "https://github.com/guiwitz/microfilm"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f317504a5f77bc1998d18761008a400ef096ed66269fb87852aa2f6eb6e9d43c",
"md5": "ebdd7465363894fc60ca62b59364ccf5",
"sha256": "a7efcf3dff964fbcecfbab432d870a376dd52f40c23905cf1573e4eed90db35a"
},
"downloads": -1,
"filename": "microfilm-0.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ebdd7465363894fc60ca62b59364ccf5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 25173,
"upload_time": "2024-12-16T14:30:13",
"upload_time_iso_8601": "2024-12-16T14:30:13.626564Z",
"url": "https://files.pythonhosted.org/packages/f3/17/504a5f77bc1998d18761008a400ef096ed66269fb87852aa2f6eb6e9d43c/microfilm-0.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4cd677eba72a829355717fd167a057ae86d2e815e3e8bfe59c0e05de0498cd33",
"md5": "a8d4f9df97ebac2a7ed962ae9bc8273b",
"sha256": "f06a458234a8bc5fec61eacf7523afbccde660e55b940deea58924a27a7b01ad"
},
"downloads": -1,
"filename": "microfilm-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "a8d4f9df97ebac2a7ed962ae9bc8273b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 83996674,
"upload_time": "2024-12-16T14:30:22",
"upload_time_iso_8601": "2024-12-16T14:30:22.423342Z",
"url": "https://files.pythonhosted.org/packages/4c/d6/77eba72a829355717fd167a057ae86d2e815e3e8bfe59c0e05de0498cd33/microfilm-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-16 14:30:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "guiwitz",
"github_project": "microfilm",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "microfilm"
}