Napari simpleitk image processing

Overview

napari-simpleitk-image-processing (n-SimpleITK)

License PyPI Python Version tests codecov napari hub

Process images using SimpleITK in napari

Usage

Filters of this napari plugin can be found in the Tools > Filtering menu. Segmentation algorithms and tools for post-processing segmented (binary or label) images can be found in the Tools > Segmentation menu. All filters implemented in this napari plugin are also demonstrated in this notebook.

Gaussian blur

Applies a Gaussian blur to an image. This might be useful for denoising, e.g. before applying the Threshold-Otsu method.

img.png

Median filter

Applies a median filter to an image. Compared to the Gaussian blur this method preserves edges in the image better. It also performs slower.

img.png

Bilateral filter

The bilateral filter allows denoising an image while preserving edges.

img.png

Threshold Otsu

Binarizes an image using Otsu's method.

img.png

Connected Component Labeling

Takes a binary image and labels all objects with individual numbers to produce a label image.

img.png

Signed Maurer distance map

A distance map (more precise: Signed Maurer Distance Map) can be useful for visualizing distances within binary images between black/white borders. Positive values in this image correspond to a white (value=1) pixel's distance to the next black pixel. Black pixel's (value=0) distance to the next white pixel are represented in this map with negative values.

img.png

Binary fill holes

Fills holes in a binary image.

img.png

Touching objects labeling

Starting from a binary image, touching objects can be splits into multiple regions, similar to the Watershed segmentation in ImageJ.

img.png

Morphological Watershed

The morhological watershed allows to segment images showing membranes. Before segmentation, a filter such as the Gaussian blur or a median filter should be used to eliminate noise. It also makes sense to increase the thickness of membranes using a maximum filter. See this notebook for details.

img.png

Watershed-Otsu-Labeling

This algorithm uses Otsu's thresholding method in combination with Gaussian blur and the Watershed-algorithm approach to label bright objects such as nuclei in an intensity image. The alogrithm has two sigma parameters and a level parameter which allow you to fine-tune where objects should be cut (spot_sigma) and how smooth outlines should be (outline_sigma). The watershed_level parameter determines how deep an intensity valley between two maxima has to be to differentiate the two maxima. This implementation is similar to Voronoi-Otsu-Labeling in clesperanto.

img.png

Richardson-Lucy Deconvolution

Richardson-Lucy deconvolution allows to restore image quality if the point-spread-function of the optical system used for acquisition is known or can be approximated.

img.png


This napari plugin was generated with Cookiecutter using @napari's cookiecutter-napari-plugin template.

Installation

You can install napari-simpleitk-image-processing via pip:

pip install napari-simpleitk-image-processing

To install latest development version :

pip install git+https://github.com/haesleinhuepf/napari-simpleitk-image-processing.git

Contributing

Contributions are very welcome. There are many useful algorithms available in SimpleITK. If you want another one available here in this napari plugin, don't hesitate to send a pull-request. This repository just holds wrappers for SimpleITK-functions, see this file for how those wrappers can be written.

License

