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
QR Code Generator

In this project, we'll be using some libraries to instantly generate authentic QR Codes and export them in various formats

Hassan Shahzad 3 Jun 02, 2022
Conversion of Image, video, text into ASCII format

asciju Python package that converts image to ascii Free software: MIT license

Aju Tamang 11 Aug 22, 2022
A proof-of-concept implementation of a parallel-decodable PNG format

mtpng A parallelized PNG encoder in Rust by Brion Vibber [email protected] Backgrou

Brion Vibber 193 Dec 16, 2022
Multiparametric Image Analysis

Documentation The documentation is available on populse_mia's website here Installation From PyPI, for users By cloning the package, for developers Fr

Populse 9 Dec 14, 2022
display: a browser-based graphics server

display: a browser-based graphics server Installation Quick Start Usage Development A very lightweight display server for Torch. Best used as a remote

Szymon Jakubczak 205 Oct 17, 2022
A simple Streamlit Component to compare images in Streamlit apps. It integrates Knightlab's JuxtaposeJS

streamlit-image-juxtapose A simple Streamlit Component to compare images in Streamlit apps using Knightlab's JuxtaposeJS. The images are saved to the

Robin 30 Dec 31, 2022
Make your master artistic punk avatar through machine learning world famous paintings

Master-art-punk Make your master artistic punk avatar through machine learning world famous paintings. 通过机器学习世界名画制作属于你的大师级艺术朋克头像 Nowadays, NFT is beco

蒋虎成 23 Jan 04, 2022
Django helper application to easily and non-destructively crop arbitrarily large images in admin and frontend.

django-image-cropping django-image-cropping is an app for cropping uploaded images via Django's admin backend using Jcrop. Screenshot: django-image-cr

Jonas und der Wolf GmbH 546 Jan 03, 2023
Python-based tools for document analysis and OCR

ocropy OCRopus is a collection of document analysis programs, not a turn-key OCR system. In order to apply it to your documents, you may need to do so

OCRopus 3.2k Jan 04, 2023
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
Validate arbitrary image uploads from incoming data urls while preserving file integrity but removing EXIF and unwanted artifacts and RCE exploit potential

Validate arbitrary base64-encoded image uploads as incoming data urls while preserving image integrity but removing EXIF and unwanted artifacts and mitigating RCE-exploit potential.

A3R0 1 Jan 10, 2022
Create a random fluent image based on multiple colors.

FluentGenerator Create a random fluent image based on multiple colors. Navigation Example Install Update Usage In Python console FluentGenerator Fluen

1 Feb 02, 2022
Image Processing - Make noise images clean

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

2 Aug 04, 2022
Draw a torus passing through three given points.

PyTorusThreePoints Draw a torus passing through three given points. Usage import numpy as np import pyvista as pv from torus_three_points.main import

2 Nov 19, 2021
🖼️ Draw Images or GIFs in your terminal

Drawitor Draw Images/GIFs in your terminal. Install pip install drawitor CLI Tool drawitor cat_dancing.gif Library The library is written in a simple

Eliaz Bobadilla 7 Dec 15, 2022
📷 Python package and CLI utility to create photo mosaics.

📷 Python package and CLI utility to create photo mosaics.

Loic Coyle 7 Oct 29, 2022
Maze generator with most popular shapes - hexagon, triangle, square

Maze-Generator Maze generator with most popular shapes - hexagon, triangle, square (sqaure not implemented yet): Theory: Planar Graph https://en.wikip

Kacper Plesiak 2 Dec 28, 2021
Quickly 'anonymize' all people in an image. This script will put a black bar over all eye-pairs in an image

Face-Detacher Quickly 'anonymize' all people in an image. This script will put a black bar over all eye-pairs in an image This is a small python scrip

Don Cato 1 Oct 29, 2021
Create a 2D mesh for an airfoil in GMSH using python.

GMSHFoil A simple class to create a 2D mesh for an airfoil in GMSH using python. Requirements pip install airfoils

Charilaos Mylonas 1 May 16, 2022
Script that organizes the Google Takeout archive into one big chronological folder

Script that organizes the Google Takeout archive into one big chronological folder

Mateusz Soszyński 1.6k Jan 09, 2023