當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。