mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-13 01:52:01 +08:00
ENH: Let CannyPlugin adapt to input image
Add `dtype_limits` helper function.
This commit is contained in:
+18
-1
@@ -2,7 +2,7 @@ from __future__ import division
|
||||
import numpy as np
|
||||
|
||||
__all__ = ['img_as_float', 'img_as_int', 'img_as_uint', 'img_as_ubyte',
|
||||
'img_as_bool']
|
||||
'img_as_bool', 'dtype_limits']
|
||||
|
||||
from .. import get_log
|
||||
log = get_log('dtype_converter')
|
||||
@@ -28,6 +28,23 @@ if np.__version__ >= "1.6.0":
|
||||
_supported_types += (np.float16, )
|
||||
|
||||
|
||||
def dtype_limits(image, auto_clip=True):
|
||||
"""Return intensity limits, i.e. (min, max) tuple, of the image's dtype.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
image : ndarray
|
||||
Input image.
|
||||
auto_clip : bool
|
||||
If True, clip the negative range (i.e. return 0 for min intensity)
|
||||
if the input image has no negative values.
|
||||
"""
|
||||
imin, imax = dtype_range[image.dtype.type]
|
||||
if auto_clip and imin < 0 and image.min() >= 0:
|
||||
imin = 0
|
||||
return imin, imax
|
||||
|
||||
|
||||
def convert(image, dtype, force_copy=False, uniform=False):
|
||||
"""
|
||||
Convert an image to the requested data-type.
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from skimage.filter import canny
|
||||
import numpy as np
|
||||
|
||||
import skimage
|
||||
from skimage.filter import canny
|
||||
from .overlayplugin import OverlayPlugin
|
||||
from ..widgets import Slider, ComboBox
|
||||
|
||||
@@ -12,7 +14,17 @@ class CannyPlugin(OverlayPlugin):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(CannyPlugin, self).__init__(image_filter=canny, **kwargs)
|
||||
|
||||
def attach(self, image_viewer):
|
||||
image = image_viewer.image
|
||||
imin, imax = skimage.dtype_limits(image)
|
||||
itype = 'float' if np.issubdtype(image.dtype, float) else 'int'
|
||||
self.add_widget(Slider('sigma', 0, 5, update_on='release'))
|
||||
self.add_widget(Slider('low threshold', 0, 255, update_on='release'))
|
||||
self.add_widget(Slider('high threshold', 0, 255, update_on='release'))
|
||||
self.add_widget(Slider('low threshold', imin, imax, value_type=itype,
|
||||
update_on='release'))
|
||||
self.add_widget(Slider('high threshold', imin, imax, value_type=itype,
|
||||
update_on='release'))
|
||||
self.add_widget(ComboBox('color', self.color_names, ptype='plugin'))
|
||||
# Call parent method at end b/c it calls `filter_image`, which needs
|
||||
# the values specified by the widgets. Alternatively, move call to
|
||||
# parent method to beginning and add a call to `self.filter_image()`
|
||||
super(CannyPlugin,self).attach(image_viewer)
|
||||
|
||||
Reference in New Issue
Block a user