Skip to content

Commit

Permalink
rescale calls _multichannel_default too. update multichannel docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
grlee77 committed May 20, 2015
1 parent 9c2f76f commit 3a45e3c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
13 changes: 11 additions & 2 deletions skimage/transform/_warps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
_convert_warp_input, _clip_warp_output)


def _multichannel_default(multichannel, ndim):
# utility for maintaining previous color image default behavior
if ndim == 3:
return True
else:
return False


def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
preserve_range=False):
"""Resize image to match a certain size.
Expand Down Expand Up @@ -156,7 +164,8 @@ def rescale(image, scale, order=1, mode='constant', cval=0, clip=True,
Whether to keep the original range of values. Otherwise, the input
image is converted according to the conventions of `img_as_float`.
multichannel : bool, optional
If True, last axis will not be rescaled.
If True, last axis will not be rescaled. The default is True for 3D
(2D+color) inputs, False otherwise.
Examples
--------
Expand All @@ -170,7 +179,7 @@ def rescale(image, scale, order=1, mode='constant', cval=0, clip=True,
"""
if multichannel is None:
multichannel = False # maintain previous default behavior
multichannel = _multichannel_default(multichannel, image.ndim)
scale = np.atleast_1d(scale)
if len(scale) > 1 and len(scale) != image.ndim:
raise ValueError("must supply a single scale or one value per axis.")
Expand Down
37 changes: 17 additions & 20 deletions skimage/transform/pyramids.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@
from scipy import ndimage
from ..transform import resize
from ..util import img_as_float


def _previous_multichannel_default(multichannel, ndim):
if multichannel is None:
# needed to maintain previous default behavior
if ndim == 3:
return True
else:
return False
else:
return multichannel
from ._warps import _multichannel_default


def _smooth(image, sigma, mode, cval, multichannel=None):
"""Return image with each channel smoothed by the Gaussian filter."""
multichannel = _previous_multichannel_default(multichannel, image.ndim)
if multichannel is None:
multichannel = _multichannel_default(multichannel, image.ndim)
smoothed = np.empty(image.shape, dtype=np.double)

# apply Gaussian filter to all channels independently
Expand Down Expand Up @@ -61,8 +52,8 @@ def pyramid_reduce(image, downscale=2, sigma=None, order=1,
cval is the value when mode is equal to 'constant'.
cval : float, optional
Value to fill past edges of input if mode is 'constant'.
multichannel : bool, optional
If True and ``image.ndim > 2``, treat last axis as channels.
If True, last axis will not be rescaled. The default is True for 3D
(2D+color) inputs, False otherwise.
Returns
-------
Expand All @@ -74,7 +65,8 @@ def pyramid_reduce(image, downscale=2, sigma=None, order=1,
.. [1] http://web.mit.edu/persci/people/adelson/pub_pdfs/pyramid83.pdf
"""
multichannel = _previous_multichannel_default(multichannel, image.ndim)
if multichannel is None:
multichannel = _multichannel_default(multichannel, image.ndim)
_check_factor(downscale)

image = img_as_float(image)
Expand Down Expand Up @@ -116,7 +108,8 @@ def pyramid_expand(image, upscale=2, sigma=None, order=1,
cval : float, optional
Value to fill past edges of input if mode is 'constant'.
multichannel : bool, optional
If True and ``image.ndim > 2``, treat last axis as channels.
If True, last axis will not be rescaled. The default is True for 3D
(2D+color) inputs, False otherwise.
Returns
-------
Expand All @@ -128,7 +121,8 @@ def pyramid_expand(image, upscale=2, sigma=None, order=1,
.. [1] http://web.mit.edu/persci/people/adelson/pub_pdfs/pyramid83.pdf
"""
multichannel = _previous_multichannel_default(multichannel, image.ndim)
if multichannel is None:
multichannel = _multichannel_default(multichannel, image.ndim)
_check_factor(upscale)

image = img_as_float(image)
Expand Down Expand Up @@ -182,7 +176,8 @@ def pyramid_gaussian(image, max_layer=-1, downscale=2, sigma=None, order=1,
cval : float, optional
Value to fill past edges of input if mode is 'constant'.
multichannel : bool, optional
If True and ``image.ndim > 2``, treat last axis as channels.
If True, last axis will not be rescaled. The default is True for 3D
(2D+color) inputs, False otherwise.
Returns
-------
Expand Down Expand Up @@ -261,7 +256,8 @@ def pyramid_laplacian(image, max_layer=-1, downscale=2, sigma=None, order=1,
cval : float, optional
Value to fill past edges of input if mode is 'constant'.
multichannel : bool, optional
If True and ``image.ndim > 2``, treat last axis as channels.
If True, last axis will not be rescaled. The default is True for 3D
(2D+color) inputs, False otherwise.
Returns
-------
Expand All @@ -274,7 +270,8 @@ def pyramid_laplacian(image, max_layer=-1, downscale=2, sigma=None, order=1,
.. [2] http://sepwww.stanford.edu/~morgan/texturematch/paper_html/node3.html
"""
multichannel = _previous_multichannel_default(multichannel, image.ndim)
if multichannel is None:
multichannel = _multichannel_default(multichannel, image.ndim)
_check_factor(downscale)

# cast to float for consistent data type in pyramid
Expand Down

0 comments on commit 3a45e3c

Please sign in to comment.