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


Python misc.imresize方法代码示例

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


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

示例1: test

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def test(self):

        list_ = os.listdir("./maps/val/")
        nums_file = list_.__len__()
        saver = tf.train.Saver(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, "generator"))
        saver.restore(self.sess, "./save_para/model.ckpt")
        rand_select = np.random.randint(0, nums_file)
        INPUTS_CONDITION = np.zeros([1, self.img_h, self.img_w, 3])
        INPUTS = np.zeros([1, self.img_h, self.img_w, 3])
        img = np.array(Image.open(self.path + list_[rand_select]))
        img_h, img_w = img.shape[0], img.shape[1]
        INPUTS_CONDITION[0] = misc.imresize(img[:, img_w//2:], [self.img_h, self.img_w]) / 127.5 - 1.0
        INPUTS[0] = misc.imresize(img[:, :img_w//2], [self.img_h, self.img_w]) / 127.5 - 1.0
        [fake_img] = self.sess.run([self.inputs_fake], feed_dict={self.inputs_condition: INPUTS_CONDITION})
        out_img = np.concatenate((INPUTS_CONDITION[0], fake_img[0], INPUTS[0]), axis=1)
        Image.fromarray(np.uint8((out_img + 1.0)*127.5)).save("./results/1.jpg")
        plt.imshow(np.uint8((out_img + 1.0)*127.5))
        plt.grid("off")
        plt.axis("off")
        plt.show() 
开发者ID:MingtaoGuo,项目名称:Chinese-Character-and-Calligraphic-Image-Processing,代码行数:22,代码来源:test.py

示例2: train

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def train(self):

        list = os.listdir(self.path)
        nums_file = list.__len__()
        saver = tf.train.Saver()
        for i in range(10000):
            rand_select = np.random.randint(0, nums_file, [self.batch_size])
            INPUTS = np.zeros([self.batch_size, self.img_h, self.img_w, 3])
            INPUTS_CONDITION = np.zeros([self.batch_size, self.img_h, self.img_w, 3])
            for j in range(self.batch_size):
                img = np.array(Image.open(self.path + list[rand_select[j]]))
                img_h, img_w = img.shape[0], img.shape[1]
                INPUT_CON = misc.imresize(img[:, :img_w//2], [self.img_h, self.img_w]) / 127.5 - 1.0
                INPUTS_CONDITION[j] = np.dstack((INPUT_CON, INPUT_CON, INPUT_CON))
                INPUT = misc.imresize(img[:, img_w//2:], [self.img_h, self.img_w]) / 127.5 - 1.0
                INPUTS[j] = np.dstack((INPUT, INPUT, INPUT))
            self.sess.run(self.opt_dis, feed_dict={self.inputs: INPUTS, self.inputs_condition: INPUTS_CONDITION})
            self.sess.run(self.opt_gen, feed_dict={self.inputs: INPUTS, self.inputs_condition: INPUTS_CONDITION})
            if i % 10 == 0:
                [G_LOSS, D_LOSS] = self.sess.run([self.g_loss, self.d_loss], feed_dict={self.inputs: INPUTS, self.inputs_condition: INPUTS_CONDITION})
                print("Iteration: %d, d_loss: %f, g_loss: %f"%(i, D_LOSS, G_LOSS))
            if i % 100 == 0:
                saver.save(self.sess, "./save_para//model.ckpt") 
开发者ID:MingtaoGuo,项目名称:Chinese-Character-and-Calligraphic-Image-Processing,代码行数:25,代码来源:pix2pix.py

示例3: align_char

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def align_char(char_img, target_h, target_w):
    canvas = np.ones([target_h, target_w], dtype=np.int32) * 255
    img_h, img_w = char_img.shape[0], char_img.shape[1]
    if img_h > img_w:
        new_h = target_h
        new_w = np.int32(img_w * target_h / img_h)
        char_img = misc.imresize(char_img, [new_h, new_w])
        mid_w = target_w // 2
        start = mid_w - new_w // 2
        end = start + new_w
        canvas[:, start:end] = char_img
    if img_h < img_w:
        new_w = target_w
        new_h = np.int32(img_h * target_w / img_w)
        char_img = misc.imresize(char_img, [new_h, new_w])
        mid_h = target_h // 2
        start = mid_h - new_h // 2
        end = start + new_h
        canvas[start:end, :] = char_img
    if img_h == img_w:
        canvas = misc.imresize(char_img, [target_h, target_w])
    return canvas 
开发者ID:MingtaoGuo,项目名称:Chinese-Character-and-Calligraphic-Image-Processing,代码行数:24,代码来源:segmentFinal.py

示例4: apply_val_transform_image

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def apply_val_transform_image(image,inputRes=None):
    meanval = (104.00699, 116.66877, 122.67892)

    if inputRes is not None:
        image = sm.imresize(image, inputRes)

    image = np.array(image, dtype=np.float32)
    image = np.subtract(image, np.array(meanval, dtype=np.float32))



    if image.ndim == 2:
        image = image[:, :, np.newaxis]

    # swap color axis because
    # numpy image: H x W x C
    # torch image: C X H X W

    image = image.transpose((2, 0, 1))
    image = torch.from_numpy(image)

    return image 
开发者ID:omkar13,项目名称:MaskTrack,代码行数:24,代码来源:utility_functions.py

示例5: make_img_gt_pair

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def make_img_gt_pair(self, idx):
        """
        Make the image-ground-truth pair
        """
        img = cv2.imread(os.path.join(self.db_root_dir, self.img_list[idx]))
        if self.labels[idx] is not None:
            label = cv2.imread(os.path.join(self.db_root_dir, self.labels[idx]), 0)
        else:
            gt = np.zeros(img.shape[:-1], dtype=np.uint8)

        if self.inputRes is not None:
            img = imresize(img, self.inputRes)
            if self.labels[idx] is not None:
                label = imresize(label, self.inputRes, interp='nearest')

        img = np.array(img, dtype=np.float32)
        img = np.subtract(img, np.array(self.meanval, dtype=np.float32))

        if self.labels[idx] is not None:
                gt = np.array(label, dtype=np.float32)
                gt = gt/np.max([gt.max(), 1e-8])

        return img, gt 
开发者ID:omkar13,项目名称:MaskTrack,代码行数:25,代码来源:davis17_online_data.py

示例6: transform

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def transform(self, img, lbl):
        img = m.imresize(img, (self.img_size[0], self.img_size[1]))  # uint8 with RGB mode
        img = img[:, :, ::-1]  # RGB -> BGR
        img = img.astype(np.float64)
        img -= self.mean
        if self.img_norm:
            # Resize scales images from 0 to 255, thus we need
            # to divide by 255.0
            img = img.astype(float) / 255.0
        # NHWC -> NCHW
        img = img.transpose(2, 0, 1)

        classes = np.unique(lbl)
        lbl = lbl.astype(float)
        lbl = m.imresize(lbl, (self.img_size[0], self.img_size[1]), "nearest", mode="F")
        lbl = lbl.astype(int)
        assert np.all(classes == np.unique(lbl))

        img = torch.from_numpy(img).float()
        lbl = torch.from_numpy(lbl).long()
        return img, lbl 
开发者ID:zhechen,项目名称:PLARD,代码行数:23,代码来源:nyuv2_loader.py

示例7: transform

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def transform(self, img, lbl):
        img = m.imresize(img, (self.img_size[0], self.img_size[1])) # uint8 with RGB mode
        img = img[:, :, ::-1] # RGB -> BGR
        img = img.astype(np.float64)
        img -= self.mean
        if self.img_norm:
            # Resize scales images from 0 to 255, thus we need
            # to divide by 255.0
            img = img.astype(float) / 255.0
        # NHWC -> NCHW
        img = img.transpose(2, 0, 1)

        lbl[lbl==255] = 0
        lbl = lbl.astype(float)
        lbl = m.imresize(lbl, (self.img_size[0], self.img_size[1]), 'nearest',
                         mode='F')
        lbl = lbl.astype(int)
        img = torch.from_numpy(img).float()
        lbl = torch.from_numpy(lbl).long()
        return img, lbl 
开发者ID:zhechen,项目名称:PLARD,代码行数:22,代码来源:pascal_voc_loader.py

示例8: transform

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def transform(self, img, lbl):
        img = m.imresize(img, (self.img_size[0], self.img_size[1])) # uint8 with RGB mode
        img = img[:, :, ::-1] # RGB -> BGR
        img = img.astype(np.float64)
        img -= self.mean
        if self.img_norm:
            # Resize scales images from 0 to 255, thus we need
            # to divide by 255.0
            img = img.astype(float) / 255.0
        # NHWC -> NCHW
        img = img.transpose(2, 0, 1)

        classes = np.unique(lbl)
        lbl = lbl.astype(float)
        lbl = m.imresize(lbl, (self.img_size[0], self.img_size[1]), 'nearest', mode='F')
        lbl = lbl.astype(int)
        assert(np.all(classes == np.unique(lbl)))

        img = torch.from_numpy(img).float()
        lbl = torch.from_numpy(lbl).long()
        return img, lbl 
开发者ID:zhechen,项目名称:PLARD,代码行数:23,代码来源:sunrgbd_loader.py

示例9: transform

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def transform(self, img, lbl):
        img = m.imresize(img, (self.img_size[0], self.img_size[1])) # uint8 with RGB mode
        img = img[:, :, ::-1] # RGB -> BGR
        img = img.astype(np.float64)
        img -= self.mean
        if self.img_norm:
            # Resize scales images from 0 to 255, thus we need
            # to divide by 255.0
            img = img.astype(float) / 255.0
        # NHWC -> NCHW
        img = img.transpose(2, 0, 1)

        lbl = self.encode_segmap(lbl)
        classes = np.unique(lbl)
        lbl = lbl.astype(float)
        lbl = m.imresize(lbl, (self.img_size[0], self.img_size[1]), 'nearest', mode='F')
        lbl = lbl.astype(int)
        assert(np.all(classes == np.unique(lbl)))

        img = torch.from_numpy(img).float()
        lbl = torch.from_numpy(lbl).long()
        return img, lbl 
开发者ID:zhechen,项目名称:PLARD,代码行数:24,代码来源:ade20k_loader.py

示例10: resize

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def resize(video, size, interpolation):
  """
  :param video: ... x h x w x num_channels
  :param size: (h, w)
  :param interpolation: 'bilinear', 'nearest'
  :return:
  """
  shape = video.shape[:-3]
  num_channels = video.shape[-1]
  video = video.reshape((-1, *video.shape[-3:]))
  resized_video = np.zeros((video.shape[0], *size, video.shape[-1]))

  for i in range(video.shape[0]):
    if num_channels == 3:
      resized_video[i] = imresize(video[i], size, interpolation)
    elif num_channels == 2:
      resized_video[i, ..., 0] = imresize(video[i, ..., 0], size, interpolation)
      resized_video[i, ..., 1] = imresize(video[i, ..., 1], size, interpolation)
    elif num_channels == 1:
      resized_video[i, ..., 0] = imresize(video[i, ..., 0], size, interpolation)
    else:
      raise NotImplementedError

  return resized_video.reshape((*shape, *size, video.shape[-1])) 
开发者ID:google,项目名称:graph_distillation,代码行数:26,代码来源:imgproc.py

示例11: crop_det

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def crop_det(det_M, img): 
    global track_struct
    crop_det_folder = track_struct['file_path']['crop_det_folder']
    crop_size = track_struct['track_params']['crop_size']
    if not os.path.isdir(crop_det_folder): 
        os.makedirs(crop_det_folder) 
    
    save_patch_list = []
    for n in range(len(det_M)):
        xmin = int(max(0,det_M[n,1])) 
        xmax = int(min(img.shape[1]-1,det_M[n,1]+det_M[n,3])) 
        ymin = int(max(0,det_M[n,2])) 
        ymax = int(min(img.shape[0]-1,det_M[n,2]+det_M[n,4])) 
        img_patch = img[ymin:ymax,xmin:xmax,:] 
        img_patch = misc.imresize(img_patch, size=[crop_size,crop_size]) 
        patch_name = track_lib.file_name(n,4)+'.png'
        save_path = crop_det_folder+'/'+patch_name 
        misc.imsave(save_path, img_patch)
        save_patch_list.append(save_path)
  
    return save_patch_list 
开发者ID:GaoangW,项目名称:TNT,代码行数:23,代码来源:tracklet_utils_3d_online.py

示例12: _compute_statistics_of_path

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def _compute_statistics_of_path(path, model, batch_size, dims, cuda):
    if path.endswith('.npz'):
        f = np.load(path)
        m, s = f['mu'][:], f['sigma'][:]
        f.close()
    else:
        path = pathlib.Path(path)
        files = list(path.glob('*.jpg')) + list(path.glob('*.png'))
        #imgs = np.array([imresize(imread(str(fn)),(64,64)).astype(np.float32) for fn in files])
        imgs = np.array([imread(str(fn)).astype(np.float32) for fn in files])
        # Bring images to shape (B, 3, H, W)
        imgs = imgs.transpose((0, 3, 1, 2))
        # Rescale images to be between 0 and 1
        imgs /= 255
        m, s = calculate_activation_statistics(imgs, model, batch_size,
                                               dims, cuda)

    return m, s 
开发者ID:jingyang2017,项目名称:Face-and-Image-super-resolution,代码行数:20,代码来源:fid_score.py

示例13: resizeImg

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def resizeImg(imgPath,img_size):
    img = imread(imgPath)
    h, w, _ = img.shape
    scale = 1
    if w >= h:
        new_w = img_size
        if w  >= new_w:
            scale = float(new_w) / w
        new_h = int(h * scale)
    else:
        new_h = img_size
        if h >= new_h:
            scale = float(new_h) / h
        new_w = int(w * scale)
    new_img = imresize(img, (new_h, new_w), interp='bilinear')
    imsave(imgPath,new_img)

#Download img
#Later we can do multi thread apply workers to do faster work 
开发者ID:e-lab,项目名称:crawl-dataset,代码行数:21,代码来源:getImages.py

示例14: resizeImg

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def resizeImg(imgPath,img_size):
    img = imread(imgPath)
    h, w, _ = img.shape
    scale = 1
    if w >= h:
        new_w = img_size
        if w  >= new_w:
            scale = float(new_w) / w
        new_h = int(h * scale)
    else:
        new_h = img_size
        if h >= new_h:
            scale = float(new_h) / h
        new_w = int(w * scale)
    new_img = imresize(img, (new_h, new_w), interp='bilinear')
    imsave(imgPath,new_img)
    print('Img Resized as {}'.format(img_size)) 
开发者ID:e-lab,项目名称:crawl-dataset,代码行数:19,代码来源:getImgs.py

示例15: resizeImg

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imresize [as 别名]
def resizeImg(imgPath,img_size):
	try:
		img = imread(imgPath)
		h, w, _ = img.shape
		scale = 1
		if w >= h:
			new_w = img_size
			if w  >= new_w:
				scale = float(new_w) / w
			new_h = int(h * scale)
		else:
			new_h = img_size
			if h >= new_h:
				scale = float(new_h) / h
			new_w = int(w * scale)
		new_img = imresize(img, (new_h, new_w), interp='bilinear')
		imsave(imgPath,new_img)
		print('Img Resized as {}'.format(img_size))
	except Exception as e:
		print(e) 
开发者ID:e-lab,项目名称:crawl-dataset,代码行数:22,代码来源:getImgs.py


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