We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Odd keyword name `min_size` for morphology's `remove_small_holes`
Should the `min_size` parameter be `max_size`, or something else entirely?  It's not a very intuitive naming.  At worst, we should document this well.

/cc @mcquin

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `skimage/morphology/misc.py`
Content:
```
1 import numpy as np
2 import functools
3 from scipy import ndimage as ndi
4 from .._shared.utils import warn
5 from .selem import _default_selem
6 
7 # Our function names don't exactly correspond to ndimages.
8 # This dictionary translates from our names to scipy's.
9 funcs = ('erosion', 'dilation', 'opening', 'closing')
10 skimage2ndimage = dict((x, 'grey_' + x) for x in funcs)
11 
12 # These function names are the same in ndimage.
13 funcs = ('binary_erosion', 'binary_dilation', 'binary_opening',
14          'binary_closing', 'black_tophat', 'white_tophat')
15 skimage2ndimage.update(dict((x, x) for x in funcs))
16 
17 
18 def default_selem(func):
19     """Decorator to add a default structuring element to morphology functions.
20 
21     Parameters
22     ----------
23     func : function
24         A morphology function such as erosion, dilation, opening, closing,
25         white_tophat, or black_tophat.
26 
27     Returns
28     -------
29     func_out : function
30         The function, using a default structuring element of same dimension
31         as the input image with connectivity 1.
32     """
33     @functools.wraps(func)
34     def func_out(image, selem=None, *args, **kwargs):
35         if selem is None:
36             selem = _default_selem(image.ndim)
37         return func(image, selem=selem, *args, **kwargs)
38 
39     return func_out
40 
41 def _check_dtype_supported(ar):
42     # Should use `issubdtype` for bool below, but there's a bug in numpy 1.7
43     if not (ar.dtype == bool or np.issubdtype(ar.dtype, np.integer)):
44         raise TypeError("Only bool or integer image types are supported. "
45                         "Got %s." % ar.dtype)
46 
47 def remove_small_objects(ar, min_size=64, connectivity=1, in_place=False):
48     """Remove connected components smaller than the specified size.
49 
50     Parameters
51     ----------
52     ar : ndarray (arbitrary shape, int or bool type)
53         The array containing the connected components of interest. If the array
54         type is int, it is assumed that it contains already-labeled objects.
55         The ints must be non-negative.
56     min_size : int, optional (default: 64)
57         The smallest allowable connected component size.
58     connectivity : int, {1, 2, ..., ar.ndim}, optional (default: 1)
59         The connectivity defining the neighborhood of a pixel.
60     in_place : bool, optional (default: False)
61         If `True`, remove the connected components in the input array itself.
62         Otherwise, make a copy.
63 
64     Raises
65     ------
66     TypeError
67         If the input array is of an invalid type, such as float or string.
68     ValueError
69         If the input array contains negative values.
70 
71     Returns
72     -------
73     out : ndarray, same shape and type as input `ar`
74         The input array with small connected components removed.
75 
76     Examples
77     --------
78     >>> from skimage import morphology
79     >>> a = np.array([[0, 0, 0, 1, 0],
80     ...               [1, 1, 1, 0, 0],
81     ...               [1, 1, 1, 0, 1]], bool)
82     >>> b = morphology.remove_small_objects(a, 6)
83     >>> b
84     array([[False, False, False, False, False],
85            [ True,  True,  True, False, False],
86            [ True,  True,  True, False, False]], dtype=bool)
87     >>> c = morphology.remove_small_objects(a, 7, connectivity=2)
88     >>> c
89     array([[False, False, False,  True, False],
90            [ True,  True,  True, False, False],
91            [ True,  True,  True, False, False]], dtype=bool)
92     >>> d = morphology.remove_small_objects(a, 6, in_place=True)
93     >>> d is a
94     True
95     """
96     # Raising type error if not int or bool
97     _check_dtype_supported(ar)
98 
99     if in_place:
100         out = ar
101     else:
102         out = ar.copy()
103 
104     if min_size == 0:  # shortcut for efficiency
105         return out
106 
107     if out.dtype == bool:
108         selem = ndi.generate_binary_structure(ar.ndim, connectivity)
109         ccs = np.zeros_like(ar, dtype=np.int32)
110         ndi.label(ar, selem, output=ccs)
111     else:
112         ccs = out
113 
114     try:
115         component_sizes = np.bincount(ccs.ravel())
116     except ValueError:
117         raise ValueError("Negative value labels are not supported. Try "
118                          "relabeling the input with `scipy.ndimage.label` or "
119                          "`skimage.morphology.label`.")
120 
121     if len(component_sizes) == 2:
122         warn("Only one label was provided to `remove_small_objects`. "
123              "Did you mean to use a boolean array?")
124 
125     too_small = component_sizes < min_size
126     too_small_mask = too_small[ccs]
127     out[too_small_mask] = 0
128 
129     return out
130 
131 def remove_small_holes(ar, min_size=64, connectivity=1, in_place=False):
132     """Remove continguous holes smaller than the specified size.
133 
134     Parameters
135     ----------
136     ar : ndarray (arbitrary shape, int or bool type)
137         The array containing the connected components of interest.
138     min_size : int, optional (default: 64)
139         The hole component size.
140     connectivity : int, {1, 2, ..., ar.ndim}, optional (default: 1)
141         The connectivity defining the neighborhood of a pixel.
142     in_place : bool, optional (default: False)
143         If `True`, remove the connected components in the input array itself.
144         Otherwise, make a copy.
145 
146     Raises
147     ------
148     TypeError
149         If the input array is of an invalid type, such as float or string.
150     ValueError
151         If the input array contains negative values.
152 
153     Returns
154     -------
155     out : ndarray, same shape and type as input `ar`
156         The input array with small holes within connected components removed.
157 
158     Examples
159     --------
160     >>> from skimage import morphology
161     >>> a = np.array([[1, 1, 1, 1, 1, 0],
162     ...               [1, 1, 1, 0, 1, 0],
163     ...               [1, 0, 0, 1, 1, 0],
164     ...               [1, 1, 1, 1, 1, 0]], bool)
165     >>> b = morphology.remove_small_holes(a, 2)
166     >>> b
167     array([[ True,  True,  True,  True,  True, False],
168            [ True,  True,  True,  True,  True, False],
169            [ True, False, False,  True,  True, False],
170            [ True,  True,  True,  True,  True, False]], dtype=bool)
171     >>> c = morphology.remove_small_holes(a, 2, connectivity=2)
172     >>> c
173     array([[ True,  True,  True,  True,  True, False],
174            [ True,  True,  True, False,  True, False],
175            [ True, False, False,  True,  True, False],
176            [ True,  True,  True,  True,  True, False]], dtype=bool)
177     >>> d = morphology.remove_small_holes(a, 2, in_place=True)
178     >>> d is a
179     True
180 
181     Notes
182     -----
183 
184     If the array type is int, it is assumed that it contains already-labeled
185     objects. The labels are not kept in the output image (this function always
186     outputs a bool image). It is suggested that labeling is completed after
187     using this function.
188     """
189     _check_dtype_supported(ar)
190 
191     #Creates warning if image is an integer image
192     if ar.dtype != bool:
193         warn("Any labeled images will be returned as a boolean array. "
194              "Did you mean to use a boolean array?", UserWarning)
195 
196     if in_place:
197         out = ar
198     else:
199         out = ar.copy()
200 
201     #Creating the inverse of ar
202     if in_place:
203         out = np.logical_not(out,out)
204     else:
205         out = np.logical_not(out)
206 
207     #removing small objects from the inverse of ar
208     out = remove_small_objects(out, min_size, connectivity, in_place)
209 
210     if in_place:
211         out = np.logical_not(out,out)
212     else:
213         out = np.logical_not(out)
214 
215     return out
216
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/skimage/morphology/misc.py b/skimage/morphology/misc.py
--- a/skimage/morphology/misc.py
+++ b/skimage/morphology/misc.py
@@ -1,3 +1,4 @@
+"""Miscellaneous morphology functions."""
 import numpy as np
 import functools
 from scipy import ndimage as ndi
@@ -29,6 +30,7 @@
     func_out : function
         The function, using a default structuring element of same dimension
         as the input image with connectivity 1.
+
     """
     @functools.wraps(func)
     def func_out(image, selem=None, *args, **kwargs):
@@ -38,12 +40,14 @@
 
     return func_out
 
+
 def _check_dtype_supported(ar):
     # Should use `issubdtype` for bool below, but there's a bug in numpy 1.7
     if not (ar.dtype == bool or np.issubdtype(ar.dtype, np.integer)):
         raise TypeError("Only bool or integer image types are supported. "
                         "Got %s." % ar.dtype)
 
+
 def remove_small_objects(ar, min_size=64, connectivity=1, in_place=False):
     """Remove connected components smaller than the specified size.
 
@@ -92,6 +96,7 @@
     >>> d = morphology.remove_small_objects(a, 6, in_place=True)
     >>> d is a
     True
+
     """
     # Raising type error if not int or bool
     _check_dtype_supported(ar)
@@ -128,21 +133,25 @@
 
     return out
 
-def remove_small_holes(ar, min_size=64, connectivity=1, in_place=False):
+
+def remove_small_holes(ar, area_threshold=64, connectivity=1, in_place=False,
+                       min_size=None):
     """Remove continguous holes smaller than the specified size.
 
     Parameters
     ----------
     ar : ndarray (arbitrary shape, int or bool type)
         The array containing the connected components of interest.
-    min_size : int, optional (default: 64)
-        The hole component size.
+    area_threshold : int, optional (default: 64)
+        The maximum area, in pixels, of a contiguous hole that will be filled.
+        Replaces `min_size`.
     connectivity : int, {1, 2, ..., ar.ndim}, optional (default: 1)
         The connectivity defining the neighborhood of a pixel.
     in_place : bool, optional (default: False)
         If `True`, remove the connected components in the input array itself.
         Otherwise, make a copy.
 
+
     Raises
     ------
     TypeError
@@ -180,35 +189,40 @@
 
     Notes
     -----
-
     If the array type is int, it is assumed that it contains already-labeled
     objects. The labels are not kept in the output image (this function always
     outputs a bool image). It is suggested that labeling is completed after
     using this function.
+
     """
     _check_dtype_supported(ar)
 
-    #Creates warning if image is an integer image
+    # Creates warning if image is an integer image
     if ar.dtype != bool:
         warn("Any labeled images will be returned as a boolean array. "
              "Did you mean to use a boolean array?", UserWarning)
 
+    if min_size is not None:
+        warn("the min_size argument is deprecated and will be removed in " +
+             "0.16. Use area_threshold instead.")
+        area_threshold = min_size
+
     if in_place:
         out = ar
     else:
         out = ar.copy()
 
-    #Creating the inverse of ar
+    # Creating the inverse of ar
     if in_place:
-        out = np.logical_not(out,out)
+        out = np.logical_not(out, out)
     else:
         out = np.logical_not(out)
 
-    #removing small objects from the inverse of ar
-    out = remove_small_objects(out, min_size, connectivity, in_place)
+    # removing small objects from the inverse of ar
+    out = remove_small_objects(out, area_threshold, connectivity, in_place)
 
     if in_place:
-        out = np.logical_not(out,out)
+        out = np.logical_not(out, out)
     else:
         out = np.logical_not(out)

{"golden_diff": "diff --git a/skimage/morphology/misc.py b/skimage/morphology/misc.py\n--- a/skimage/morphology/misc.py\n+++ b/skimage/morphology/misc.py\n@@ -1,3 +1,4 @@\n+\"\"\"Miscellaneous morphology functions.\"\"\"\n import numpy as np\n import functools\n from scipy import ndimage as ndi\n@@ -29,6 +30,7 @@\n     func_out : function\n         The function, using a default structuring element of same dimension\n         as the input image with connectivity 1.\n+\n     \"\"\"\n     @functools.wraps(func)\n     def func_out(image, selem=None, *args, **kwargs):\n@@ -38,12 +40,14 @@\n \n     return func_out\n \n+\n def _check_dtype_supported(ar):\n     # Should use `issubdtype` for bool below, but there's a bug in numpy 1.7\n     if not (ar.dtype == bool or np.issubdtype(ar.dtype, np.integer)):\n         raise TypeError(\"Only bool or integer image types are supported. \"\n                         \"Got %s.\" % ar.dtype)\n \n+\n def remove_small_objects(ar, min_size=64, connectivity=1, in_place=False):\n     \"\"\"Remove connected components smaller than the specified size.\n \n@@ -92,6 +96,7 @@\n     >>> d = morphology.remove_small_objects(a, 6, in_place=True)\n     >>> d is a\n     True\n+\n     \"\"\"\n     # Raising type error if not int or bool\n     _check_dtype_supported(ar)\n@@ -128,21 +133,25 @@\n \n     return out\n \n-def remove_small_holes(ar, min_size=64, connectivity=1, in_place=False):\n+\n+def remove_small_holes(ar, area_threshold=64, connectivity=1, in_place=False,\n+                       min_size=None):\n     \"\"\"Remove continguous holes smaller than the specified size.\n \n     Parameters\n     ----------\n     ar : ndarray (arbitrary shape, int or bool type)\n         The array containing the connected components of interest.\n-    min_size : int, optional (default: 64)\n-        The hole component size.\n+    area_threshold : int, optional (default: 64)\n+        The maximum area, in pixels, of a contiguous hole that will be filled.\n+        Replaces `min_size`.\n     connectivity : int, {1, 2, ..., ar.ndim}, optional (default: 1)\n         The connectivity defining the neighborhood of a pixel.\n     in_place : bool, optional (default: False)\n         If `True`, remove the connected components in the input array itself.\n         Otherwise, make a copy.\n \n+\n     Raises\n     ------\n     TypeError\n@@ -180,35 +189,40 @@\n \n     Notes\n     -----\n-\n     If the array type is int, it is assumed that it contains already-labeled\n     objects. The labels are not kept in the output image (this function always\n     outputs a bool image). It is suggested that labeling is completed after\n     using this function.\n+\n     \"\"\"\n     _check_dtype_supported(ar)\n \n-    #Creates warning if image is an integer image\n+    # Creates warning if image is an integer image\n     if ar.dtype != bool:\n         warn(\"Any labeled images will be returned as a boolean array. \"\n              \"Did you mean to use a boolean array?\", UserWarning)\n \n+    if min_size is not None:\n+        warn(\"the min_size argument is deprecated and will be removed in \" +\n+             \"0.16. Use area_threshold instead.\")\n+        area_threshold = min_size\n+\n     if in_place:\n         out = ar\n     else:\n         out = ar.copy()\n \n-    #Creating the inverse of ar\n+    # Creating the inverse of ar\n     if in_place:\n-        out = np.logical_not(out,out)\n+        out = np.logical_not(out, out)\n     else:\n         out = np.logical_not(out)\n \n-    #removing small objects from the inverse of ar\n-    out = remove_small_objects(out, min_size, connectivity, in_place)\n+    # removing small objects from the inverse of ar\n+    out = remove_small_objects(out, area_threshold, connectivity, in_place)\n \n     if in_place:\n-        out = np.logical_not(out,out)\n+        out = np.logical_not(out, out)\n     else:\n         out = np.logical_not(out)\n", "issue": "Odd keyword name `min_size` for morphology's `remove_small_holes`\nShould the `min_size` parameter be `max_size`, or something else entirely?  It's not a very intuitive naming.  At worst, we should document this well.\r\n\r\n/cc @mcquin\n", "before_files": [{"content": "import numpy as np\nimport functools\nfrom scipy import ndimage as ndi\nfrom .._shared.utils import warn\nfrom .selem import _default_selem\n\n# Our function names don't exactly correspond to ndimages.\n# This dictionary translates from our names to scipy's.\nfuncs = ('erosion', 'dilation', 'opening', 'closing')\nskimage2ndimage = dict((x, 'grey_' + x) for x in funcs)\n\n# These function names are the same in ndimage.\nfuncs = ('binary_erosion', 'binary_dilation', 'binary_opening',\n         'binary_closing', 'black_tophat', 'white_tophat')\nskimage2ndimage.update(dict((x, x) for x in funcs))\n\n\ndef default_selem(func):\n    \"\"\"Decorator to add a default structuring element to morphology functions.\n\n    Parameters\n    ----------\n    func : function\n        A morphology function such as erosion, dilation, opening, closing,\n        white_tophat, or black_tophat.\n\n    Returns\n    -------\n    func_out : function\n        The function, using a default structuring element of same dimension\n        as the input image with connectivity 1.\n    \"\"\"\n    @functools.wraps(func)\n    def func_out(image, selem=None, *args, **kwargs):\n        if selem is None:\n            selem = _default_selem(image.ndim)\n        return func(image, selem=selem, *args, **kwargs)\n\n    return func_out\n\ndef _check_dtype_supported(ar):\n    # Should use `issubdtype` for bool below, but there's a bug in numpy 1.7\n    if not (ar.dtype == bool or np.issubdtype(ar.dtype, np.integer)):\n        raise TypeError(\"Only bool or integer image types are supported. \"\n                        \"Got %s.\" % ar.dtype)\n\ndef remove_small_objects(ar, min_size=64, connectivity=1, in_place=False):\n    \"\"\"Remove connected components smaller than the specified size.\n\n    Parameters\n    ----------\n    ar : ndarray (arbitrary shape, int or bool type)\n        The array containing the connected components of interest. If the array\n        type is int, it is assumed that it contains already-labeled objects.\n        The ints must be non-negative.\n    min_size : int, optional (default: 64)\n        The smallest allowable connected component size.\n    connectivity : int, {1, 2, ..., ar.ndim}, optional (default: 1)\n        The connectivity defining the neighborhood of a pixel.\n    in_place : bool, optional (default: False)\n        If `True`, remove the connected components in the input array itself.\n        Otherwise, make a copy.\n\n    Raises\n    ------\n    TypeError\n        If the input array is of an invalid type, such as float or string.\n    ValueError\n        If the input array contains negative values.\n\n    Returns\n    -------\n    out : ndarray, same shape and type as input `ar`\n        The input array with small connected components removed.\n\n    Examples\n    --------\n    >>> from skimage import morphology\n    >>> a = np.array([[0, 0, 0, 1, 0],\n    ...               [1, 1, 1, 0, 0],\n    ...               [1, 1, 1, 0, 1]], bool)\n    >>> b = morphology.remove_small_objects(a, 6)\n    >>> b\n    array([[False, False, False, False, False],\n           [ True,  True,  True, False, False],\n           [ True,  True,  True, False, False]], dtype=bool)\n    >>> c = morphology.remove_small_objects(a, 7, connectivity=2)\n    >>> c\n    array([[False, False, False,  True, False],\n           [ True,  True,  True, False, False],\n           [ True,  True,  True, False, False]], dtype=bool)\n    >>> d = morphology.remove_small_objects(a, 6, in_place=True)\n    >>> d is a\n    True\n    \"\"\"\n    # Raising type error if not int or bool\n    _check_dtype_supported(ar)\n\n    if in_place:\n        out = ar\n    else:\n        out = ar.copy()\n\n    if min_size == 0:  # shortcut for efficiency\n        return out\n\n    if out.dtype == bool:\n        selem = ndi.generate_binary_structure(ar.ndim, connectivity)\n        ccs = np.zeros_like(ar, dtype=np.int32)\n        ndi.label(ar, selem, output=ccs)\n    else:\n        ccs = out\n\n    try:\n        component_sizes = np.bincount(ccs.ravel())\n    except ValueError:\n        raise ValueError(\"Negative value labels are not supported. Try \"\n                         \"relabeling the input with `scipy.ndimage.label` or \"\n                         \"`skimage.morphology.label`.\")\n\n    if len(component_sizes) == 2:\n        warn(\"Only one label was provided to `remove_small_objects`. \"\n             \"Did you mean to use a boolean array?\")\n\n    too_small = component_sizes < min_size\n    too_small_mask = too_small[ccs]\n    out[too_small_mask] = 0\n\n    return out\n\ndef remove_small_holes(ar, min_size=64, connectivity=1, in_place=False):\n    \"\"\"Remove continguous holes smaller than the specified size.\n\n    Parameters\n    ----------\n    ar : ndarray (arbitrary shape, int or bool type)\n        The array containing the connected components of interest.\n    min_size : int, optional (default: 64)\n        The hole component size.\n    connectivity : int, {1, 2, ..., ar.ndim}, optional (default: 1)\n        The connectivity defining the neighborhood of a pixel.\n    in_place : bool, optional (default: False)\n        If `True`, remove the connected components in the input array itself.\n        Otherwise, make a copy.\n\n    Raises\n    ------\n    TypeError\n        If the input array is of an invalid type, such as float or string.\n    ValueError\n        If the input array contains negative values.\n\n    Returns\n    -------\n    out : ndarray, same shape and type as input `ar`\n        The input array with small holes within connected components removed.\n\n    Examples\n    --------\n    >>> from skimage import morphology\n    >>> a = np.array([[1, 1, 1, 1, 1, 0],\n    ...               [1, 1, 1, 0, 1, 0],\n    ...               [1, 0, 0, 1, 1, 0],\n    ...               [1, 1, 1, 1, 1, 0]], bool)\n    >>> b = morphology.remove_small_holes(a, 2)\n    >>> b\n    array([[ True,  True,  True,  True,  True, False],\n           [ True,  True,  True,  True,  True, False],\n           [ True, False, False,  True,  True, False],\n           [ True,  True,  True,  True,  True, False]], dtype=bool)\n    >>> c = morphology.remove_small_holes(a, 2, connectivity=2)\n    >>> c\n    array([[ True,  True,  True,  True,  True, False],\n           [ True,  True,  True, False,  True, False],\n           [ True, False, False,  True,  True, False],\n           [ True,  True,  True,  True,  True, False]], dtype=bool)\n    >>> d = morphology.remove_small_holes(a, 2, in_place=True)\n    >>> d is a\n    True\n\n    Notes\n    -----\n\n    If the array type is int, it is assumed that it contains already-labeled\n    objects. The labels are not kept in the output image (this function always\n    outputs a bool image). It is suggested that labeling is completed after\n    using this function.\n    \"\"\"\n    _check_dtype_supported(ar)\n\n    #Creates warning if image is an integer image\n    if ar.dtype != bool:\n        warn(\"Any labeled images will be returned as a boolean array. \"\n             \"Did you mean to use a boolean array?\", UserWarning)\n\n    if in_place:\n        out = ar\n    else:\n        out = ar.copy()\n\n    #Creating the inverse of ar\n    if in_place:\n        out = np.logical_not(out,out)\n    else:\n        out = np.logical_not(out)\n\n    #removing small objects from the inverse of ar\n    out = remove_small_objects(out, min_size, connectivity, in_place)\n\n    if in_place:\n        out = np.logical_not(out,out)\n    else:\n        out = np.logical_not(out)\n\n    return out\n", "path": "skimage/morphology/misc.py"}], "after_files": [{"content": "\"\"\"Miscellaneous morphology functions.\"\"\"\nimport numpy as np\nimport functools\nfrom scipy import ndimage as ndi\nfrom .._shared.utils import warn\nfrom .selem import _default_selem\n\n# Our function names don't exactly correspond to ndimages.\n# This dictionary translates from our names to scipy's.\nfuncs = ('erosion', 'dilation', 'opening', 'closing')\nskimage2ndimage = dict((x, 'grey_' + x) for x in funcs)\n\n# These function names are the same in ndimage.\nfuncs = ('binary_erosion', 'binary_dilation', 'binary_opening',\n         'binary_closing', 'black_tophat', 'white_tophat')\nskimage2ndimage.update(dict((x, x) for x in funcs))\n\n\ndef default_selem(func):\n    \"\"\"Decorator to add a default structuring element to morphology functions.\n\n    Parameters\n    ----------\n    func : function\n        A morphology function such as erosion, dilation, opening, closing,\n        white_tophat, or black_tophat.\n\n    Returns\n    -------\n    func_out : function\n        The function, using a default structuring element of same dimension\n        as the input image with connectivity 1.\n\n    \"\"\"\n    @functools.wraps(func)\n    def func_out(image, selem=None, *args, **kwargs):\n        if selem is None:\n            selem = _default_selem(image.ndim)\n        return func(image, selem=selem, *args, **kwargs)\n\n    return func_out\n\n\ndef _check_dtype_supported(ar):\n    # Should use `issubdtype` for bool below, but there's a bug in numpy 1.7\n    if not (ar.dtype == bool or np.issubdtype(ar.dtype, np.integer)):\n        raise TypeError(\"Only bool or integer image types are supported. \"\n                        \"Got %s.\" % ar.dtype)\n\n\ndef remove_small_objects(ar, min_size=64, connectivity=1, in_place=False):\n    \"\"\"Remove connected components smaller than the specified size.\n\n    Parameters\n    ----------\n    ar : ndarray (arbitrary shape, int or bool type)\n        The array containing the connected components of interest. If the array\n        type is int, it is assumed that it contains already-labeled objects.\n        The ints must be non-negative.\n    min_size : int, optional (default: 64)\n        The smallest allowable connected component size.\n    connectivity : int, {1, 2, ..., ar.ndim}, optional (default: 1)\n        The connectivity defining the neighborhood of a pixel.\n    in_place : bool, optional (default: False)\n        If `True`, remove the connected components in the input array itself.\n        Otherwise, make a copy.\n\n    Raises\n    ------\n    TypeError\n        If the input array is of an invalid type, such as float or string.\n    ValueError\n        If the input array contains negative values.\n\n    Returns\n    -------\n    out : ndarray, same shape and type as input `ar`\n        The input array with small connected components removed.\n\n    Examples\n    --------\n    >>> from skimage import morphology\n    >>> a = np.array([[0, 0, 0, 1, 0],\n    ...               [1, 1, 1, 0, 0],\n    ...               [1, 1, 1, 0, 1]], bool)\n    >>> b = morphology.remove_small_objects(a, 6)\n    >>> b\n    array([[False, False, False, False, False],\n           [ True,  True,  True, False, False],\n           [ True,  True,  True, False, False]], dtype=bool)\n    >>> c = morphology.remove_small_objects(a, 7, connectivity=2)\n    >>> c\n    array([[False, False, False,  True, False],\n           [ True,  True,  True, False, False],\n           [ True,  True,  True, False, False]], dtype=bool)\n    >>> d = morphology.remove_small_objects(a, 6, in_place=True)\n    >>> d is a\n    True\n\n    \"\"\"\n    # Raising type error if not int or bool\n    _check_dtype_supported(ar)\n\n    if in_place:\n        out = ar\n    else:\n        out = ar.copy()\n\n    if min_size == 0:  # shortcut for efficiency\n        return out\n\n    if out.dtype == bool:\n        selem = ndi.generate_binary_structure(ar.ndim, connectivity)\n        ccs = np.zeros_like(ar, dtype=np.int32)\n        ndi.label(ar, selem, output=ccs)\n    else:\n        ccs = out\n\n    try:\n        component_sizes = np.bincount(ccs.ravel())\n    except ValueError:\n        raise ValueError(\"Negative value labels are not supported. Try \"\n                         \"relabeling the input with `scipy.ndimage.label` or \"\n                         \"`skimage.morphology.label`.\")\n\n    if len(component_sizes) == 2:\n        warn(\"Only one label was provided to `remove_small_objects`. \"\n             \"Did you mean to use a boolean array?\")\n\n    too_small = component_sizes < min_size\n    too_small_mask = too_small[ccs]\n    out[too_small_mask] = 0\n\n    return out\n\n\ndef remove_small_holes(ar, area_threshold=64, connectivity=1, in_place=False,\n                       min_size=None):\n    \"\"\"Remove continguous holes smaller than the specified size.\n\n    Parameters\n    ----------\n    ar : ndarray (arbitrary shape, int or bool type)\n        The array containing the connected components of interest.\n    area_threshold : int, optional (default: 64)\n        The maximum area, in pixels, of a contiguous hole that will be filled.\n        Replaces `min_size`.\n    connectivity : int, {1, 2, ..., ar.ndim}, optional (default: 1)\n        The connectivity defining the neighborhood of a pixel.\n    in_place : bool, optional (default: False)\n        If `True`, remove the connected components in the input array itself.\n        Otherwise, make a copy.\n\n\n    Raises\n    ------\n    TypeError\n        If the input array is of an invalid type, such as float or string.\n    ValueError\n        If the input array contains negative values.\n\n    Returns\n    -------\n    out : ndarray, same shape and type as input `ar`\n        The input array with small holes within connected components removed.\n\n    Examples\n    --------\n    >>> from skimage import morphology\n    >>> a = np.array([[1, 1, 1, 1, 1, 0],\n    ...               [1, 1, 1, 0, 1, 0],\n    ...               [1, 0, 0, 1, 1, 0],\n    ...               [1, 1, 1, 1, 1, 0]], bool)\n    >>> b = morphology.remove_small_holes(a, 2)\n    >>> b\n    array([[ True,  True,  True,  True,  True, False],\n           [ True,  True,  True,  True,  True, False],\n           [ True, False, False,  True,  True, False],\n           [ True,  True,  True,  True,  True, False]], dtype=bool)\n    >>> c = morphology.remove_small_holes(a, 2, connectivity=2)\n    >>> c\n    array([[ True,  True,  True,  True,  True, False],\n           [ True,  True,  True, False,  True, False],\n           [ True, False, False,  True,  True, False],\n           [ True,  True,  True,  True,  True, False]], dtype=bool)\n    >>> d = morphology.remove_small_holes(a, 2, in_place=True)\n    >>> d is a\n    True\n\n    Notes\n    -----\n    If the array type is int, it is assumed that it contains already-labeled\n    objects. The labels are not kept in the output image (this function always\n    outputs a bool image). It is suggested that labeling is completed after\n    using this function.\n\n    \"\"\"\n    _check_dtype_supported(ar)\n\n    # Creates warning if image is an integer image\n    if ar.dtype != bool:\n        warn(\"Any labeled images will be returned as a boolean array. \"\n             \"Did you mean to use a boolean array?\", UserWarning)\n\n    if min_size is not None:\n        warn(\"the min_size argument is deprecated and will be removed in \" +\n             \"0.16. Use area_threshold instead.\")\n        area_threshold = min_size\n\n    if in_place:\n        out = ar\n    else:\n        out = ar.copy()\n\n    # Creating the inverse of ar\n    if in_place:\n        out = np.logical_not(out, out)\n    else:\n        out = np.logical_not(out)\n\n    # removing small objects from the inverse of ar\n    out = remove_small_objects(out, area_threshold, connectivity, in_place)\n\n    if in_place:\n        out = np.logical_not(out, out)\n    else:\n        out = np.logical_not(out)\n\n    return out\n", "path": "skimage/morphology/misc.py"}]}