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


Python scipy.misc方法代码示例

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


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

示例1: center_crop

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def center_crop(x, crop_h, crop_w=None, resize_w=64):

    if crop_w is None:
        crop_w = crop_h
    h, w = x.shape[:2]
    j = int(round((h - crop_h)/2.))
    i = int(round((w - crop_w)/2.))

    rate = np.random.uniform(0, 1, size=1)

    if rate < 0.5:
        x = np.fliplr(x)

    #first crop tp 178x178 and resize to 128x128
    return scipy.misc.imresize(x[20:218-20, 0: 178], [resize_w, resize_w])

    #Another cropped method

    # return scipy.misc.imresize(x[j:j+crop_h, i:i+crop_w],
    #                            [resize_w, resize_w]) 
开发者ID:zhangqianhui,项目名称:Residual_Image_Learning_GAN,代码行数:22,代码来源:utils.py

示例2: read_img

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def read_img(path, data_type):
    # read image by misc or from .npy
    # return: Numpy float32, HWC, RGB, [0,255]
    if data_type == 'img':
        img = imageio.imread(path, pilmode='RGB')
    elif data_type.find('npy') >= 0:
        img = np.load(path)
    else:
        raise NotImplementedError

    if img.ndim == 2:
        img = np.expand_dims(img, axis=2)
    return img


####################
# image processing
# process on numpy image
#################### 
开发者ID:Paper99,项目名称:SRFBN_CVPR19,代码行数:21,代码来源:common.py

示例3: imsave

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def imsave(image, path):
    label_colours = [
        (0,0,0),
        # 0=background
        (128,0,0),(0,128,0),(128,128,0),(0,0,128),(128,0,128),
        # 1=aeroplane, 2=bicycle, 3=bird, 4=boat, 5=bottle
        (0,128,128),(128,128,128),(64,0,0),(192,0,0),(64,128,0),
        # 6=bus, 7=car, 8=cat, 9=chair, 10=cow
        (192,128,0),(64,0,128),(192,0,128),(64,128,128),(192,128,128),
        # 11=diningtable, 12=dog, 13=horse, 14=motorbike, 15=person
        (0,64,0),(128,64,0),(0,192,0),(128,192,0),(0,64,128)]
        # 16=potted plant, 17=sheep, 18=sofa, 19=train, 20=tv/monitor
    images = np.ones(list(image.shape)+[3])
    for j_, j in enumerate(image):
        for k_, k in enumerate(j):
            if k < 21:
                images[j_, k_] = label_colours[int(k)]
    scipy.misc.imsave(path, images) 
开发者ID:HongyangGao,项目名称:PixelTCN,代码行数:20,代码来源:img_utils.py

示例4: single_img_colorize

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def single_img_colorize( predicted, input_batch, to_store_name ):
    maxs = np.amax(predicted, axis=-1)
    softmax = np.exp(predicted - np.expand_dims(maxs, axis=-1))
    sums = np.sum(softmax, axis=-1)
    softmax = softmax / np.expand_dims(sums, -1)
    kernel = np.load('lib/data/pts_in_hull.npy')
    gen_target_no_temp = np.dot(softmax, kernel)

    images_resized = np.zeros([0, 256, 256, 2], dtype=np.float32)
    for image in range(gen_target_no_temp.shape[0]):
        temp = scipy.ndimage.zoom(np.squeeze(gen_target_no_temp[image]), (4, 4, 1), mode='nearest')
        images_resized = np.append(images_resized, np.expand_dims(temp, axis=0), axis=0)
    inp_rescale = rescale_l_for_display(input_batch)
    output_lab_no_temp = np.concatenate((inp_rescale, images_resized), axis=3).astype(np.float64)
    for i in range(input_batch.shape[0]):
        output_lab_no_temp[i,:,:,:] = skimage.color.lab2rgb(output_lab_no_temp[i,:,:,:])
    predicted = output_lab_no_temp
    scipy.misc.toimage(np.squeeze(predicted), cmin=0.0, cmax=1.0).save(to_store_name) 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:20,代码来源:task_viz.py

