如何使用弹射读取图像

发布于 2025-02-07 00:04:24 字数 757 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪花飘飘的天空 2025-02-14 00:04:24

图像是JPG还是PNG对ImageIO没有影响。它将使用相同的语法将任何一种格式加载到ndarray中。

关于您将所有图像加载到文件夹中的愿望,我们有一个官方示例有关如何从文件夹中读取所有图像的官方:

import imageio.v3 as iio
from pathlib import Path

images = list()
for file in Path("path/to/folder").iterdir():
    if not file.is_file():
        continue

    images.append(iio.imread(file))

如果您想读取来自多个文件夹的图像列表,则以几乎相同的方式工作

import imageio.v3 as iio

list_of_files = []  # list of paths to images in various formats
images = [iio.imread(file_path) for file_path in list_of_files]

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:

import imageio.v3 as iio
from pathlib import Path

images = list()
for file in Path("path/to/folder").iterdir():
    if not file.is_file():
        continue

    images.append(iio.imread(file))

If you instead want to read a list of images from several folders, this works in almost the same way

import imageio.v3 as iio

list_of_files = []  # list of paths to images in various formats
images = [iio.imread(file_path) for file_path in list_of_files]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文