Distributed under the terms of the BSD-3 license, "napari-simpleitk-image-processing" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Comments
  • Error if no intensity image is provided

    Error if no intensity image is provided

    The label statistics function produces an error if an intensity image is not provided. This happens even in cases where only statistics that do not require intensity are requested (eg: size, shape, position).

    To reproduce:

    1. Open napari and load some labels
    import napari
    from skimage.data import binary_blobs
    from skimage.measure import label
    
    blobs = label(binary_blobs(length=64, volume_fraction=0.05, n_dim=3))
    viewer = napari.view_labels(blobs)
    
    1. Open "label statistics" from the napari-simpleitk-image-processing plugin menu: Plugins > napari-simpleitk-image-processing > label statistics
    2. Uncheck the "intensity" checkbox (but leave the "size" checkbox selected).
    3. Click the "Run" button on the plugin, and observe the error message
    Full traceback (click to expand):
      File "C:\Users\CryoEM\.conda\envs\napari-empanada\lib\site-packages\SimpleITK\extra.py", line 184, in _get_sitk_pixelid
        return _np_sitk[numpy_array_type.dtype]
    KeyError: dtype('O')
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Users\CryoEM\.conda\envs\napari-empanada\lib\site-packages\magicgui\widgets\_bases\value_widget.py", line 57, in _on_value_change
        self.changed.emit(value)
      File "psygnal\\_signal.py", line 725, in psygnal._signal.SignalInstance.emit
      File "psygnal\\_signal.py", line 767, in psygnal._signal.SignalInstance._run_emit_loop
      File "psygnal\\_signal.py", line 768, in psygnal._signal.SignalInstance._run_emit_loop
      File "psygnal\\_signal.py", line 788, in psygnal._signal.SignalInstance._run_emit_loop
      File "C:\Users\CryoEM\.conda\envs\napari-empanada\lib\site-packages\magicgui\widgets\_function_gui.py", line 207, in _disable_button_and_call
        self.__call__()
      File "C:\Users\CryoEM\.conda\envs\napari-empanada\lib\site-packages\magicgui\widgets\_function_gui.py", line 318, in __call__
        value = self._function(*bound.args, **bound.kwargs)
      File "C:\Users\CryoEM\.conda\envs\napari-empanada\lib\site-packages\napari_simpleitk_image_processing\_simpleitk_image_processing.py", line 814, in label_statistics
        sitk_intensity_image = sitk.GetImageFromArray(intensity_image)
      File "C:\Users\CryoEM\.conda\envs\napari-empanada\lib\site-packages\SimpleITK\extra.py", line 292, in GetImageFromArray
        id = _get_sitk_pixelid(z)
      File "C:\Users\CryoEM\.conda\envs\napari-empanada\lib\site-packages\SimpleITK\extra.py", line 189, in _get_sitk_pixelid
        raise TypeError('dtype: {0} is not supported.'.format(numpy_array_type.dtype))
    TypeError: dtype: object is not supported.
    
    If you suspect this is an IPython 8.4.0 bug, please report it at:
        https://github.com/ipython/ipython/issues
    or send an email to the mailing list at [email protected]
    
    You can print a more detailed traceback right now with "%tb", or use "%debug"
    to interactively debug it.
    
    Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
        %config Application.verbose_crash=True
    

    Additional details:

    • Operating system: Windows 10
    • python version: 3.9
    • napari version: 0.4.15
    • napari-simpleitk-image-processing version: 0.4.0
    opened by GenevieveBuckley 3
  • import fails with OSError on headless system

    import fails with OSError on headless system

    importing napari_simpleitk_image_processing fails with errors about missing GL libraries (see below). I assume this means that this plugin needs a working display?

    is there a workaround to make this plugin work without gl support?

    Cheers,

    Till

    `napari_simpleitk_image_processing` import errors ---------------------------------------------------------------------------

    OSError Traceback (most recent call last) Input In [6], in <cell line: 7>() 5 import numpy as np 6 #import napari_segment_blobs_and_things_with_membranes as nsbatwm ----> 7 import napari_simpleitk_image_processing as nsitk

    File /app/env/lib/python3.9/site-packages/napari_simpleitk_image_processing/init.py:9, in 3 common_alias = "nsitk" 8 from ._function import napari_experimental_provide_function ----> 9 from ._simpleitk_image_processing import
    10 plugin_function,
    11 median_filter,
    12 gaussian_blur,
    13 threshold_otsu,
    14 threshold_intermodes,
    15 threshold_kittler_illingworth,
    16 threshold_li,
    17 threshold_moments,
    18 threshold_renyi_entropy,
    19 threshold_shanbhag,
    20 threshold_yen,
    21 threshold_isodata,
    22 threshold_triangle,
    23 threshold_huang,
    24 threshold_maximum_entropy,
    25 signed_maurer_distance_map,
    26 morphological_watershed,
    27 morphological_gradient,
    28 standard_deviation_filter,
    29 simple_linear_iterative_clustering,
    30 scalar_image_k_means_clustering,
    31 connected_component_labeling,
    32 touching_objects_labeling,
    33 watershed_otsu_labeling,
    34 binary_fill_holes,
    35 invert_intensity,
    36 bilateral_filter,
    37 laplacian_filter,
    38 laplacian_of_gaussian_filter,
    39 binominal_blur_filter,
    40 canny_edge_detection,
    41 gradient_magnitude,
    42 h_maxima,
    43 h_minima,
    44 otsu_multiple_thresholds,
    45 regional_maxima,
    46 regional_minima,
    47 richardson_lucy_deconvolution,
    48 wiener_deconvolution,
    49 tikhonov_deconvolution,
    50 rescale_intensity,
    51 sobel,
    52 black_top_hat,
    53 white_top_hat,
    54 adaptive_histogram_equalization,
    55 curvature_flow_denoise,
    56 relabel_component,
    57 label_contour,
    58 label_statistics,
    59 pixel_count_map,
    60 elongation_map,
    61 feret_diameter_map,
    62 roundness_map

    File /app/env/lib/python3.9/site-packages/napari_simpleitk_image_processing/_simpleitk_image_processing.py:7, in 5 from toolz import curry 6 import inspect ----> 7 from napari_tools_menu import register_function 8 from napari_time_slicer import time_slicer 9 from napari_skimage_regionprops._all_frames import analyze_all_frames

    File /app/env/lib/python3.9/site-packages/napari_tools_menu/init.py:9, in 7 import warnings 8 import napari ----> 9 import napari._qt 10 import numpy as np 11 from qtpy.QtWidgets import QMenu

    File /app/env/lib/python3.9/site-packages/napari/qt/init.py:53, in 45 warn_message = trans.( 46 "\n\nnapari was tested with QT library >=5.12.3.\nThe version installed is {version}. Please report any issues with\nthis specific QT version at https://github.com/Napari/napari/issues. style="color:rgb(175,0,0)">", 47 deferred=True, 48 version=QtCore.version, 49 ) 50 warn(message=warn_message) ---> 53 from .qt_event_loop import get_app, gui_qt, quit_app, run 54 from .qt_main_window import Window

    File /app/env/lib/python3.9/site-packages/napari/_qt/qt_event_loop.py:15, in 12 from qtpy.QtWidgets import QApplication 14 from .. import version ---> 15 from ..settings import get_settings 16 from ..utils import config, perf 17 from ..utils.notifications import ( 18 notification_manager, 19 show_console_notification, 20 )

    File /app/env/lib/python3.9/site-packages/napari/settings/init.py:6, in 4 from ..utils.translations import trans 5 from ._base import _NOT_SET ----> 6 from ._napari_settings import NapariSettings 8 all = ['NapariSettings', 'get_settings'] 11 class _SettingsProxy:

    File /app/env/lib/python3.9/site-packages/napari/settings/_napari_settings.py:9, in 7 from ..utils._base import _DEFAULT_CONFIG_PATH 8 from ..utils.translations import trans ----> 9 from ._appearance import AppearanceSettings 10 from ._application import ApplicationSettings 11 from ._base import EventedConfigFileSettings, _remove_empty_dicts

    File /app/env/lib/python3.9/site-packages/napari/settings/_appearance.py:4, in 1 from pydantic import Field 3 from ..utils.events.evented_model import EventedModel ----> 4 from ..utils.theme import available_themes 5 from ..utils.translations import trans 6 from ._fields import Theme

    File /app/env/lib/python3.9/site-packages/napari/utils/init.py:2, in 1 from ._dask_utils import resize_dask_cache ----> 2 from .colormaps import Colormap 3 from .info import citation_text, sys_info 4 from .notebook_display import nbscreenshot

    File /app/env/lib/python3.9/site-packages/napari/utils/colormaps/init.py:2, in 1 from .colorbars import make_colorbar ----> 2 from .colormap import Colormap 3 from .colormap_utils import ( 4 ALL_COLORMAPS, 5 AVAILABLE_COLORMAPS, (...) 16 matplotlib_colormaps, 17 )

    File /app/env/lib/python3.9/site-packages/napari/utils/colormaps/colormap.py:11, in 9 from ..translations import trans 10 from .colorbars import make_colorbar ---> 11 from .standardize_color import transform_color 14 class ColormapInterpolationMode(str, Enum): 15 """INTERPOLATION: Interpolation mode for colormaps. 16 17 Selects an interpolation mode for the colormap. (...) 21 bin between by neighboring controls points. 22 """

    File /app/env/lib/python3.9/site-packages/napari/utils/colormaps/standardize_color.py:27, in 24 from typing import Any, Callable, Dict, Sequence 26 import numpy as np ---> 27 from vispy.color import ColorArray, get_color_dict, get_color_names 28 from vispy.color.color_array import _string_to_rgb 30 from ..translations import trans

    File /app/env/lib/python3.9/site-packages/vispy/color/init.py:12, in 10 from ._color_dict import get_color_names, get_color_dict # noqa 11 from .color_array import Color, ColorArray ---> 12 from .colormap import (Colormap, BaseColormap, # noqa 13 get_colormap, get_colormaps) # noqa 15 all = ['Color', 'ColorArray', 'Colormap', 'BaseColormap', 16 'get_colormap', 'get_colormaps', 17 'get_color_names', 'get_color_dict']

    File /app/env/lib/python3.9/site-packages/vispy/color/colormap.py:14, in 12 from hsluv import hsluv_to_rgb 13 from ..util.check_environment import has_matplotlib ---> 14 import vispy.gloo 16 ############################################################################### 17 # Color maps 18 19 # Length of the texture map used for luminance to RGBA conversion 20 LUT_len = 1024

    File /app/env/lib/python3.9/site-packages/vispy/gloo/init.py:47, in 5 """ 6 Object oriented interface to OpenGL. 7 (...) 42 43 """ 45 from future import division ---> 47 from . import gl # noqa 48 from .wrappers import * # noqa 49 from .context import (GLContext, get_default_config, # noqa 50 get_current_canvas) # noqa

    File /app/env/lib/python3.9/site-packages/vispy/gloo/gl/init.py:230, in 228 from . import gl2 as default_backend # noqa 229 if default_backend._lib is None: # Probably Android or RPi --> 230 from . import es2 as default_backend # noqa 233 # Call use to start using our default backend 234 use_gl()

    File /app/env/lib/python3.9/site-packages/vispy/gloo/gl/es2.py:48, in 46 # Else, we failed and exit 47 if es2_file is None: ---> 48 raise OSError('GL ES 2.0 library not found') 49 # Load it 50 _lib = ctypes.CDLL(es2_file)

    OSError: GL ES 2.0 library not found

    opened by thawn 1
  • Crash caused by leaked semaphore objects

    Crash caused by leaked semaphore objects

    I'm getting crashes when running label statistics for datasets around size (1000, 2048, 2048) pixels.

    There's some sort of memory leak, which kills ipython completely. I'd understand more if this was a truly giant dataset, or I was doing exessively complicated label statistics, instead of just label size, but that's not the case. I'm using a small, cropped subsection of my larger dataset, and I'd always considered one to two thousand pixels a fairly reasonable size to process in memory.

    In [7]: zsh: killed     ipython
    (napari-empanada) genevieb@192-168-1-103 ~ % /Users/genevieb/mambaforge/envs/napari-empanada/lib/python3.9/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
      warnings.warn('resource_tracker: There appear to be %d '
    
    opened by GenevieveBuckley 3
  • Filters don't take voxel size into account when called from tools menu

    Filters don't take voxel size into account when called from tools menu

    See: https://forum.image.sc/t/z-scale-reshape-issue/67022/6

    It should be feasible to adopt the assistants strategy to copy layer scale from input to output...

    opened by haesleinhuepf 0
  • Spatial transforms / resampling

    Spatial transforms / resampling

    It would be cool to implement some simple transforms: rescaling, translation, rotation and/or rigid. This notebook is a good starting point: http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/21_Transforms_and_Resampling.html

    enhancement good first issue 
    opened by haesleinhuepf 0
Releases(0.4.4)
  • 0.4.4(Sep 24, 2022)

  • 0.4.3(Aug 27, 2022)

  • 0.4.2(Aug 10, 2022)

    Bugfix

    • Speed up label_statistics() computation and spare memory in case shape=False and/or perimeter=False (thanks to @GenevieveBuckley for reporting this issue)
    Source code(tar.gz)
    Source code(zip)
  • 0.4.1(Jul 28, 2022)

  • 0.4.0(Jul 10, 2022)

    Miscellaneous

    • The menu entry Morphological gradient has been moved to Tools > Filtering / edge enhancement
    • Dropped support for Python 3.7, added 3.10
    • Updated function documentation to be more biology-specific, as the napari-assistant can now search it.

    Backwards compatibility breaking changes

    • The unused viewer parameter has been removed from all functions
    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(May 28, 2022)

  • 0.3.0(May 8, 2022)

    Backwards compatibility breaking changes

    • The API of label_statistics was modified:
      • The position of the napari_viewer argument was changed. It is recommended to use it as keyword-argument.
      • The function now returns Pandas DataFrames instead of a dictionary.
    Source code(tar.gz)
    Source code(zip)
  • 0.2.7(Apr 27, 2022)

  • 0.2.5(Apr 2, 2022)

    New features

    • Support for analysing time lapse data (frame-by-frame) in menu Tools > Measurement > Measurements of all frames (n-SsimpleITK)
    Source code(tar.gz)
    Source code(zip)
  • 0.2.4(Mar 26, 2022)

  • 0.2.3(Mar 20, 2022)

  • 0.2.2(Mar 20, 2022)

  • 0.2.1(Jan 30, 2022)

  • 0.2.0(Jan 1, 2022)

    New features

    • label_statistics
    • simple_linear_iterative_clustering
    • scalar_image_k_means_clustering
    • invert_intensity
    • adaptive_histogram_equalization
    • curvature_flow_denoise
    • morphological_gradient
    • standard_deviation_filter
    • relabel_component
    • label_contour
    • threshold_intermodes
    • threshold_kittler_illingworth
    • threshold_li
    • threshold_moments
    • threshold_renyi_entropy
    • threshold_shanbhag
    • threshold_yen
    • threshold_isodata
    • threshold_triangle
    • threshold_huang
    • threshold_maximum_entropy
    Source code(tar.gz)
    Source code(zip)
  • 0.1.4(Dec 12, 2021)

  • 0.1.3(Dec 4, 2021)

  • 0.1.2(Nov 28, 2021)

    New features

    • Input images can be dask images now. They will be converted to numpy before passing over to SimpleITK
    • new filters
      • bilateral_filter,
      • laplacian_filter
      • laplacian_of_gaussian_filter
      • binominal_blur_filter
      • canny_edge_detection
      • gradient_magnitude
      • h_maxima
      • h_minima
      • otsu_multiple_thresholds
      • regional_maxima
      • regional_minima
      • richardson_lucy_deconvolution
      • wiener_deconvolution
      • tikhonov_deconvolution
      • rescale_intensity
      • sobel
      • black_top_hat
      • white_top_hat
    Source code(tar.gz)
    Source code(zip)
  • 0.1.1(Nov 28, 2021)

  • 0.1.0(Nov 28, 2021)

    New features

    • median_filter
    • gaussian_blur
    • threshold_otsu
    • signed_maurer_distance_map
    • morphological_watershed
    • connected_component_labeling
    • touching_objects_labeling
    • watershed_otsu_labeling
    • binary_fill_holes
    Source code(tar.gz)
    Source code(zip)
Owner
Robert Haase
Computational Microscopist, BioImage Analyst, Code Jockey
Robert Haase
Sample data for the napari image viewer.

napari-demo-data Sample data for the napari image viewer. This napari plugin was generated with Cookiecutter using @napari's cookiecutter-napari-plugi

Genevieve Buckley 1 Nov 8, 2021
A simple image-level annotation tool supporting multi-channel images for napari.

napari-labelimg4classification A simple image-level annotation tool supporting multi-channel images for napari. This napari plugin was generated with

null 4 May 16, 2022
A suite of useful tools based on 3D interactivity in napari

napari-threedee A suite of useful tools based on 3D interactivity in napari This napari plugin was generated with Cookiecutter using @napari's cookiec

null 11 Dec 14, 2022
Napari plugin for iteratively improving 3D instance segmentation of cells (u-net x watershed)

iterseg napari plugin for iteratively improving unet-watershed segmentation This napari plugin was generated with Cookiecutter using @napari's cookiec

Abigail McGovern 3 May 16, 2022
A simple plugin to view APR images in napari

napari-apr-viewer A simple plugin to view APR images in napari This napari plugin was generated with Cookiecutter using @napari's cookiecutter-napari-

null 5 Jan 24, 2022
Anaglyph 3D Converter - A python script that adds a 3D anaglyph style effect to an image using the Pillow image processing package.

Anaglyph 3D Converter - A python script that adds a 3D anaglyph style effect to an image using the Pillow image processing package.

Kizdude 2 Jan 22, 2022
PIX is an image processing library in JAX, for JAX.

PIX PIX is an image processing library in JAX, for JAX. Overview JAX is a library resulting from the union of Autograd and XLA for high-performance ma

DeepMind 294 Jan 8, 2023
Blue noise image stippling in Processing (requires GPU)

Blue noise image stippling in Processing (requires GPU)

Mike Wong 141 Oct 9, 2022
impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools and so on.

impy is All You Need in Image Analysis impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools a

null 24 Dec 20, 2022
A Python package implementing various HDRI / Radiance image processing algorithms.

Colour - HDRI A Python package implementing various HDRI / Radiance image processing algorithms. It is open source and freely available under the New

colour-science 111 Dec 6, 2022
starfish is a Python library for processing images of image-based spatial transcriptomics.

starfish: scalable pipelines for image-based transcriptomics starfish is a Python library for processing images of image-based spatial transcriptomics

null 199 Dec 8, 2022
GPU-accelerated image processing using cupy and CUDA

napari-cupy-image-processing GPU-accelerated image processing using cupy and CUDA This napari plugin was generated with Cookiecutter using with @napar

Robert Haase 16 Oct 26, 2022
image-processing exercises.

image_processing Assignment 21 Checkered Board Create a chess table using numpy and opencv. view: Color Correction Reverse black and white colors with

Benyamin Zojaji 25 Dec 15, 2022
clesperanto is a graphical user interface for GPU-accelerated image processing.

clesperanto is a graphical user interface for a multi-platform multi-language framework for GPU-accelerated image processing. It is based on napari and the pyclesperanto-prototype.

null 1 Jan 2, 2022
Simple Python image processing & automatization project for a simple web based game

What is this? Simple Python image processing & automatization project for a simple web based game Made using only Github Copilot (except the color and

SGeri 2 Aug 15, 2022
Image Processing - Make noise images clean

影像處理-影像降躁化(去躁化) (Image Processing - Make Noise Images Clean) 得力於電腦效能的大幅提升以及GPU的平行運算架構,讓我們能夠更快速且有效地訓練AI,並將AI技術應用於不同領域。本篇將帶給大家的是 「將深度學習應用於影像處理中的影像降躁化 」,

null 2 Aug 4, 2022
A small Python module for BMP image processing.

micropython-microbmp A small Python module for BMP image processing. It supports BMP image of 1/2/4/8/24-bit colour depth. Loading supports compressio

Quan Lin 4 Nov 2, 2022
Image Processing HighPass Filter With Python

Image_Processing_HighPassFilter High Pass Filter take the high frequency and ignore the low frequency High Pass Filter can be use to sharpening an ima

Felix Pratamasan 1 Dec 27, 2021
kikuchipy is an open-source Python library for processing and analysis of electron backscatter diffraction (EBSD) patterns

kikuchipy is an open-source Python library for processing and analysis of electron backscatter diffraction (EBSD) patterns. The library builds on the

pyxem 53 Dec 29, 2022