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


Python misc.imread方法代码示例

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


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

示例1: create_tf_example

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [as 别名]
def create_tf_example(line, attribute_name, img_dir):
    info = line.split()
    img_name = os.path.join(img_dir, info[0])
    img = misc.imread(img_name)
    # from IPython import embed; embed();exit()
    feature={
        'image/id_name': bytes_feature(info[0]),
        'image/height' : int64_feature(img.shape[0]),
        'image/width'  : int64_feature(img.shape[1]),
        'image/encoded': bytes_feature(tf.compat.as_bytes(img.tostring())),
    }
    for j, val in enumerate(info[1:]):
        feature[attribute_name[j]] = int64_feature(int(val))

    example = tf.train.Example(features=tf.train.Features(feature=feature))
    return example 
开发者ID:Prinsphield,项目名称:DNA-GAN,代码行数:18,代码来源:create_tfrecords.py

示例2: __getitem__

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [as 别名]
def __getitem__(self, index):
        """__getitem__

        :param index:
        """
        img_path = self.files[self.split][index].rstrip()
        lbl_path = os.path.join(self.annotations_base, os.path.basename(img_path)[:-4] + '.png')

        img = m.imread(img_path)
        img = np.array(img, dtype=np.uint8)

        lbl = m.imread(lbl_path)
        lbl = np.array(lbl, dtype=np.uint8)

        if self.augmentations is not None:
            img, lbl = self.augmentations(img, lbl)

        if self.is_transform:
            img, lbl = self.transform(img, lbl)

        return img, lbl 
开发者ID:zhechen,项目名称:PLARD,代码行数:23,代码来源:mit_sceneparsing_benchmark_loader.py

示例3: __getitem__

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [as 别名]
def __getitem__(self, index):
        img_path = self.files[self.split][index].rstrip()
        img_number = img_path.split("_")[-1][:4]
        lbl_path = os.path.join(
            self.root, self.split + "_annot", "new_nyu_class13_" + img_number + ".png"
        )

        img = m.imread(img_path)
        img = np.array(img, dtype=np.uint8)

        lbl = m.imread(lbl_path)
        lbl = np.array(lbl, dtype=np.uint8)

        if not (len(img.shape) == 3 and len(lbl.shape) == 2):
            return self.__getitem__(np.random.randint(0, self.__len__()))

        if self.augmentations is not None:
            img, lbl = self.augmentations(img, lbl)

        if self.is_transform:
            img, lbl = self.transform(img, lbl)

        return img, lbl 
开发者ID:zhechen,项目名称:PLARD,代码行数:25,代码来源:nyuv2_loader.py

示例4: __getitem__

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [as 别名]
def __getitem__(self, index):
        img_path = self.files[self.split][index].rstrip()
        lbl_path = self.anno_files[self.split][index].rstrip()
        # img_number = img_path.split('/')[-1]
        # lbl_path = os.path.join(self.root, 'annotations', img_number).replace('jpg', 'png')

        img = m.imread(img_path)    
        img = np.array(img, dtype=np.uint8)

        lbl = m.imread(lbl_path)
        lbl = np.array(lbl, dtype=np.uint8)

        if not (len(img.shape) == 3 and len(lbl.shape) == 2):
            return self.__getitem__(np.random.randint(0, self.__len__()))

        if self.augmentations is not None:
            img, lbl = self.augmentations(img, lbl)

        if self.is_transform:
            img, lbl = self.transform(img, lbl)

        return img, lbl 
开发者ID:zhechen,项目名称:PLARD,代码行数:24,代码来源:sunrgbd_loader.py

示例5: __getitem__

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [as 别名]
def __getitem__(self, index):
        """__getitem__

        :param index:
        """
        img_path = self.files[self.split][index].rstrip()
        lbl_path = os.path.join(self.annotations_base,
                                img_path.split(os.sep)[-2], 
                                os.path.basename(img_path)[:-15] + 'gtFine_labelIds.png')

        img = m.imread(img_path)
        img = np.array(img, dtype=np.uint8)

        lbl = m.imread(lbl_path)
        lbl = self.encode_segmap(np.array(lbl, dtype=np.uint8))
        
        if self.augmentations is not None:
            img, lbl = self.augmentations(img, lbl)
        
        if self.is_transform:
            img, lbl = self.transform(img, lbl)

        return img, lbl 
开发者ID:zhechen,项目名称:PLARD,代码行数:25,代码来源:cityscapes_loader.py

示例6: __getitem__

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [as 别名]
def __getitem__(self, index):
        img_path = self.files[self.split][index].rstrip()
        lbl_path = img_path[:-4] + '_seg.png'

        img = m.imread(img_path)
        img = np.array(img, dtype=np.uint8)

        lbl = m.imread(lbl_path)
        lbl = np.array(lbl, dtype=np.int32)

        if self.augmentations is not None:
            img, lbl = self.augmentations(img, lbl)

        if self.is_transform:
            img, lbl = self.transform(img, lbl)

        return img, lbl 
开发者ID:zhechen,项目名称:PLARD,代码行数:19,代码来源:ade20k_loader.py

