本文整理匯總了Python中skimage.img_as_float方法的典型用法代碼示例。如果您正苦於以下問題:Python skimage.img_as_float方法的具體用法?Python skimage.img_as_float怎麽用?Python skimage.img_as_float使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類skimage
的用法示例。
在下文中一共展示了skimage.img_as_float方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: crop_image
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def crop_image(x, target_height=227, target_width=227):
image = skimage.img_as_float(skimage.io.imread(x)).astype(np.float32)
if len(image.shape) == 2:
image = np.tile(image[:,:,None], 3)
elif len(image.shape) == 4:
image = image[:,:,:,0]
height, width, rgb = image.shape
if width == height:
resized_image = skimage.transform.resize(image, (target_height,target_width))
elif height < width:
resized_image = skimage.transform.resize(image, (int(width * float(target_height)/height), target_width))
cropping_length = int((resized_image.shape[1] - target_height) / 2)
resized_image = resized_image[:,cropping_length:resized_image.shape[1] - cropping_length]
else:
resized_image = skimage.transform.resize(image, (target_height, int(height * float(target_width) / width)))
cropping_length = int((resized_image.shape[0] - target_width) / 2)
resized_image = resized_image[cropping_length:resized_image.shape[0] - cropping_length,:]
return skimage.transform.resize(resized_image, (target_height, target_width))
示例2: bsds500_train
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def bsds500_train(input_root):
import scipy.io as SIO
from skimage import img_as_float
from skimage.io import imread
dataset_dir = os.path.join(input_root, "BSDS500", "data")
image_dir = os.path.join(dataset_dir, "images", "train")
label_dir = os.path.join(dataset_dir, "groundTruth", "train")
data = []
for file_name in os.listdir(label_dir):
gts = SIO.loadmat(os.path.join(label_dir, file_name))
gts = gts["groundTruth"].flatten()
bnds = [gt["Boundaries"][0, 0] for gt in gts]
segs = [gt["Segmentation"][0, 0] for gt in gts]
img = imread(os.path.join(image_dir, file_name[:-3] + "jpg"))
img = img_as_float(img)
data.append((img, bnds, segs))
return data
示例3: bsds500_test
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def bsds500_test(model, input_root, output_root):
from skimage import img_as_float, img_as_ubyte
from skimage.io import imread, imsave
if not os.path.exists(output_root):
os.makedirs(output_root)
image_dir = os.path.join(input_root, "BSDS500", "data", "images", "test")
file_names = filter(lambda name: name[-3:] == "jpg", os.listdir(image_dir))
n_image = len(file_names)
for i, file_name in enumerate(file_names):
img = img_as_float(imread(os.path.join(image_dir, file_name)))
edge = img_as_ubyte(model.predict(img))
imsave(os.path.join(output_root, file_name[:-3] + "png"), edge)
sys.stdout.write("Processing Image %d/%d\r" % (i + 1, n_image))
sys.stdout.flush()
print
示例4: crop_image
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def crop_image(self, x, target_height=224, target_width=224):
image = skimage.img_as_float(skimage.io.imread(x)).astype(np.float32)
if len(image.shape) == 2:
image = np.tile(image[:,:,None], 3)
elif len(image.shape) == 4:
image = image[:,:,:,0]
height, width, rgb = image.shape
if width == height:
resized_image = cv2.resize(image, (target_height,target_width))
elif height < width:
resized_image = cv2.resize(image, (int(width * float(target_height)/height), target_width))
cropping_length = int((resized_image.shape[1] - target_height) / 2)
resized_image = resized_image[:,cropping_length:resized_image.shape[1] - cropping_length]
else:
resized_image = cv2.resize(image, (target_height, int(height * float(target_width) / width)))
cropping_length = int((resized_image.shape[0] - target_width) / 2)
resized_image = resized_image[cropping_length:resized_image.shape[0] - cropping_length,:]
return cv2.resize(resized_image, (target_height, target_width))
####### Network Parameters ########
示例5: load_scaled_image
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def load_scaled_image( filename, color=True ):
"""
Load an image converting from grayscale or alpha as needed.
From KChen
Args:
filename : string
color : boolean
flag for color format. True (default) loads as RGB while False
loads as intensity (if image is already grayscale).
Returns
image : an image with type np.float32 in range [0, 1]
of size (H x W x 3) in RGB or
of size (H x W x 1) in grayscale.
By kchen
"""
img = skimage.img_as_float(skimage.io.imread(filename, as_grey=not color)).astype(np.float32)
if img.ndim == 2:
img = img[:, :, np.newaxis]
if color:
img = np.tile(img, (1, 1, 3))
elif img.shape[2] == 4:
img = img[:, :, :3]
return img
示例6: resize_rescale_imagenet
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def resize_rescale_imagenet(img, new_dims, interp_order=1, current_scale=None, no_clip=False):
"""
Resize an image array with interpolation, and rescale to be
between
Parameters
----------
im : (H x W x K) ndarray
new_dims : (height, width) tuple of new dimensions.
new_scale : (min, max) tuple of new scale.
interp_order : interpolation order, default is linear.
Returns
-------
im : resized ndarray with shape (new_dims[0], new_dims[1], K)
"""
img = skimage.img_as_float( img )
img = resize_image( img, new_dims, interp_order )
img = img[:,:,[2,1,0]] * 255.
mean_bgr = [103.062623801, 115.902882574, 123.151630838]
img = img - mean_bgr
return img
示例7: resize_rescale_image_low_sat
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def resize_rescale_image_low_sat(img, new_dims, new_scale, interp_order=1, current_scale=None, no_clip=False):
"""
Resize an image array with interpolation, and rescale to be
between
Parameters
----------
im : (H x W x K) ndarray
new_dims : (height, width) tuple of new dimensions.
new_scale : (min, max) tuple of new scale.
interp_order : interpolation order, default is linear.
Returns
-------
im : resized ndarray with shape (new_dims[0], new_dims[1], K)
"""
img = skimage.img_as_float( img )
img = resize_image( img, new_dims, interp_order )
img = np.clip(img, 0.1, 0.9)
img = rescale_image( img, new_scale, current_scale=current_scale, no_clip=no_clip )
return img
示例8: resize_rescale_image_low_sat_2
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def resize_rescale_image_low_sat_2(img, new_dims, new_scale, interp_order=1, current_scale=None, no_clip=False):
"""
Resize an image array with interpolation, and rescale to be
between
Parameters
----------
im : (H x W x K) ndarray
new_dims : (height, width) tuple of new dimensions.
new_scale : (min, max) tuple of new scale.
interp_order : interpolation order, default is linear.
Returns
-------
im : resized ndarray with shape (new_dims[0], new_dims[1], K)
"""
img = skimage.img_as_float( img )
img = resize_image( img, new_dims, interp_order )
img = np.clip(img, 0.2, 0.8)
img = rescale_image( img, new_scale, current_scale=current_scale, no_clip=no_clip )
return img
示例9: resize_rescale_image
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def resize_rescale_image(img, new_dims, new_scale, interp_order=1, current_scale=None, no_clip=False):
"""
Resize an image array with interpolation, and rescale to be
between
Parameters
----------
im : (H x W x K) ndarray
new_dims : (height, width) tuple of new dimensions.
new_scale : (min, max) tuple of new scale.
interp_order : interpolation order, default is linear.
Returns
-------
im : resized ndarray with shape (new_dims[0], new_dims[1], K)
"""
img = skimage.img_as_float( img )
img = resize_image( img, new_dims, interp_order )
img = rescale_image( img, new_scale, current_scale=current_scale, no_clip=no_clip )
return img
示例10: random_noise_image
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def random_noise_image(img, new_dims, new_scale, interp_order=1 ):
"""
Add noise to an image
Args:
im : (H x W x K) ndarray
new_dims : (height, width) tuple of new dimensions.
new_scale : (min, max) tuple of new scale.
interp_order : interpolation order, default is linear.
Returns:
a noisy version of the original clean image
"""
img = skimage.util.img_as_float( img )
img = resize_image( img, new_dims, interp_order )
img = skimage.util.random_noise(img, var=0.01)
img = rescale_image( img, new_scale )
return img
#################
# Colorization #
#################
示例11: to_light_low_sat
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def to_light_low_sat(img, new_dims, new_scale, interp_order=1 ):
"""
Turn an image into lightness
Args:
im : (H x W x K) ndarray
new_dims : (height, width) tuple of new dimensions.
new_scale : (min, max) tuple of new scale.
interp_order : interpolation order, default is linear.
Returns:
a lightness version of the original image
"""
img = skimage.img_as_float( img )
img = np.clip(img, 0.2, 0.8)
img = resize_image( img, new_dims, interp_order )
img = skimage.color.rgb2lab(img)[:,:,0]
img = rescale_image( img, new_scale, current_scale=[0,100])
return np.expand_dims(img,2)
示例12: to_light
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def to_light(img, new_dims, new_scale, interp_order=1 ):
"""
Turn an image into lightness
Args:
im : (H x W x K) ndarray
new_dims : (height, width) tuple of new dimensions.
new_scale : (min, max) tuple of new scale.
interp_order : interpolation order, default is linear.
Returns:
a lightness version of the original image
"""
img = skimage.img_as_float( img )
img = resize_image( img, new_dims, interp_order )
img = skimage.color.rgb2lab(img)[:,:,0]
img = rescale_image( img, new_scale, current_scale=[0,100])
return np.expand_dims(img,2)
示例13: resize_rescale_imagenet
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def resize_rescale_imagenet(img, new_dims, interp_order=1, current_scale=None, no_clip=False):
"""
Resize an image array with interpolation, and rescale to be
between
Parameters
----------
im : (H x W x K) ndarray
new_dims : (height, width) tuple of new dimensions.
new_scale : (min, max) tuple of new scale.
interp_order : interpolation order, default is linear.
Returns
-------
im : resized ndarray with shape (new_dims[0], new_dims[1], K)
"""
img = skimage.img_as_float( img )
img = resize_image( img, new_dims, interp_order )
#img = rescale_image( img, new_scale, current_scale=current_scale, no_clip=no_clip )
img = img[:,:,[2,1,0]] * 255.
root = '/home/ubuntu/task-taxonomy-331b/lib/data'
#img = img - np.load('{}/mean_image.npy'.format(root))
mean_bgr = [103.062623801, 115.902882574, 123.151630838]
img = img - mean_bgr
return img
示例14: resize_rescale_image_low_sat_2
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def resize_rescale_image_low_sat_2(img, new_dims, new_scale, interp_order=1, current_scale=None, no_clip=False):
"""
Resize an image array with interpolation, and rescale to be
between
Parameters
----------
im : (H x W x K) ndarray
new_dims : (height, width) tuple of new dimensions.
new_scale : (min, max) tuple of new scale.
interp_order : interpolation order, default is linear.
Returns
-------
im : resized ndarray with shape (new_dims[0], new_dims[1], K)
"""
img = skimage.img_as_float( img )
img = resize_image( img, new_dims, interp_order )
img = np.clip(img, 0.2, 0.8)
# low_sat_scale = [0.05, 0.95]
# img = rescale_image( img, low_sat_scale, current_scale=current_scale, no_clip=no_clip )
img = rescale_image( img, new_scale, current_scale=current_scale, no_clip=no_clip )
return img
示例15: resize_rescale_image_gaussian_blur
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import img_as_float [as 別名]
def resize_rescale_image_gaussian_blur(img, new_dims, new_scale, interp_order=1, blur_strength=4, current_scale=None, no_clip=False):
"""
Resize an image array with interpolation, and rescale to be
between
Parameters
----------
im : (H x W x K) ndarray
new_dims : (height, width) tuple of new dimensions.
new_scale : (min, max) tuple of new scale.
interp_order : interpolation order, default is linear.
Returns
-------
im : resized ndarray with shape (new_dims[0], new_dims[1], K)
"""
img = skimage.img_as_float( img )
img = resize_image( img, new_dims, interp_order )
img = rescale_image( img, new_scale, current_scale=current_scale, no_clip=True )
blurred = gaussian_filter(img, sigma=blur_strength)
if not no_clip:
min_val, max_val = new_scale
np.clip(blurred, min_val, max_val, out=blurred)
return blurred