Skip to content

Commit

Permalink
update for v1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjinliu committed May 25, 2021
1 parent fc0d6b3 commit 8513a4c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 59 deletions.
Binary file removed Figs/2021-04-22-21-35-08.png
Binary file not shown.
Binary file added Figs/Img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 73 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,88 @@
# impy

## More Numpy in image analysis!
## More Numpy in Image Analysis!

```python
import impy as ip
img = ip.imread(r"...\images\Image_0.tif")
peaks = img.find_sm(percentile=90)
img.specify(center=peaks, radius=3, labeltype="circle")
img.imshow()
img.imshow_label()
```

![](Figs/2021-04-22-21-35-08.png)
![](Figs/Img.png)

ImageJ is generally used for image analysis especially in biological backgrounds. However, recent demands for batch analysis, machine learning and high reproducibility are usually hard to achieve with ImageJ. On the other hand, the famous image analysis toolkit, [scikit-image](https://github.com/scikit-image/scikit-image), is not suited for biological image analysis because many functions do not support standard multi-dimensional tiff files.

Here with `ImgArray`, this module solved major problems that happens when you code image analysis in Python. Because axial information such as xy plane, channels and time are also included in the arrays, many functions can automatically optimize multi-dimensional image analysis such as filtering, background subtraction and deconvolution. You can also access its contents in an intuitive way called "axis-targeted slicing" like `img["t=1:5;z=4"]`.
This module solves major problems that happens when you code image analysis in Python.

Other types of objects are defined in `impy` for other purposes.
- `ImgArray` is an array mainly used for image analysis here. Many `skimage`'s functions are wrapped in this class.
- `PropArray` is an array that contains properties of another array, such as mean intensities of fixed regions of an array.
- `Label` is also an array type while it is only used for labeling of another image and is always attached to it.
- `PhaseArray` is an array that contains phase information. Unit (radian or degree) and periodicity are always tagged to itself so that you don't need to care about it.
- `PhaseArray` is an array that contains phase values. Unit (radian or degree) and periodicity are always tagged to itself so that you don't need to care about them.
- `MarkerFrame` is a subclass of `pandas.DataFrame` and it is specialized in storing coordinates and markers, such as xyz-coordinates of local maxima. This class also supports axis targeted slicing `df["x=4;y=5"]`.
- `TrackFrame` is quite similar to `MarkerFrame` while it is only retuned when points are linked by particle tracking methods in `trackpy`. It has information of track ID.
- `TrackFrame` is quite similar to `MarkerFrame` while it is only retuned when points are linked by particle tracking. It has information of track ID.

This module also provides many image analysis tools and seamless interface between [napari](https://github.com/napari/napari), which help you to operate with and visualize images, and [trackpy](https://github.com/soft-matter/trackpy), which enables efficient molecule tracking.
This module also provides many image analysis tools and seamless interface between [napari](https://github.com/napari/napari), which help you to operate with and visualize n-D images, and [trackpy](https://github.com/soft-matter/trackpy), which enables efficient molecule tracking.


## Image Analysis Tools

`ImgArray` has a lot of member functions for image analysis. Some of them supports multiprocessing.

- `track_drift`, `drift_correction` → Automatic drift correction.
- `wiener`, `lucy` → Deconvolution of images.
- `pad`, `defocus` → Effective padding.
- `affine_correction` → Correction of such as chromatic aberration using Affine transformation.
- `focus_map` → Find focus using variance of Laplacian method.
- `hessian_eigval`, `hessian_eig` → Feature detection using Hessian method.
- `structure_tensor_eigval`, `structure_tensor_eig` → Feature detection using structure tensor.
- `dog_filter`, `doh_filter`, `log_filter` → Blob detection.
- `mean_filter`, `meadian_filter`, `gaussian_filter` → n-dimensional smoothing.
- `directional_median_filter` → Smoothing without blurring edges.
- `std_filter`, `coef_filter` → Standard deviation based filtering.
- `sobel_filter`, `laplacian_filter` → Edge detection.
- `split_polarization`, `stokes` → Analyze polarization.
- `entropy_filter`, `gabor_filter` → Object detection method.
- `enhance_contrast` → Enhancing contrast.
- `erosion`, `dilation`, `opening`, `closing` → Morphological processing.
- `rolling_ball`, `tophat` → Background subtraction.
- `convolve` → Any convolution.
- `hessian_angle`, `gabor_angle` → Calculate angles of filaments for each pixel.
- `gaussfit`, `gauss_correction` → Fit the image to 2-D Gaussian, and use it for image correction.
- `distance_map`, `skeletonize`, `fill_hole`, `count_neighbors` → Processing binary images.
- `fft`, `ifft` → Fourier transformation.
- `threshold` → Thresholding (many methods included).
- `find_sm`, `peak_local_max`, `corner_peaks` → Find maxima.
- `centroid_sm`, `gauss_sm` → Find single molecule in subpixel precision.
- `label`, `label_threshold`, `specify`, `append_label` → Label images.
- `expand_labels`, `watershed`, `random_walker` → Adjuct/segment labels.
- `extract` → Substitute values that do not satisfy certain condition.
- `regionprops`, `lineprops` → Measure properties on labels/lines.
- `reslice` → Get line scan.
- `lbp`, `glcm`, `glcm_props` → Texture classification.
- `crop_center` → Crop image.
- `clip`, `rescale_intensity` → Rescale the intensity profile into certain range.
- `proj` → Z-projection along any axis.
- `split` → Split the image along any axis.
- **Drift/Aberration Correction**
- `track_drift`, `drift_correction`
- `affine_correction` → Correction of such as chromatic aberration using Affine transformation.

- **3D Deconvolution**
- `wiener`, `lucy`

- **Filters**
- `mean_filter`, `meadian_filter`, `gaussian_filter`, `directional_median_filter` → Smoothing.
- `dog_filter`, `doh_filter`, `log_filter` → Blob detection.
- `sobel_filter`, `laplacian_filter` → Edge detection.
- `std_filter`, `coef_filter` → Standard deviation based filtering.
- `entropy_filter`, `enhance_contrast`, `gabor_filter` → Object detection etc.

- **Morphological Image Processing**
- `erosion`, `dilation`, `opening`, `closing` → Basic ones.
- `area_opening`, `area_closing`, `diameter_opening`, `diameter_closing` → Advanced ones.
- `skeletonize`, `fill_hole` → Binary processing.
- `count_neighbors` → For structure detection in binary images.
- `remove_large_objects`, `remove_fine_objects` `remove_skeleton_structure` → Detect and remove objects.

- **Single Molecule Detection**
- `find_sm`, `peak_local_max` → Return coordinates of single molecules.
- `centroid_sm`, `gauss_sm`, `refine_sm` → Return coordinates in subpixel precision.

- **Background Correction**
- `rolling_ball`, `tophat` → Background subtraction.
- `gaussfit`, `gauss_correction` → Use Gaussian for image correction.

- **Labeling**
- `label`, `label_if`, `label_threshold` → Labeling using binary images.
- `specify` → Labeling around coordinates.
- `append_label` → Label images.
- `expand_labels`, `watershed`, `random_walker` → Adjuct or segment labels.

- **Feature Detection**
- `hessian_eigval`, `hessian_eig` → Hessian.
- `structure_tensor_eigval`, `structure_tensor_eig` → Structure tensor.

- **Filament Angle Estimation**
- `hessian_angle` → Using Hessian eigenvector's orientations.
- `gabor_angle` → Using Gabor filter's responses.

- **Property Measurement**
- `regionprops` → Measure region properties such as mean intensity, Euler number, centroid, moment etc.
- `lineprops`, `pointprops` → Measure line/point properties.

- **Texture Classification**
- `lbp`, `glcm`, `glcm_props`

- **Others**
- `focus_map` → Find focus using variance of Laplacian method.
- `stokes` → Analyze polarization using Stokes parameters.
- `fft`, `ifft` → Fourier transformation.
- `threshold` → Thresholding (many methods included).
- `reslice` → Get line scan.
- `crop_center`, `remove_edges` → Crop image.
- `clip`, `rescale_intensity` → Rescale the intensity profile into certain range.
- `proj` → Z-projection along any axis.
- `split`, `split_pixel_unit` → Split the image.
- `pad`, `defocus` → Padding.

## Brief Examples

Expand Down Expand Up @@ -102,8 +119,9 @@ img
You can also access any parts of image with string that contains axis information.

```python
img_new = img["z=1;t=4,6,8"]
img_new.axes = "p*@e"
img1 = img["z=1;t=4,6,8"]
img1.axes = "p*@e"
img2 = img["z=3:6;t=2:15,18:-1"]
```

#### 3. Axis-Targeted Iteration
Expand Down Expand Up @@ -135,8 +153,9 @@ for (t in t_all) {
```python
img.label_threshold(thr="yen") # Label image using Yen's thresholding
props = img.regionprop(properties=("mean_intensity", "perimeter")) # Measure mean intensity and perimeter for every labeled region
props.perimeter.p() # Plot results of perimeter
props.perimeter.plot() # Plot results of perimeter
props.perimeter["p=10;t=2"] # Get the perimeter of 10-th label in the slice t=2.
fit_result = props.mean_intensity.curve_fit(func) # curve fitting
```

## Basic Functions in impy
Expand Down
2 changes: 1 addition & 1 deletion impy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.7.4"
__version__ = "1.8.0"

import warnings
from .imgarray import (array, zeros, zeros_like, empty, empty_like,
Expand Down
8 changes: 4 additions & 4 deletions impy/phasearray.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ def set_border(self, a, b) -> None:
self.fix_border()
return None

def deg2rad(self) -> None:
def deg2rad(self) -> PhaseArray:
if self.unit == "rad":
raise ValueError("Array is already in radian.")
np.deg2rad(self, out=self.value[:])
self.unit = "rad"
self.border = tuple(np.deg2rad(self.border))
return None
return self

def rad2deg(self) -> None:
def rad2deg(self) -> PhaseArray:
if self.unit == "deg":
raise ValueError("Array is already in degree.")
np.rad2deg(self, out=self.value[:])
self.unit = "deg"
self.border = tuple(np.rad2deg(self.border))
return None
return self

@record()
@dims_to_spatial_axes
Expand Down

0 comments on commit 8513a4c

Please sign in to comment.