Skip to content

Commit

Permalink
version 3.0.0
Browse files Browse the repository at this point in the history
* Staks are now initialized from arrays. Add apply function to stacks.

* adds new methods to the Stack object.

* fix integer index problem

* version 3, updated doc

* Update README.md

* correct typos in readme
  • Loading branch information
mpascucci authored Nov 20, 2021
1 parent 0415249 commit 9afb98c
Show file tree
Hide file tree
Showing 41 changed files with 1,053 additions and 668 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ __pycache__
dist/
.vscode/
build/
.ipynb
.ipynb
examples/Notebook/
228 changes: 13 additions & 215 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,239 +3,37 @@
cite this software:
[![DOI](https://zenodo.org/badge/166888905.svg)](https://zenodo.org/badge/latestdoi/166888905)

`multipagetiff` is a python module that makes easier working with multipage images (stacks). Image stacks are often found as multi-page tiff files.
`multipagetiff` is a python module that simplifies working with multipage images (stacks). Image stacks are often found as multi-page tiff files.

With this module one can read, manipulate and display multi-page tiff files and apply depth color-coding by max-projection, like the Z-projection functions of ImageJ.
With this module one can read/write, manipulate and display multi-page tiff files and apply depth color-coding by max-projection, like the Z-projection functions of ImageJ.

# Install
instal with `pip`
```sh
pip install multipagetiff
```

## Usage example
```python
from matplotlib import pyplot as plt
import multipagetiff as tiff
Or, in order to get the latest version, install it from git
```

## load a stack
Load a stack and display its frames.
The stack here is the 3D image of an actin filament imaged with a super-resolution specle microscope ([M.Pascucci et al. 2019 Nat. Com.](https://www.nature.com/articles/s41467-019-09297-5.pdf?origin=ppub)).


```python
plt.figure(figsize=(7,7))
# Load the stack and define the resolution and the units
s = tiff.Stack("actin_filament.tif", dx=10, dz=50, units='nm')
# The frames to display can be specified with the frames parameter
# e.g. frames=range(5,15)
tiff.plot_frames(s, cmap='gray')
pip install git+git://github.com/mpascucci/multipagetiff.git
```

## Usage example


![png](imgs/output_4_0.png)


## Slicing and accessing single pages
A Stack objects is an Iterable and it can be sliced (eg`s[0:4]` will return the pages 0 to 3 as numpy array)

Numpy methods can be called on `s.pages` or simply `s[:]`.
For example, the mean image of the stack can be calculated as follows:
```
mean_img = s.pages.mean(axis=0))
```
or
```
mean_img = s[:].mean(axis=0))
```
# z max-projection

## z max-projection
Have a look at the [cookbook](examples/markdown/example.md), it contains examples and explications for a quick start.

The following is a very short example of a depth colored z max-projection of an image stack:

```python
import multipagetiff as mtif
# set the colormap
tiff.set_cmap(plt.cm.cool)
s = mtif.read_stack("actin_filament.tif", dx=10, dz=50, units='nm')
mtif.set_cmap(plt.cm.cool)
# plot the stack
tiff.plot_flatten(s)
mtif.plot_flatten(s)
```



![png](imgs/output_6_0.png)



## Refine the image


```python
# set XY crop area
s.crop = [50,50,270,270]

# set Z range
s.set_start_in_units(-550)
s.set_end_in_units(700)

# plot with threshold
tiff.plot_flatten(s, threshold=0.25)
```



![png](imgs/output_8_0.png)



---

## Detailed example


```python
st = tiff.Stack('Stack.tiff', dx=1, dz=1, z_label='depth', units='mm')

print("the stack has {} pages".format(len(st))) # number of frames
```

the stack has 3 pages


## plot a stack

Plot page by page. The Stack object behaves like a list, which elements are the frames


```python
plt.subplot(1,3,1)
plt.imshow(st[0], cmap='gray')
plt.subplot(1,3,2)
plt.imshow(st[1], cmap='gray')
plt.subplot(1,3,3)
plt.imshow(st[2], cmap='gray')
plt.tight_layout()
```



![png](imgs/output_14_0.png)



Display the frame of the stack with the plot_frames function


```python
tiff.plot_frames(st, cmap='gray')
```



![png](imgs/output_16_0.png)



## color code


```python
cc = tiff.color_code(st)
![png](examples/markdown/output_24_0.png)

plt.subplot(1,3,1)
plt.imshow(cc[0])
plt.subplot(1,3,2)
plt.imshow(cc[1])
plt.subplot(1,3,3)
plt.imshow(cc[2])
plt.tight_layout()
```



![png](imgs/output_18_0.png)




```python
# If you need to print only a part of the stack, select it with
# st.set_start_in_units(start) and st.set_end_in_units(end)

tiff.plot_frames(st, colorcoded=True)
```



![png](imgs/output_19_0.png)



## max projection

Create a color coded RGB image representing frame-depth. The image is the max projection of the color coded stack.


```python
mp = tiff.flatten(st)
plt.imshow(mp)
```




<matplotlib.image.AxesImage at 0x7fb8d639a3a0>





![png](imgs/output_22_1.png)



plot the max projection, together with its colorbar


```python
tiff.plot_flatten(st)
```



![png](imgs/output_24_0.png)



## change colormap

Use a matplotlib preset colormap


```python
tiff.set_cmap(plt.cm.cool)
tiff.plot_flatten(st)
```



![png](imgs/output_27_0.png)



or define you own colormap


```python
from matplotlib.colors import LinearSegmentedColormap

my_colors = [(1,0,0),(0,1,0),(0.0,0.5,1)]
my_cmap = LinearSegmentedColormap.from_list("myCmap", my_colors, N=256)
tiff.set_cmap(my_cmap)
tiff.plot_flatten(st)
```



![png](imgs/output_29_0.png)

6 changes: 3 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Multi-page TIFF

![image](https://github.com/mpascucci/multipagetiff/raw/master/imgs/output_19_0.png)
![image](https://raw.githubusercontent.com/mpascucci/multipagetiff/dev/examples/markdown/output_45_0.png)

This module module makes easy dealing with multi-page tiff images stacks.
This module simplifies working with multipage images (stacks). Image stacks are often found as multi-page tiff files.

It implements depth color-coding by max-projection, like the Z-projection functions of ImageJ.

Detailed description on the [GitHub project page](https://github.com/mpascucci/multipagetiff/blob/master/README.md).

typical import line:
```python
import multipagetiff as tiff
import multipagetiff as mtif
```

Binary file not shown.
Loading

0 comments on commit 9afb98c

Please sign in to comment.