示例7: create_pkl

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [as 别名]
def create_pkl():
    with open(settings.TEST_CLASSIFICATION) as f:
        lines = f.read().splitlines()
    with open(settings.TEST_CLASSIFICATION_GT) as f:
        gt_lines = f.read().splitlines()
    assert len(lines) == len(gt_lines)
    test = []
    for i, line in enumerate(lines):
        anno = json.loads(line.strip())
        gt_anno = json.loads(gt_lines[i].strip())
        image = misc.imread(os.path.join(settings.TEST_IMAGE_DIR, anno['file_name']))
        assert image.shape == (anno['height'], anno['width'], 3)
        assert len(anno['proposals']) == len(gt_anno['ground_truth'])
        for proposal, gt in zip(anno['proposals'], gt_anno['ground_truth']):
            cropped = crop(image, proposal['adjusted_bbox'], 32)
            test.append([cropped, gt])
        if i % 100 == 0:
            print('test', i, '/', len(lines))
    with open(settings.TEST_CLS_CROPPED, 'wb') as f:
        cPickle.dump(test, f) 
开发者ID:yuantailing,项目名称:ctw-baseline,代码行数:22,代码来源:predictions2html.py

示例8: getInVidsAtFrame

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [as 别名]
def getInVidsAtFrame(f):
    arr = np.zeros([1, INVID_HEIGHT,INVID_WIDTH,INVID_DEPTH])
    for imageIndex in range(0,29):
        strIndex = str(f-14+imageIndex)
        while len(strIndex) < 4:
            strIndex = "0"+strIndex
        newImage = misc.imread('3/mouthImages/frame'+strIndex+'.jpg')

        if newImage.shape[0] > INVID_HEIGHT:
            extraMargin = (newImage.shape[0]-INVID_HEIGHT)//2
            newImage = newImage[extraMargin:extraMargin+INVID_HEIGHT,:,:]
        if newImage.shape[1] > INVID_WIDTH:
            extraMargin = (newImage.shape[1]-INVID_WIDTH)//2
            newImage = newImage[:,extraMargin:extraMargin+INVID_WIDTH,:]

        h = newImage.shape[0]
        w = newImage.shape[1]
        yStart = (INVID_HEIGHT-h)//2
        xStart = (INVID_WIDTH-w)//2
        arr[:,yStart:yStart+h,xStart:xStart+w,imageIndex*3:(imageIndex+1)*3] = newImage
    return np.asarray(arr)/255.0 
开发者ID:carykh,项目名称:videoToVoice,代码行数:23,代码来源:phoframeTrain.py

示例9: hist_feature_extract

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [as 别名]
def hist_feature_extract(feature_size, num_patch, max_length, patch_folder):
    fea_mat = np.zeros((num_patch,feature_size-4+2))
    tracklet_list = os.listdir(patch_folder)
    N_tracklet = len(tracklet_list)
    cnt = 0
    for n in range(N_tracklet):
        tracklet_folder = patch_folder+'/'+tracklet_list[n]
        patch_list = os.listdir(tracklet_folder)

        # get patch list, track_id and fr_id, starts from 1
        prev_cnt = cnt
        for m in range(len(patch_list)):
            # track_id
            fea_mat[cnt,0] = n+1
            # fr_id
            fea_mat[cnt,1] = int(patch_list[m][-8:-4])
            
            patch_list[m] = tracklet_folder+'/'+patch_list[m]
            patch_img = imread(patch_list[m])
            fea_mat[cnt,2:] = track_lib.extract_hist(patch_img)
            #import pdb; pdb.set_trace()
            cnt = cnt+1
    return fea_mat 
开发者ID:GaoangW,项目名称:TNT,代码行数:25,代码来源:tracklet_utils_3c.py

示例10: _compute_statistics_of_path_1

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [as 别名]
def _compute_statistics_of_path_1(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([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 = (imgs/255)*2-1

        m, s = calculate_activation_statistics(imgs, model, batch_size,
                                               dims, cuda)

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

示例11: _compute_statistics_of_path

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [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

示例12: resizeImg

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [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

示例13: resizeImg

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [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

示例14: resizeImg

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [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

示例15: read_image

# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import imread [as 别名]
def read_image(path):
    image = imread(path)
    if len(image.shape) != 3 or image.shape[2] != 3:
        print('Wrong image {} with shape {}'.format(path, image.shape))
        return None

    # split image
    h, w, c = image.shape
    assert w in [256, 512, 1200], 'Image size mismatch ({}, {})'.format(h, w)
    assert h in [128, 256, 600], 'Image size mismatch ({}, {})'.format(h, w)
    if 'maps' in path:
        image_a = image[:, w/2:, :].astype(np.float32) / 255.0
        image_b = image[:, :w/2, :].astype(np.float32) / 255.0
    else:
        image_a = image[:, :w/2, :].astype(np.float32) / 255.0
        image_b = image[:, w/2:, :].astype(np.float32) / 255.0

    # range of pixel values = [-1.0, 1.0]
    image_a = image_a * 2.0 - 1.0
    image_b = image_b * 2.0 - 1.0
    return image_a, image_b 
开发者ID:clvrai,项目名称:BicycleGAN-Tensorflow,代码行数:23,代码来源:data_loader.py


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