[英]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.