当前位置: 首页>>代码示例>>Python>>正文


Python skimage.img_as_float方法代码示例

本文整理汇总了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)) 
开发者ID:ufal,项目名称:neuralmonkey,代码行数:25,代码来源:caffe_image_features.py

示例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 
开发者ID:ArtanisCV,项目名称:StructuredForests,代码行数:24,代码来源:StructuredForests.py

示例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 
开发者ID:ArtanisCV,项目名称:StructuredForests,代码行数:23,代码来源:StructuredForests.py

示例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 ######## 
开发者ID:cs-chan,项目名称:Deep-Plant,代码行数:27,代码来源:visualClef.py

示例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 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:26,代码来源:load_ops.py

示例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 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:22,代码来源:load_ops.py

示例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 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:21,代码来源:load_ops.py

示例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 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:21,代码来源:load_ops.py

示例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 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:21,代码来源:load_ops.py

示例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  #
################# 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:23,代码来源:load_ops.py

示例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) 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:20,代码来源:load_ops.py

示例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) 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:19,代码来源:load_ops.py

示例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 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:25,代码来源:load_ops.py

示例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 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:23,代码来源:load_ops.py

示例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 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:24,代码来源:load_ops.py


注:本文中的skimage.img_as_float方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。