Skip to main content

Speed up coding/extending image analysis in Python.

Project description

BSD 3-Clause License Python package index download statistics PyPI version

impy

impy is an all-in-one multi-dimensional image analysis library. The core array, ImgArray, is a subclass of numpy.ndarray, tagged with information such as:

  • image axes
  • scale of each axis
  • directory of the original image
  • and other image metadata

Documentation

Documentation is available here.

Installation

  • use pip
pip install impy-array
pip install impy-array[tiff]    # with supports for reading/writing .tif files
pip install impy-array[mrc]     # with supports for reading/writing .mrc files
pip install impy-array[napari]  # viewer support
pip install impy-array[all]     # install everything
  • from source
git clone https://github.com/hanjinliu/impy

Code as fast as you speak

Almost all the functions, such as filtering, deconvolution, labeling, single molecule detection, and even those pure numpy functions, are aware of image metadata. They "know" which dimension corresponds to "z" axis, which axes they should iterate along or where to save the image. As a result, your code will be very concise:

import impy as ip
import numpy as np

img = ip.imread("path/to/image.tif")   # Read images with metadata.
img["z=3;t=0"].imshow()                # Plot image slice at z=3 and t=0.
img["y=N//4:N//4*3"].imshow()          # `N` for the size of the axis.
img_fil = img.gaussian_filter(sigma=2) # Paralell batch denoising. No more for loop!
img_prj = np.max(img_fil, axis="z")    # Z-projection (numpy is aware of image axes!).
img_prj.imsave("image_max.tif")        # Save in the same place. Don't spend time on searching for the directory!

Supports many file formats

impy automatically chooses the proper reader/writer according to the extension.

  • Tiff file (".tif", ".tiff")
  • LSM file (".lsm")
  • MRC file (".mrc", ".rec", ".st", ".map", ".map.gz")
  • Zarr file (".zarr")
  • ND2 file (".nd2")
  • Other image file (".png", ".jpg")

Lazy loading

With the lazy submodule, you can easily make image processing workflows for large images.

import impy as ip

img = ip.lazy.imread("path/to/very-large-image.tif")
out = img.gaussian_filter()
out.imsave("image_filtered.tif")

Switch between CPU and GPU

impy can internally switches the functions between numpy and cupy.

img.gaussian_filter()  # <- CPU
with ip.use("cupy"):
    img.gaussian_filter()  # <- GPU
ip.Const["RESOURCE"] = "cupy"  # <- globally use GPU

Seamless interface between napari

napari is an interactive viewer for multi-dimensional images. impy has a simple and efficient interface with it, via the object ip.gui. Since ImgArray is tagged with image metadata, you don't have to care about axes or scales. Just run

ip.gui.add(img)

Extend your function for batch processing

Already have a function for numpy and scipy? Decorate it with @ip.bind

@ip.bind
def imfilter(img, param=None):
    # Your function here.
    # Do something on a 2D or 3D image and return image, scalar or labels
    return out

and it's ready for batch processing!

img.imfilter(param=1.0)

Command line usage

impy also supports command-line-based image analysis. All methods of ImgArray are available from the command line, such as

impy path/to/image.tif ./output.tif --method gaussian_filter --sigma 2.0

which is equivalent to

import impy as ip
img = ip.imread("path/to/image.tif")
out = img.gaussian_filter(sigma=2.0)
out.imsave("./output.tif")

For more complex procedures, it is possible to send images directly to IPython

impy path/to/image.tif -i
thr = img.gaussian_filter().threshold()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

impy_array-2.5.1.tar.gz (156.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

impy_array-2.5.1-py3-none-any.whl (185.5 kB view details)

Uploaded Python 3

File details

Details for the file impy_array-2.5.1.tar.gz.

File metadata

  • Download URL: impy_array-2.5.1.tar.gz
  • Upload date:
  • Size: 156.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for impy_array-2.5.1.tar.gz
Algorithm Hash digest
SHA256 3e4dc996d48020211e766a0d90472b7f49dd32c150dad42993b163fa5d5e74a2
MD5 cf85586c002eb08fbc1645cf3466b991
BLAKE2b-256 b33b63df50816bbebec5902965467f64ac41bd96a584486c6ac1973e2ab03e4e

See more details on using hashes here.

File details

Details for the file impy_array-2.5.1-py3-none-any.whl.

File metadata

  • Download URL: impy_array-2.5.1-py3-none-any.whl
  • Upload date:
  • Size: 185.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for impy_array-2.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6c974cd27f09530ecbacf2ecb143822f833ff81b599318f22cdfce32dee51614
MD5 9082fbf8d8fd9b6bf09787d75507c78e
BLAKE2b-256 4a1359943493a646e8018fe2670882f3e868fe2be23e34fb292355c42a7c0274

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page