Speed up coding/extending image analysis in Python.
BSD-3-CLAUSE License
Published by hanjinliu almost 3 years ago
ImgArray.imsave
now can save .mrc file if file extension is specified.smooth_mask
in ImgArray
for creating soft masks..map
file using mrcfile
.ip.zeros
.read_meta
faster.proj
and binning
for better performance.cupy
.pandas
and dask
.napari==0.4.13
LazyImgArray
, img.compute()
should be used in place of img.data
because there is no reason to use different name as dask
.LazyImgArray
, img.value
should be used in place of img.img
for compatibility with ImgArray
.Published by hanjinliu almost 3 years ago
fft
and ifft
returned wrong results if image has axes other than spatial dimensions.impy.random
is no longer an Random
object but now its a submodule. No API change.random_uint8
and random_uint16
, for easier random image generation.imsave
.scale_unit
to "px"
if exception happened.Published by hanjinliu almost 3 years ago
fft
, power_spectra
and local_dft
, you can set double_precision=True
to force float64 and complex128 calculation because single precision sometimes causes non-negligible errors.local_dft
is minimized by considering periodicity of exponential function. The error between local_dft
and fft
are now completely even.lowpass_filter
, highpass_filter
did not work on such as "tyx"
and "zcyx"
images.__turediv__
was incompatible with complex images.enhance_contrast
was incompatible with float images.LazyImgArray
behaved in slightly different ways compared to ImgArray
.Published by hanjinliu almost 3 years ago
napari
because it became incompatible with current version.numpy
inherited functions such as ip.empty
.Published by hanjinliu almost 3 years ago
"<"
are all changed to "a"
.img.shape
now returns namedtuple
(AxesShape
) object.napari
.float32
in FFT based filters.np.memmap
and tempfile
in LazyImgArray
's release
and imsave
methods and the performance is largely improved.ScaleDict
support __setitem__
and __setattr__
.label_multiostu
and slic
methods because they are unstable.ifft
was not correct.cupy
.Published by hanjinliu about 3 years ago
In this release I updated for napari==0.4.11
and improved some UI.
napari==0.4.11
.Published by hanjinliu about 3 years ago
ip.gui.bind_protocol
, then key bindings and parameter container are updated automatically.register_point
and register_shape
. The layers are linked to the result tables.ip.gui.results
are updated to this widgets but API does not change.Axes.scale
uses ScaleDict
now. You can get scales by such as img.scale.x
instead of img.scale["x"]
. ScaleDict
is also compatible with scale parameter in Affine transformation, so that it can directly passed to them like viewer.add_image(img, scale=img.scale)
.Published by hanjinliu about 3 years ago
In this release new widgets are added and existing widgets are improved a lot.
ip.gui.bind
is called and when logger is accessed via ip.gui.log
.ip.gui.bind
now can make custom functions with parameter inputs. It automatically adds a parameter controller widget to the active viewer.ip.gui.bind
now has access to the table widget and the log widget in the viewer.ip.gui.goto
method makes it easier to change the current slice.LabeledArray
now inherit copy (not pointer) of metadata from previous array.pandas.read_csv
and directly convert it to table.ip.imread_collection
can read images from list of paths.ip.imread
.Published by hanjinliu about 3 years ago
The biggest update in v1.20 is ip.gui.bind
method. You can make interactive plugins very easily now.
ip.gui.bind
.ip.gui.get
method enables getting certain type of layer's data very easily.ip.gui.current_slice
property enables getting slice from viewer very easily.[
and ]
had a bug. → fixed.imsave
. → fixed.dask.cache
is moved into try/except in case Cachey
is not installed.apply_dask
had a serious bug such as when multidimensional hessian_eigval
is called. → fixed.LabeledArray.extract
no longer supports crop=False
because it is not useful and almost independent of crop=True
.ImgArray.rotate
and ImgArray.scale
was wrong. → fixed.Published by hanjinliu about 3 years ago
In this release I implemented a lot of new features concerned to napari
viewer. Lots of new widgets and key bindings. You can find them in the "Functions" menu in the menu bar.
Shapes
and Points
layers. You can edit texts of selected shapes/points easily.Alt
+ right click.napari
viewer (change img.labels
in place).regionprops
in viewer and add the result directly to the Labels
layer's properties.add_surface
function to convert 3D images into Surface
layers.__getitem__
in function handler using input like ["y=10:40"]
.Shapes
or Points
layer is selected, you can focus on the previous/next object by pressing [
or ]
.ip.gui.add(path)
.ip
is added in the global namespace by default inside napari
's console if it is started from start.py
.LazyImgArray.drift_correction
's graph construction is much faster now by moving variable shift
into the local warp
function.threshold
's argument is changed: dims
→ along
, for compatibility with other functions.local_dft
, local_power_spectra
for fast up-sampling Fourier transformation.opening
function in Label
.Published by hanjinliu over 3 years ago
track_drift
, drift_correction
→ Both works totally lazily with specialized implementation.erosion
, dilation
, opening
and closing
.fft
, ifft
and power_spectra
.wiener
and lucy
. lucy_tv
is not implemented because it evaluate total variance for every iteration.Published by hanjinliu over 3 years ago
cupy
are now supported! You can conduct Affine transformation, deconvolution and many filter functions with GPU. Arrays are converted inside the functions so that you don't have to care about the difference between numpy
and cupy
.for_params
can run same function with different parameter inputs. No for-loop anymore!skimage
or napari
.DataList
inherits UserList
now. All the list
methods are compatible.DataDict
is defined in place of ArrayDict
and FrameDict
.DataList
is returned in split
.LazyImgArray
directly with imsave
method now.dict
now. You can update them with such as ip.Const["MAX_GB"] = 3.0
or with context manager with ip.SetConst("MAX_GB", 3.0): ...
.shape=
to specify output shape.ncc
→ ncc_filter
.mrcfile
read images as read-only array, which made it incompatible with some functions. This problem is fixed by explicitly set mode="r+"
.fill_hole
did not work since dask
is integrated as multiprocessing. Now fixed.rotated_crop
in LazyImgArray
, or corresponding rotated cropping in viewers returned wrong shape of arrays. This is fixed now.Published by hanjinliu over 3 years ago
LazyImgArray
ImgArray
-- rotated_crop
, crop_center
, binning
, proj
, gaussian_filter
, median_filter
, convolve
, edge_filter
and reslice
. dask
arrays are rechunked automatically to make function running efficiently. Some function are dependent on dask_image
.as_uint8
, as_uint16
. Be careful these functions do not work exactly in a same way as those in ImgArray
. Because dask
must be evaluated in if
, they cannot check whether a float image is in range of [0, 1].ImgArray
proj
has a new option mask=...
. You can mask input image and calculate projection without the masked region. This is useful when you want to exclude outliers in the image from its projection.__getitem__
is safer for images without axes.multiprocess
methods are translated to dask
methods, with function apply_dask
. Accordingly, parallel
, parallel_eig
, n_cpu
are deleted.napari
viewerAlt
.ip.imread
and ip.lazy_imread
now supports squeezing arrays as an option. This is useful when there is only one image file in a folder.ip.set_verbose
no longer works. Change it by ip.SHOW_PROGRESS = False
or ip.MAX_GB = 3.0
directly.AxesMixin
. MetaArray
and LazyImgArray
inherit it.ip.imread
and evaluation functions in LazyImgArray
always raise MemoryError
if the expected size exceeds ip.MAX_GB
.reslice
in viewer to make a kymograph.@record
because they are redundant.mapping
in ip.bind
is deprecated because it is useless.Published by hanjinliu over 3 years ago
imread_collection
and imread_stack
cannot be called now. Use imread
instead. Also, how to recursively read images is changed to pims
-like format, i.e., write the wildcard string directly as a path e.g. >>> ip.imread(r"C:\...\**\*.tif")
.imread_collection
now works as an I/O function for reading images with different shapes and storing them in DataList
.mrcfile
is installed. Metadata is stored in tif-friendly format.napari
viewer (Ctrl
+ Shift
+ X
) can use rotated rectangles. It is achieved by ndi.map_coordinates
rather than rotating the whole image.Alt
or Ctrl
+Alt
, similar to PowerPoint.imread(..., key="...")
, lazy_imread
for reading large datasets.DataList
for batch processing images with different shapes.LazyImgArray
for handling lazy reading and previewing using dask
.radial_profile
can calculate radial profile P(r) of images.power_spectra
can calculate FFT power spectra image directly.gaussian_filter
, are faster with single thread so that they are never conducted with multi-processing.napari
viewer now support handling LazyImgArray
as dask
input, and DataList
by adding all the contents.regionprops
could have not be calculated since numpy
function is overloaded for ImgArray
. This problem is fixed.binning
was not true binning because affine transformation is not same as binning. Now binning
returns correct results, and you can also use other reduce functions such as np.median
for binning.dirpath
and scale
of images. This problem is now fixed for both MetaArray
s and dask.arrays.core.Array
.Published by hanjinliu over 3 years ago
tile
function for image tiling. Overlap is not considered for now.lowpass_filter
and highpass_filter
. Similar functions will be imported from skimage.filters
after v0.19 is available.binning
function for image binning like 2x2 or 4x4. Divisibility is required unlike rescale
.for_each_channel
enables different parameter inputs for different channel. Until v1.13, you needed to split channels, apply function for each channel, and stack them again. Now you only have to call for_each_channel
.kalman_filter
for smoothing of time-series image stacks. This function is identical to "Kalman Stack Filter" in ImageJ.PathFrame
that contains paths, similar to TrackFrame
.pathprops
can measure path properties like regionprops
.imread
can call imread_collection
or imread_stack
to open folder instead of raising errors. With default settings you don't have to call imread_collection
or imread_stack
anymore.TiffFile
just once in imread
.lucy
, rfftn
and irfftn
are used instead of fftn
and ifftn
. This change makes them ~2 times faster.numpy
functions, such as np.allclose
, did not support MetaArray
input. Now fixed.reslice
now supports reslicing a path.napari
's viewer can automatically add a table widget when a PropArray
is given.napari
's viewer can automatically add a Shapes
layer when a PathFrame
is given.Published by hanjinliu over 3 years ago
This release contains many new functions and function improvements.
rof_filter
for total variance denoising.pearson_coloc
and manders_coloc
to calculate colocalization coefficient.crop_kernel
to make small kernel array.ncc
for template matching using NCC (normalized cross correlation).impy.gaussina_kernel
for deconvolution and template matching.track_template
for template tracking based on NCC.function_handler
now accept list
and numpy
as input.Ctrl
+ G
) and unlink (Ctrl
+ Shift
+ G
) layer shortcuts: .defocus
.find_sm
has a new option method="ncc"
. This method is based on template matching of Gaussian particle.find_sm
has a new keyword argument cutoff
. Filtered images are clipped by this value.lucy
and lucy_tv
takes new argument eps=...
to avoid near-zero division.imsave
inside napari
.function_handler
and magicgui
.Ctrl
+ Shift
+ X
) works fine now.random_walker
works fine now.Ctrl
+ Shift
+ X
removes the original image. Duplicate it if you want.imread_stack
now have dirpath
attribute at the deepest directory of path
argument, which does not contain either "$" or "*".defocus
also pad in yx-direction by default. If it is not needed, you need to set width = 0
.Published by hanjinliu over 3 years ago
This Release is mainly focused on viewer.
impy.imread
function inside viewers. Unlike the original one, this can read tiff metadata.centroid_sm
now works for "zcyx"-images.impy
-object conversion is smarter now. Axes & scale information are recorded in metadata
attributes so that AxesFrame
remembers the initial states.Label
determines dtype
upon construction.rolling_ball
can return background with keyword return_bg=True
. Also, median filter is available for prefiltering.rolling_ball
is changed: smooth
→ prefilter
.impy.window
→ impy.gui
because it is no longer a single window.Published by hanjinliu over 3 years ago
This release contains many improvements for general usage.
numpy
functions.__array_function__
, we can overload numpy
functions in a single-dispatch-like way (see here). Now you can use numpy
functions directly in a impy
style, like np.mean(img, axis="t")
, np.expand_dims(img, axis="pz")
, np.stack([img1, img2], axis="z")
. Those functions that may change the dimensions of arrays are individually re-implemented.numpy
functions like np.array
or np.random.rand
cannot know if you are to generate np.ndarray
or ImgArray
. These functions are implemented in ip.array
, ip.random.rand
style.ip.bind
decorator class can interpret custom defined functions for batch processing. This decorator add dims
keyword argument and convert the function into an ImgArray
-like format. As long as the custom function returns images or labels with same shape as input, or single property per image, almost any function can be extended for batch processing.napari
viewer is improved as lot.ip.window
can deal with multiple windows. Previous codes still works, while new window is created by ip.window["new name"].add(X).
.Ctrl+Shift+X
.napari.Viewer
.ip.window.selection
. They are in ImgArray
, MarkerFrame
, ... form.napari==0.4.8
, scale unit can be displayed beside the scale bar. impy
can automatically read scale unit from the metadata of such as ImgArray
so that you don't need to add scale unit all the way.lucy_tv
, Richardson-Lucy with total variance regularization is now available. This is a little bit slower than lucy
but is widely used for deconvolution.label
and watershed
, returned LabeledArray
before. Hereafter they'll return Label
instead.ip.stack
, ip.zeros_like
, ip.empty_like
no longer works. Use np.stack
, np.zeros_like
, np.empty_like
instead.AxesFrame.iter
method sometimes raises error because of inconsistency between iteration took place or not. This is fixed now.dims_to_spatial_axes
now works for AxesFrame
as well.estimate_sigma
method did not work due to wrong implementation. This is fixed now.Published by hanjinliu over 3 years ago
This release mainly focused on bug fixes and improvements.
Previously impy
could not automatically deal with scale (or image resolution) so that users must set it by set_scale
method. Now you don't need to do that!
ip.imread
can read scales from tiff metadata and store it into scale property of ImgArray
.imsave
method can write scales of LabeledArray
into tiff files. It is compatible with ImageJ so that you can confirm in ImageJ by Ctrl+Shift+P.impy
now supports more flexible file handling.
ip.imread_collection
, ext
argument is deprecated. Instead, wildcard can be defined in more detailed way by filename
argument and image shape, axes or scale you want to read can be filtered by template
argument.ip.imread_stack
suits for practical image stacking for real microscopy. You may want to save multiple tiff files in different folders, and make a image stack from such as fr"~\XX{i}\YY{j}.tif" for i in [10,20,30] for j in [0,1,2,3]
format, followed by defining i
-direction as t-axis and j
-direction as p-axis. This task can be achieved by a very simple code: img = ip.imread_stack(fr"~\XX$t\YY$p.tif")
.Previously, when img1
has zcyx-axes and img2
has zyx-axes, img1/img2
raised broadcasting error due to numpy
's broadcasting rules. However, MetaArray
should know how to broadcast because apparently img1
and img2
have common axes "zyx". Now axis-targeted broadcasting is working. Accordingly, previous broadcasting-like parts in __getitem__
method is replaced with common function _broadcast
.
set_scale
can take "xy"
or "yx"
arguments to set yx-scale at the same time, like img.set_scale(yx=0.217)
.skimage
's sample data with such as ip.sample_image("camera")
. Image axes of RGB images will always be transposed so that they are cyx-order.crop_center
, remove_edges
accepts sequence as parameters.defocus
now can take any array as a defocusing kernel. Default Gaussian kernel is also supported.lucy
is ~30% faster now, achieved by recycling array objects during iterations.ip.squeeze
can squeeze ImgArray
in a flexible way.imsave
can automatically change axes symbols if possible when any symbols are not compatible with ImageJ (e.g. pyx
-> tyx
).proj
can calculate projection along multiple axes, like img.proj(axis="ptz")
.track_drift
and drift_correction
had wrong default settings so they always raised errors without explicit along
argument. → Fixed, and the error messages are also improved.Axes.replace(old, new)
did not change scale
attribute at the same time. This caused inconsistency between axes
and scale
and raised KeyError
in many situations (especially imsave
). → Fixed, and to prevent unexpected overwriting, scale
will be copied every time upon this function call.Published by hanjinliu over 3 years ago
Label
or AxesFrame
easily using shapes_to_labels
or points_to_frames
methods.imread
and imsave
can input/output xy-scale of tiff images. You don't have to call set_scale
method every time..edge_filter
for edge detection including sobel_filter
in the past. Accordingly sobel_filter
is deleted.edge_grad
for calculating gradient of an image. This function returns PhaseArray with 2*pi periodicity.proj_labels
for label projection. This is useful when you have tyx-labels but want them to be yx-labels.unmix
for unmixing leakage between channels in fluorescent microscopy.label_if
is fixed.affine
and translate
will support 3D transformation after scikit-image v0.19 becomes available.set_scale
in LabeledArray
(therefore ImgArray
and PhaseArray
) can set the same scales to their labels.peak_local_max
, corner_peaks
and refine_sm
did not work for zcyx-images due to wrong implementation. This is now fixed.