深度学习|批处理图像保存到四维数组中

将文件夹中不同尺寸的图像保存到四维的数组中,作为数据集

方法1:

import numpy as np
import tensorflow as tf
from skimage import io
import os
import cv2
import matplotlib.pyplot as plt
from PIL import Image   #导入Image模块
def get_imagelist(path):   
    """
    此函数读取特定文件夹下的jpg格式图像,返回图片所在路径的列表
    函数输入:
    -path:图像文件夹路径
    函数输出:
    -imglist:图片所在路径列表
    """
    imglist=[os.path.join(path,f) for f in os.listdir(path) if f.endswith('.jpg') ]
    return imglist

def img_bprocess(path,m,n):
    """
    该函数返回图像组成的数组
    函数输入:
    -path:图像文件路径
    -m:图像长
    -n:图像宽
    函数输出:
    X_train:输出数据集数组.size(d,m,n,3)


    """
    imglist=get_imagelist(path) 
    #print (imglist)     #这里以list形式输出jpg格式的所有图像(带路径)
    d=len(imglist)    #这可以以输出图像个数,如果你的文件夹下有500张图片,那么d为500
    #print("图片个数:",d)
    X_train=np.empty((d,m,n,3))#建立d*&#x
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值