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


Python util.img_as_float方法代码示例

本文整理汇总了Python中skimage.util.img_as_float方法的典型用法代码示例。如果您正苦于以下问题:Python util.img_as_float方法的具体用法?Python util.img_as_float怎么用?Python util.img_as_float使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在skimage.util的用法示例。


在下文中一共展示了util.img_as_float方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pyramid_expand_3d

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import img_as_float [as 别名]
def pyramid_expand_3d(volume, upscale=2, sigma=None, order=1, mode='reflect', cval=0):
    _check_factor(upscale)
    #_check_float32(volume)
    #volume=img_as_float(volume)
    volume=volume.astype('float64') # /(12641.6)  #
    x = volume.shape[0]
    y = volume.shape[1]
    z = volume.shape[2]
    out_x = math.ceil(upscale * x)
    out_y = math.ceil(upscale * y)
    out_z = math.ceil(upscale * z)

    if sigma is None:
        # automatically determine sigma which covers > 99% of distribution
        sigma = 2 * upscale / 6.0
    
    start_time = time.time()
    resized = resize(volume, (out_x, out_y, out_z), order=order, mode=mode, cval=cval)
    start_time = time.time()
    out = _smooth_3d(resized, sigma, mode, cval)
    # I want it to be float32
    start_time = time.time()    
    out=out.astype('float32')
    return out 
开发者ID:konopczynski,项目名称:Vessel3DDL,代码行数:26,代码来源:pyramids_3d.py

示例2: get_resized_image

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import img_as_float [as 别名]
def get_resized_image(file, ratio):
    img = util.img_as_float(io.imread(file))
    if len(img.shape) >= 3 and img.shape[2] == 4:
        img = color.rgba2rgb(img)
    if len(img.shape) == 2:
        img = color.gray2rgb(img)

    eimg = filters.sobel(color.rgb2gray(img))
    width = img.shape[1]
    height = img.shape[0]

    mode, rm_paths = get_lines_to_remove((width, height), ratio)
    if mode:
        logger.debug("Carving %s %s paths ", rm_paths, mode)
        outh = transform.seam_carve(img, eimg, mode, rm_paths)
        return outh
    else:
        return img 
开发者ID:ftramer,项目名称:ad-versarial,代码行数:20,代码来源:generator.py

示例3: __call__

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import img_as_float [as 别名]
def __call__(self, images):
        image_sizes = np.array([list(img.shape[:2]) for img in images])
        scale_crop_mtx = _compute_scale_and_crop_matrices(image_sizes, self.crop_size, self.padding, self.random_crop)

        aug_xf = self.aug.aug_xforms(len(images), self.crop_size)
        scale_crop_aug_xf = augmentation.cat_nx2x3(aug_xf, scale_crop_mtx)
        colour_matrix, colour_offset = self.aug.aug_colour_xforms(len(images))
        cutout_flags, cutout_lower, cutout_upper = self.aug.aug_cutouts(len(images), self.crop_size)

        result = []
        for i, img in enumerate(images):
            img = cv2.warpAffine(img, scale_crop_aug_xf[i, :, :], self.crop_size[::-1], borderValue=self.border_value,
                                 borderMode=cv2.BORDER_REFLECT_101)
            img = img_as_float(img).astype(np.float32)
            img = (img - self.mean[None, None, :]) / self.std[None, None, :]
            img = np.tensordot(img, colour_matrix[i, :, :], [[2], [1]]) + colour_offset[i, None, None, :]
            if cutout_flags is not None and cutout_flags[i]:
                img[cutout_lower[i, 0]:cutout_upper[i, 0], cutout_lower[i, 1]:cutout_upper[i, 1], :] = 0.0
            result.append(img)

        return (result,) 
开发者ID:Britefury,项目名称:self-ensemble-visual-domain-adapt-photo,代码行数:23,代码来源:image_transforms.py

示例4: em_G_D_002

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import img_as_float [as 别名]
def em_G_D_002(x, scale=4, upsample=False):
    x = img_as_float(x)
    mu, sigma = 0, 3
    noise = np.random.normal(mu, sigma*0.05, x.shape)
    x = np.clip(x + noise, 0, 1)
    x_down = npzoom(x, 1/scale, order=1)
    x_up = npzoom(x_down, scale, order=1)
    return x_down, x_up 
