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) [email protected] ~ % /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
Image histogram remapping

Hmap An image histogram remapping script written in Python 2.7 by Anthony Kesich and Ross Goodwin. Changes source image so that source image's histogr

Ross Goodwin 199 Nov 19, 2022
An API which would colorize a black and white image

Image Colorization API Machine Learning Model used- https://github.com/richzhang/colorization/tree/caffe Paper - https://arxiv.org/abs/1603.08511 Step

Neelesh Ranjan Jha 4 Nov 23, 2021
Generative Art Synthesizer - a python program that generates python programs that generates generative art

GAS - Generative Art Synthesizer Generative Art Synthesizer - a python program that generates python programs that generates generative art. Examples

Alexey Borsky 43 Dec 03, 2022
Short piece of code to create a rainbow gif of gradual contours from two shapefiles

rainbow-elevation-gif Short piece of code to create a rainbow gif of gradual con

Jess Roberts 6 Jan 17, 2022
QR-code Generator with a basic GUI.

Qr_generator_python Qr code generator with a basic GUI. ❔ About the QR-Code-Generator This project Generates QR codes to sites, e-mails and plain text

Tecixck 2 Oct 11, 2021
Simple utility to tinker with OPlus images

OPlus image utilities Prerequisites Linux running kernel 5.4 or up (check with uname -r) Image rebuilding Used to rebuild read-only erofs images into

Wiley Lau 15 Dec 28, 2022
OctoPrint is the snappy web interface for your 3D printer!

OctoPrint OctoPrint provides a snappy web interface for controlling consumer 3D printers. It is Free Software and released under the GNU Affero Genera

OctoPrint 7.1k Jan 03, 2023
Art directed cropping, useful for responsive images

Art direction sets a focal point and can be used when you need multiple copies of the same Image but also in in different proportions.

Daniel 1 Aug 16, 2022
Convert photos to paintings with python

Convert-photos-to-paintings Before the changes After the changes Before the changes After the changes This code is written in the Python programming l

Amir Hussein Sharifnezhad 3 May 31, 2022
MikuMikuRig是一款集生成控制器,自动导入动画,自动布料为一体的blender插件

Miku_Miku_Rig MikuMikuRig是一款集生成控制器,自动导入动画,自动布料为一体的blender插件。 MikumiKurig is a Blender plugin that can generates rig, automatically imports animations

小威廉伯爵 342 Dec 29, 2022
A ray tracing render implemented using Taichi language.

A ray tracing render implemented using Taichi language.

Mingrui Zhang 45 Oct 23, 2022
Python wrappers for external BART computational imaging tools and internal libraries

bartpy Python bindings for BART. Overview This repo contains code to generate an updated Python wrapper for the Berkeley Advance Reconstruction Toolbo

Max Litster 7 May 09, 2022
NFT collection generator. Generates layered images

NFT collection generator Generates layered images, whole collections. Provides additional functionality. Repository includes three scripts generate.py

Gleb Gonchar 10 Nov 15, 2022
Generate waves art for an image

waves-art Generate waves art for an image. Requirements: OpenCV Numpy Example Usage python waves_art.py --image_path tests/test1.jpg --patch_size 15 T

Hamza Rawal 18 Apr 04, 2022
Qrgenerator - A qr generator app using python3

qrgenerator by Mal4D Hi welcome into qr code generator using python by Mal4d Lin

Mal4D 1 Jan 09, 2022
Instagram-like image filters.

PyGram Instagram-like image filters. Usage First, import the client: from filters import * Instanciate a filter and apply it: f = Nashville("image.jp

Ajay Kumar Nagaraj 0 Oct 18, 2022
An open source image editor which can manipulate an image in many ways!

Image Editor - An open source image editor which can manipulate an image in many ways! If you need any more modes in repo or I

TroJanzHEX 44 Nov 17, 2022
Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Python

AICSImageIO Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Pure Python Features Supports reading metadata and imaging

Allen Institute for Cell Science - Modeling 137 Dec 14, 2022
Pythonocc nodes for Ryven

Pythonocc-nodes-for-Ryven Pythonocc nodes for Ryven Here a way to work on Pythonocc with a node editor, Ryven in that case. To get it functional you w

Tanneguy 30 Dec 18, 2022
Generate your own QR Code and scan it to see the results! Never use it for malicious purposes.

QR-Code-Generator-Python Choose the name of your generated QR .png file. If it happens to open the .py file (the application), there are specific comm

1 Dec 23, 2021