Create helper function for image conversion

This commit is contained in:
Johannes Schönberger
2014-12-22 20:28:00 +01:00
parent dedcee6543
commit 3e881fe35c
2 changed files with 15 additions and 17 deletions
+13 -7
View File
@@ -995,6 +995,18 @@ def warp_coords(coord_map, shape, dtype=np.float64):
return coords
def _convert_warp_input(image, keep_range):
"""Convert input image to double image with the appropriate range."""
if keep_range:
image = image.astype(np.double)
else:
if image.dtype == np.double:
image = rescale_intensity(image)
else:
image = img_as_float(image)
return image
def _clip_warp_output(input_image, output_image, clip, mode, order, cval):
"""Clip output image to range of values of input image, considering the
parameters of a call to warp.
@@ -1146,13 +1158,7 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
"""
if keep_range:
image = image.astype(np.double)
else:
if image.dtype == np.double:
image = rescale_intensity(image)
else:
image = img_as_float(image)
image = _convert_warp_input(image, keep_range)
input_shape = np.array(image.shape)
+2 -10
View File
@@ -1,11 +1,9 @@
import numpy as np
from scipy import ndimage
from ..util import img_as_float
from ..exposure import rescale_intensity
from ..measure import block_reduce
from ._geometric import (warp, SimilarityTransform, AffineTransform,
_clip_warp_output)
_convert_warp_input, _clip_warp_output)
def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
@@ -81,13 +79,7 @@ def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
coord_map = np.array([map_rows, map_cols, map_dims])
if keep_range:
image = image.astype(np.double)
else:
if image.dtype == np.double:
image = rescale_intensity(image)
else:
image = img_as_float(image)
image = _convert_warp_input(image, keep_range)
out = ndimage.map_coordinates(image, coord_map, order=order,
mode=mode, cval=cval)