开发者ID:BPHO-Salk,项目名称:PSSR,代码行数:10,代码来源:crappifiers.py

示例5: captcha_draw

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import img_as_float [as 别名]
def captcha_draw(label, fonts, dir_path, pic_id):
    # width, height = 512, 48
    # size_cha = random.randint(24, 48) # 字符大小
    # derx = random.randint(0, 16)
    # im = Image.new(mode='L', size=(width, height), color='white') # color 背景颜色,size 图片大小
    # drawer = ImageDraw.Draw(im)
    # font = ImageFont.truetype(random.choice(fonts), size_cha)
    # drawer.text(xy=(derx, 0), text=label, font=font, fill='black') #text 内容,font 字体(包括大小)
    # # im.show()
    # write2file(dir_path, label, im)

    width, height = 32, 32
    size_cha = random.randint(16, 28) # 字符大小
    derx = random.randint(0, max(width-size_cha-10, 0))
    dery = random.randint(0, max(height-size_cha-10, 0))
    im = Image.new(mode='L', size=(width, height), color='white') # color 背景颜色,size 图片大小
    drawer = ImageDraw.Draw(im)
    font = ImageFont.truetype(random.choice(fonts), size_cha)

    drawer.text(xy=(derx, dery), text=label, font=font, fill='black') #text 内容,font 字体(包括大小)
    # if label != ' ' and (img_as_float(im) == np.ones((48, 48))).all():
    #     # in case the label is not in this font, then the image will be all white
    #     return 0
    im = im.convert('RGBA')
    max_angle = 45 # to be tuned
    angle = random.randint(-max_angle, max_angle)
    im = im.rotate(angle, Image.BILINEAR, expand=0)
    fff = Image.new('RGBA', im.size, (255,)*4)
    im = Image.composite(im, fff, im)
    # if random.random() < 0.5:
    #     im = Image.fromarray(grey_erosion(im, size=(2, 2))) # erosion
    # if random.random() < 0.5:
    #     im = Image.fromarray((random_noise(img_as_float(im), mode='s&p')*255).astype(np.uint8))
    # im = im.filter(ImageFilter.GaussianBlur(radius=random.random()))
    # im.show()
    write2file(dir_path, label, im, pic_id)
    return 1 
开发者ID:xingjian-f,项目名称:DeepLearning-OCR,代码行数:39,代码来源:generator.py

示例6: get_saliency_ft

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import img_as_float [as 别名]
def get_saliency_ft(img_path):

	# Saliency map calculation based on:

	img = skimage.io.imread(img_path)

	img_rgb = img_as_float(img)

	img_lab = skimage.color.rgb2lab(img_rgb) 

	mean_val = np.mean(img_rgb,axis=(0,1))

	kernel_h = (1.0/16.0) * np.array([[1,4,6,4,1]])
	kernel_w = kernel_h.transpose()

	blurred_l = scipy.signal.convolve2d(img_lab[:,:,0],kernel_h,mode='same')
	blurred_a = scipy.signal.convolve2d(img_lab[:,:,1],kernel_h,mode='same')
	blurred_b = scipy.signal.convolve2d(img_lab[:,:,2],kernel_h,mode='same')

	blurred_l = scipy.signal.convolve2d(blurred_l,kernel_w,mode='same')
	blurred_a = scipy.signal.convolve2d(blurred_a,kernel_w,mode='same')
	blurred_b = scipy.signal.convolve2d(blurred_b,kernel_w,mode='same')

	im_blurred = np.dstack([blurred_l,blurred_a,blurred_b])

	sal = np.linalg.norm(mean_val - im_blurred,axis = 2)
	sal_max = np.max(sal)
	sal_min = np.min(sal)
	sal = 255 * ((sal - sal_min) / (sal_max - sal_min))
	return sal 
开发者ID:yhenon,项目名称:pyimgsaliency,代码行数:32,代码来源:saliency.py

