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
The friendly PIL fork (Python Imaging Library)

Pillow Python Imaging Library (Fork) Pillow is the friendly PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lund

Pillow 10.4k Dec 31, 2022
🎨 Generate and change color-schemes on the fly.

Generate and change color-schemes on the fly. Pywal is a tool that generates a color palette from the dominant colors in an image. It then applies the

dylan 6.9k Jan 03, 2023
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
【萝莉图片算法】高损图像压缩算法!?

【萝莉图片算法】高损图像压缩算法!? 我又发明出新算法了! 这次我发明的是新型高损图像压缩算法——萝莉图片算法!为什么是萝莉图片,这是因为它是使动用法,让图片变小所以是萝莉图片,大家一定要学好语文哦! 压缩效果 太神奇了!压缩率竟然高达99.97%! 与常见压缩算法对比 在图片最终大小为1KB的情况

黄巍 49 Oct 17, 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
Labelme is a graphical image annotation tool, It is written in Python and uses Qt for its graphical interface

Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation).

Kentaro Wada 9.6k Jan 09, 2023
Gaphor is the simple modeling tool

Gaphor Gaphor is a UML and SysML modeling application written in Python. It is designed to be easy to use, while still being powerful. Gaphor implemen

Gaphor 1.3k Dec 31, 2022
Rembg is a tool to remove images background.

Rembg is a tool to remove images background.

Daniel Gatis 7.8k Jan 05, 2023
👾 Python project to help you convert any image into a pixel art.

👾 Pixel Art Generator Python project to help you convert any image into a pixel art. ⚙️ Developer's Guide Things you need to get started with this co

Atul Anand 6 Dec 14, 2022
sK1 2.0 cross-platform vector graphics editor

sK1 2.0 sK1 2.0 is a cross-platform open source vector graphics editor similar to CorelDRAW, Adobe Illustrator, or Freehand. sK1 is oriented for prepr

sK1 Project 238 Dec 04, 2022
3D printer / slicing GUI built on top of the Uranium framework

Cura Ultimaker Cura is a state-of-the-art slicer application to prepare your 3D models for printing with a 3D printer. With hundreds of settings and h

Ultimaker 4.4k Jan 02, 2023
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
This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specialized data structure called VP-Tree which makes searching an image on a dataset of 100Ks almost instantanious

Offline Reverse Image Search Overview This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specia

53 Nov 15, 2022
A tool to maintain an archive/mirror of your Google Photos library for backup purposes.

Google Photos Archiver Updated Instructions 8/9/2021 Version 2.0.6 Instructions: Download the script (exe or python script listed below) Follow the in

Nick Dawson 116 Jan 03, 2023
Pnuemonia Normal detection by using XRay images.

Pnuemonia Normal detection by using XRay images. Got image datas from kaggle(link is given in sources.txt file) also normal xray images from other site (also link is given) in order to avoid data dis

Zarina 1 Feb 28, 2022
Find target hash collisions for Apple's NeuralHash perceptual hash function.💣

neural-hash-collider Find target hash collisions for Apple's NeuralHash perceptual hash function. For example, starting from a picture of this cat, we

Anish Athalye 630 Jan 01, 2023
New program to export a Blender model to the LBA2 model format.

LBA2 Blender to Model 2 This is a new program to export a Blender model to the LBA2 model format. This is also the first publicly released version of

2 Nov 30, 2022
Sombra is simple Raytracer written in pure Python.

Sombra Sombra is simple Raytracer written in pure Python. It's main purpose is to help understand how raytracing works with a clean code. If you are l

Hernaldo Jesus Henriquez Nuñez 10 Jul 16, 2022
A ray tracing render implemented using Taichi language.

A ray tracing render implemented using Taichi language.

Mingrui Zhang 45 Oct 23, 2022