示例5: single_img_colorize

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def single_img_colorize( predicted, input_batch, to_store_name ):
    maxs = np.amax(predicted, axis=-1)
    softmax = np.exp(predicted - np.expand_dims(maxs, axis=-1))
    sums = np.sum(softmax, axis=-1)
    softmax = softmax / np.expand_dims(sums, -1)
    kernel = np.load('/home/ubuntu/task-taxonomy-331b/lib/data/pts_in_hull.npy')
    gen_target_no_temp = np.dot(softmax, kernel)

    images_resized = np.zeros([0, 256, 256, 2], dtype=np.float32)
    for image in range(gen_target_no_temp.shape[0]):
        temp = scipy.ndimage.zoom(np.squeeze(gen_target_no_temp[image]), (4, 4, 1), mode='nearest')
        images_resized = np.append(images_resized, np.expand_dims(temp, axis=0), axis=0)
    inp_rescale = rescale_l_for_display(input_batch)
    output_lab_no_temp = np.concatenate((inp_rescale, images_resized), axis=3).astype(np.float64)
    for i in range(input_batch.shape[0]):
        output_lab_no_temp[i,:,:,:] = skimage.color.lab2rgb(output_lab_no_temp[i,:,:,:])
    predicted = output_lab_no_temp
    scipy.misc.toimage(np.squeeze(predicted), cmin=0.0, cmax=1.0).save(to_store_name) 
开发者ID:StanfordVL,项目名称:taskonomy,代码行数:20,代码来源:vid_task_viz.py

示例6: center_crop

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def center_crop(x, crop_h, crop_w=None, resize_w=64):
    if crop_w is None:
        crop_w = crop_h
    h, w = x.shape[:2]
    j = int(round((h - crop_h)/2.))
    i = int(round((w - crop_w)/2.))

    rate = np.random.uniform(0, 1, size=1)

    if rate < 0.5:
        x = np.fliplr(x)

    return scipy.misc.imresize(x[j:j + crop_h, i:i + crop_w],
                               [resize_w, resize_w])

        # return scipy.misc.imresize(x[20:218 - 20, 0: 178], [resize_w, resize_w])

    # return scipy.misc.imresize(x[45: 45 + 128, 25:25 + 128], [resize_w, resize_w]) 
开发者ID:zhangqianhui,项目名称:progressive_growing_of_gans_tensorflow,代码行数:20,代码来源:utils.py

示例7: _get_image

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def _get_image(self, image_path):
        """Retrieves an image at a given path and resizes it to the
        specified size.

        Args:
            image_path: Path to image.

        Returns:
            Loaded and transformed image.
        """

        # Read image at image_path.
        image = scipy.misc.imread(image_path).astype(np.float)

        # Return transformed image.
        return _prepare_image(image, self.center_crop_dim,
                              self.center_crop_dim,
                              resize_height=self.resize_size,
                              resize_width=self.resize_size,
                              is_crop=True) 
开发者ID:kabkabm,项目名称:defensegan,代码行数:22,代码来源:dataset.py

示例8: transform

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def transform(image, npx=64 , is_crop=False, resize_w=64):
    # npx : # of pixels width/height of image
    if is_crop:
        cropped_image = center_crop(image , npx , resize_w = resize_w)
    else:
        cropped_image = image
        cropped_image = scipy.misc.imresize(cropped_image ,
                            [resize_w , resize_w])
    return np.array(cropped_image)/127.5 - 1 
开发者ID:zhangqianhui,项目名称:Residual_Image_Learning_GAN,代码行数:11,代码来源:utils.py

示例9: imread

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def imread(path, is_grayscale=False):

    if (is_grayscale):
        return scipy.misc.imread(path, flatten=True).astype(np.float)
    else:
        return scipy.misc.imread(path).astype(np.float) 
开发者ID:zhangqianhui,项目名称:Residual_Image_Learning_GAN,代码行数:8,代码来源:utils.py

示例10: imsave

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def imsave(images, size, path):
    return scipy.misc.imsave(path, merge(images, size)) 
开发者ID:zhangqianhui,项目名称:Residual_Image_Learning_GAN,代码行数:4,代码来源:utils.py

示例11: load_image

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def load_image(image_path, img_size=None):
    assert exists(image_path), "image {} does not exist".format(image_path)
    img = scipy.misc.imread(image_path)
    if (len(img.shape) != 3) or (img.shape[2] != 3):
        img = np.dstack((img, img, img))

    if (img_size is not None):
        img = scipy.misc.imresize(img, img_size)

    img = img.astype("float32")
    return img 
开发者ID:ShafeenTejani,项目名称:fast-style-transfer,代码行数:13,代码来源:utils.py

示例12: save_image

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def save_image(img, path):
    scipy.misc.imsave(path, np.clip(img, 0, 255).astype(np.uint8)) 
开发者ID:ShafeenTejani,项目名称:fast-style-transfer,代码行数:4,代码来源:utils.py