示例7: generate

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import img_as_float [as 别名]
def generate(im, bb, ads, num=1, mode='bb'):
    logger.info("Generate from %s", im)
    abs_path = os.path.abspath(im)
    rem, _ = os.path.split(abs_path)
    rem, p2 = os.path.split(rem)
    rem, p1 = os.path.split(rem)
    out = "{}_{}".format(p1, p2)
    images = [util.img_as_float(io.imread(im)) for i in range(0, num)]
    # remove alpha channel
    if len(images[0].shape) >= 3 and images[0].shape[2] == 4:
        logger.debug("Removed alpha from image")
        images = [color.rgba2rgb(img) for img in images]
    with open(bb) as bbf:
        boxes = json.load(bbf)
    if mode == "mixed":
        generate_mixed(images, boxes, ads, out)
        return
    if mode == "inter":
        generate_interstitial(images, ads, out)
        return
    if mode in ["bb", "bb+logo"]:
        generate_bb(images, boxes, ads, out, mode)
        return
    if mode == "copy":
        generate_copy(images, boxes, out)
        return
    if mode == "bg":
        generate_background(images, ads, boxes, out)
        return 
开发者ID:ftramer,项目名称:ad-versarial,代码行数:31,代码来源:generator.py

示例8: pyramid_expand

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import img_as_float [as 别名]
def pyramid_expand(image, upscale=2, sigma=None, order=1, mode='reflect', cval=0):
    """Upsample and then smooth image.
    Parameters
    ----------
    image : array
        Input image.
    upscale : float, optional
        Upscale factor.
    sigma : float, optional
        Sigma for Gaussian filter. Default is `2 * upscale / 6.0` which
        corresponds to a filter mask twice the size of the scale factor that
        covers more than 99% of the Gaussian distribution.
    order : int, optional
        Order of splines used in interpolation of upsampling. See
        `skimage.transform.warp` for detail.
    mode : {'reflect', 'constant', 'edge', 'symmetric', 'wrap'}, optional
        The mode parameter determines how the array borders are handled, where
        cval is the value when mode is equal to 'constant'.
    cval : float, optional
        Value to fill past edges of input if mode is 'constant'.
    Returns
    -------
    out : array
        Upsampled and smoothed float image.
    References
    ----------
    .. [1] http://web.mit.edu/persci/people/adelson/pub_pdfs/pyramid83.pdf
    """

    _check_factor(upscale)

    image = img_as_float(image)

    rows = image.shape[0]
    cols = image.shape[1]
    out_rows = math.ceil(upscale * rows)
    out_cols = math.ceil(upscale * cols)

    if sigma is None:
        # automatically determine sigma which covers > 99% of distribution
        sigma = 2 * upscale / 6.0

    resized = resize(image, (out_rows, out_cols), order=order, mode=mode, cval=cval)
    out = _smooth(resized, sigma, mode, cval)

    return out 
开发者ID:konopczynski,项目名称:Vessel3DDL,代码行数:48,代码来源:pyramids_3d.py

示例9: load_images

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import img_as_float [as 别名]
def load_images(path, suffixes=('jpg', 'gif', 'png', 'bmp'), points_too=False):
    """load an image set from a directory.

    Load all images in a directory as float grayscale. Optionally
    if MATLAB 'points' files are present (as in the published RASL
    data sets[1]), read and return those. These give coordinates of
    corresponding points on the batch of images, eg, the outside eye
    corners in facial images.

    Parameters
    ----------
    path : string
        file path to image directory
    suffixes : list of string
        allowable image suffixes
    points_too : bool
        if true, read and return any "*.mat" files that are present

    Returns
    -------
    images : list[100] of ndarray(h,v)
        dummy images as ndarrays
    bounds : list[100] of ndarray(2, 2)
        coordinates of eye corner points as columns

    References
    ----------
    .. [1] http://perception.csl.illinois.edu/matrix-rank/rasl.html#Code

    """
    images = [img_as_float(skio.imread(os.path.join(path, fname), as_grey=True))
              for fname in os.listdir(path)
              if fname.split('.')[-1] in suffixes]
    shapes = np.array([image.shape for image in images])
    if np.all(shapes == shapes[0, :]):
        print("loaded {} {}x{} images".format(
            len(images), images[0].shape[0], images[0].shape[1]))
    else:
        print("loaded {} images with sizes ranging {},{} -- {},{}".format(
            len(images), np.min(shapes[:, 0]), np.min(shapes[:, 1]),
            np.max(shapes[:, 0]), np.max(shapes[:, 1])))

    if points_too:
        points = [scio.loadmat(os.path.join(path, fname))['points']
                  for fname in os.listdir(path) if fname.endswith('.mat')]
        return images, points
    else:
        return images 
开发者ID:welch,项目名称:rasl,代码行数:50,代码来源:application.py


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