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)

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.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Tareq
  • 3
  • 4
  • 2
    I hear you're supposed to use `imageio` instead of `skimage.io` because skimage is deprecating their `io` submodule -- are you **really** just asking to be linked to official documentation on how to use the library? – Christoph Rackwitz Jun 11 '22 at 22:37
  • Or you could use `imread` method from `matplotlib` to read images – Jeru Luke Jun 12 '22 at 13:49
  • Since you're doing segmentation, why don't you use a data generator? That way you don't have to read in all your data during your machine learning process. – Kevin M Jun 26 '22 at 00:59

1 Answers1

1

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]
FirefoxMetzger
  • 2,880
  • 1
  • 18
  • 32