Search code examples
pythonmatrixscikit-learnscikit-imageimread

reading all the images in a directory and saving as (.mat file matrixes) into another directory


I'm working with kinect, and just started with python.

I know how to read an image and save as a matrix in python.

But how can I manage to read all images in a directory and save as matrix files (.mat files) in another directory?

Could you give a brief short example?

Thanks,


Solution

  • Using scikit-image, you can utilise the ImageCollection object:

    from skimage import io
    images = io.imread_collection('/path/to/images/*.jpg')
    
    for (image, fn) in zip(images, images.files):
        np.savetxt(fn + '.txt', image)