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
Unique image & metadata generation using weighted layer collections.

nft-generator-py nft-generator-py is a python based NFT generator which programatically generates unique images using weighted layer files. The progra

Jonathan Becker 243 Dec 31, 2022
Change the image one color channel at a time.

Building-a-Contact-Sheet This hands-on Project is in Python 3 Programming Specialization offered by University of Michigan via Coursera. change the im

Eszter Pai 1 Jan 03, 2022
A sketch like(?) effect for images

lineArt A sketch like(?) effect for images How to run main.py [filename] [option {1,2}] option 1 retains colour option 2 gives gray image #results ori

1 Oct 28, 2021
MetaStalk is a tool that can be used to generate graphs from the metadata of JPEG, TIFF, and HEIC images

MetaStalk About MetaStalk is a tool that can be used to generate graphs from the metadata of JPEG, TIFF, and HEIC images, which are tested. More forma

Cyb3r Jak3 1 Jul 05, 2021
A tool and a library for SVG path data transformations.

SVG path data transformation toolkit A tool and a library for SVG path data transformations. Currently it supports a translation and a scaling. Usage

Igor Mikushkin 2 Mar 07, 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
ModernGL is a python wrapper over OpenGL 3.3+ core

ModernGL is a python wrapper over OpenGL 3.3+ core that simplifies the creation of simple graphics applications like scientific simulations, games or user interface

ModernGL 1.4k Jan 01, 2023
HCaptcha solver using requests and an image recognition package!

HCaptcha solver using requests and an image recognition package! Report Bug ยท Request Feature Features Image recognition Requests base

dropout 6 Oct 22, 2021
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
ScreenTeX is a tool that grabs all text when taking a screenshot rather than getting an image.

The ScreenTeX project By: Seanpm2001 / ScreenTeX, Et; Al. Top README.md Read this article in a different language ๐ŸŒ List of languages Sorted by: A-Z

Sean P. Myrick V19.1.7.2 3 Oct 25, 2022
Nanosensor Image Processor (NanoImgPro), a python-based image analysis tool for dopamine nanosensors

NanoImgPro Nanosensor Image Processor (NanoImgPro), a python-based image analysis tool for dopamine nanosensors NanoImgPro.py contains the main class

1 Mar 02, 2022
Ascify-Art - An easy to use, GUI based and user-friendly colored ASCII art generator from images!

Ascify-Art This is a python based colored ASCII art generator for free! How to Install? You can download and use the python version if you want, modul

Akash Bora 14 Dec 31, 2022
Napari 3D Ortho Viewer - an ortho viewer for napari for 3D images

napari-3d-ortho-viewer Napari 3D Ortho Viewer - an ortho viewer for napari for 3D images This napari plugin was generated with Cookiecutter using @nap

niklas netter 5 Nov 28, 2022
Python Program that lets you write in your handwriting!

Handwriting with Python Python Program that lets you write in your handwriting! Inspired by: thaisribeiro.in How to run? Install Unidecode and Pillow

Amanda Rodrigues Vieira 2 Oct 25, 2021
Remove Background from Image With Python

Install Library pypi $ pip3 install xremovebg

krypton 4 May 26, 2022
Next-generation of the non-destructive, node-based 2D image graphics editor

Non-destructive, node-based 2D image graphics editor written in Python, focused on simplicity, speed, elegance, and usability

Gimel Studio 238 Dec 30, 2022
PyGtk Color - A couple of python scripts to select a color (for scripting usage)

Selection Scripts This repository contains two scripts to be used within a scripting project, to aquire a color value. Both scripts requir

Spiros Georgaras 1 Oct 31, 2021
Fast Image Retrieval is an open source image retrieval framework

Fast Image Retrieval is an open source image retrieval framework release by Center of Image and Signal Processing Lab (CISiP Lab), Universiti Malaya. This framework implements most of the major binar

CISiP Lab 39 Nov 25, 2022
Fix datetime EXIF data in photos downloaded from Google Takeout

fix-google-takeout Warning Use at your own risk. Backup your photos. Overview Google takeout for photos

Mayank Mandava 20 Nov 05, 2022
Fixed Version Of Blender Low Poly Rock Generator For Blender 3.0.0

Blender (3.0.0) - Low Poly Rock Generator This is an addon for Blender 3.0.0 to generate low poly rocks. It was based on an addon that unfortunately h

3 Mar 24, 2022