[英]How to read images using skimage
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)
上面的代码作为示例给出。 我看到这段代码并尝试加载我的数据集。
我想从一个文件夹中加载所有图像数据。 但它有两种类型的文件。 1 是 .jpg 文件 2 是 .png 文件。 现在我想将它们加载到两个不同的 variables.variable = train_ids 中,我可以从多个文件夹加载图像。 但是,在我的数据集中,所有图像都在同一个文件夹中。 我怎样才能将它们全部加载?
这是我的路径,所有图像都位于:F:\segmentation\ISBI2016_ISIC_Part3B_Training_Data\ISBI2016_ISIC_Part3B_Training_Data_1
[这里有 .jpg 和 .png 文件]
我的 python 代码位于分段文件夹中。
图像是 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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.