示例13: _auto_color

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def _auto_color(self, url:str, ranks):
        phrases = ["Calculating colors..."] # in case I want more
        #try:
        await self.bot.say("**{}**".format(random.choice(phrases)))
        clusters = 10

        async with aiohttp.get(url) as r:
            image = await r.content.read()
        with open('data/leveler/temp_auto.png','wb') as f:
            f.write(image)

        im = Image.open('data/leveler/temp_auto.png').convert('RGBA')
        im = im.resize((290, 290)) # resized to reduce time
        ar = scipy.misc.fromimage(im)
        shape = ar.shape
        ar = ar.reshape(scipy.product(shape[:2]), shape[2])

        codes, dist = scipy.cluster.vq.kmeans(ar.astype(float), clusters)
        vecs, dist = scipy.cluster.vq.vq(ar, codes)         # assign codes
        counts, bins = scipy.histogram(vecs, len(codes))    # count occurrences

        # sort counts
        freq_index = []
        index = 0
        for count in counts:
            freq_index.append((index, count))
            index += 1
        sorted_list = sorted(freq_index, key=operator.itemgetter(1), reverse=True)

        colors = []
        for rank in ranks:
            color_index = min(rank, len(codes))
            peak = codes[sorted_list[color_index][0]] # gets the original index
            peak = peak.astype(int)

            colors.append(''.join(format(c, '02x') for c in peak))
        return colors # returns array
        #except:
            #await self.bot.say("```Error or no scipy. Install scipy doing 'pip3 install numpy' and 'pip3 install scipy' or read here: https://github.com/AznStevy/Maybe-Useful-Cogs/blob/master/README.md```")

    # converts hex to rgb 
开发者ID:AznStevy,项目名称:Maybe-Useful-Cogs,代码行数:43,代码来源:leveler.py

示例14: process_file

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def process_file(params):
    index, data, base_filename, db_name, C, aug_data = params
    label = index % NUM_CLASSES
    if C==1:
        orig_im = data[0,:,:]
        im = ndimage.interpolation.zoom(orig_im, DOWNSCALE_FACTOR)
    elif C==2:
        im = np.zeros((int(MAT_SHAPE[2]*DOWNSCALE_FACTOR),int(MAT_SHAPE[3]*DOWNSCALE_FACTOR),3))
        orig_im = np.zeros((MAT_SHAPE[2],MAT_SHAPE[3],3))
        im[:,:,0] =  ndimage.interpolation.zoom(data[0,:,:], DOWNSCALE_FACTOR)
        im[:,:,1] =  ndimage.interpolation.zoom(data[1,:,:], DOWNSCALE_FACTOR)
        orig_im[:,:,0] =  data[0,:,:]
        orig_im[:,:,1] =  data[1,:,:]
    else:
        print "Error in reading data to db- number of channels must be 1 or 2"
    im_name = '%s_%d%s' % (base_filename, index,IM_FORMAT)
    scipy.misc.toimage(im, cmin=0.0, cmax=255.0).save(os.path.join(db_name,im_name))
    im_names = [im_name]
    if aug_data:
        degrees = [-20, -10, 10, 20]
        crop_dims = [2, 4, 6, 8]
        for i, degree in enumerate(degrees):
            im_name = '%s_%d_%d%s' % (base_filename,index,degree,IM_FORMAT)
            im_names.append(im_name)
            rot_im = rotate_im(orig_im, degree)
            scipy.misc.toimage(rot_im, cmin=0.0, cmax=255.0).save(os.path.join(db_name,im_name))
        for i, crop_dim in enumerate(crop_dims):
            im_name = '%s_%d_%d%s' % (base_filename,index,crop_dim,IM_FORMAT)
            im_names.append(im_name)
            cr_im = crop_and_rescale(orig_im, crop_dim)        
            scipy.misc.toimage(cr_im, cmin=0.0, cmax=255.0).save(os.path.join(db_name,im_name))
    return label, im_names 
开发者ID:HUJI-Deep,项目名称:Generative-ConvACs,代码行数:34,代码来源:generate_norb_small.py

示例15: read_depth

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import misc [as 别名]
def read_depth(self, filename):
    depth_mat = sio.loadmat(filename)
    depthtmp=depth_mat["depth"]
    ds = depthtmp.shape
    if self.is_crop:
      depth = scipy.misc.imresize(depthtmp,(self.output_height,self.output_width),mode='F')
    depth = np.array(depth).astype(np.float32)
    depth = np.multiply(self.max_depth,np.divide(depth,depth.max()))

    return depth 
开发者ID:kskin,项目名称:WaterGAN,代码行数:12,代码来源:modelmhl.py


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