如何使用弹射读取图像
seed = 42
np.random.seed = seed
Img_Width=128
Img_Height=128
Img_Channel = 3
Train_Path = 'stage1_train/'
Test_Path = 'stage1_test/'
train_ids = next(os.walk(Train_Path))[1]
test_ids = next(os.walk(Test_Path))[1]
print(train_ids)
X_train = np.zeros((len(train_ids), Img_Height, Img_Width, Img_Channel),dtype=np.uint8)
Y_train = np.zeros((len(train_ids),Img_Height, Img_Width, 1), dtype=bool)
上面的代码作为样本给出。我看到此代码并尝试加载数据集。
我想从一个文件夹加载所有图像数据。但是它有2个类型的文件。 1是.jpg文件2是.png文件。现在,我想将它们加载到两个不同的变量中。Variable= Train_ids,可以在其中加载来自多个文件夹的图像。但是,在我的数据集中,所有图像在同一文件夹中。如何加载它们?
这是我的路径,所有图像都位于: f:\分割\ isbi2016_isic_part3b_training_data \ isbi2016_isic_part3b_training_data_1
[此处.jpg& .png文件存在]
我的Python代码位于分段文件夹上。
seed = 42
np.random.seed = seed
Img_Width=128
Img_Height=128
Img_Channel = 3
Train_Path = 'stage1_train/'
Test_Path = 'stage1_test/'
train_ids = next(os.walk(Train_Path))[1]
test_ids = next(os.walk(Test_Path))[1]
print(train_ids)
X_train = np.zeros((len(train_ids), Img_Height, Img_Width, Img_Channel),dtype=np.uint8)
Y_train = np.zeros((len(train_ids),Img_Height, Img_Width, 1), dtype=bool)
Above's code give as sample. I see this code and try to load my dataset.
I want to load all the image data from one folder. But it has 2 types file. 1 is .jpg file 2 is .png file. Now I want to load them into two different variables.variable = train_ids, where I can load images from several folder. But, in my dataset all the images in the same folder. How can I load them all?
This is my path, where all the images located:
F:\segmentation\ISBI2016_ISIC_Part3B_Training_Data\ISBI2016_ISIC_Part3B_Training_Data_1
[Here .jpg & .png file present]
My python code has situated on segmentation folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
图像是JPG还是PNG对ImageIO没有影响。它将使用相同的语法将任何一种格式加载到ndarray中。
关于您将所有图像加载到文件夹中的愿望,我们有一个官方示例有关如何从文件夹中读取所有图像的官方:
如果您想读取来自多个文件夹的图像列表,则以几乎相同的方式工作
Whether the image is a JPG or a PNG makes no difference to ImageIO; it will load either format into a ndarray using the same syntax.
Regarding your the desire to load all images in a folder, we have an official example on how to read all images from a folder:
If you instead want to read a list of images from several folders, this works in almost the same way