'''
This script is used to read multiple .mat files and convert to corresponding
.png files (or .jpg or anything else)
'''

import os
from scipy.io import loadmat
from scipy.misc import imsave

os.getcwd()

src_dir = './Datasets/2-UMichigan-corridor/mat/'
dst_dir = './Datasets/2-UMichigan-corridor/png/'

for i, filename in enumerate(os.listdir(src_dir)):
    # get image name from .mat file
    name_split = filename.split(".")
    name = name_split[0]
    print(name)

    # load .mat file and convert to .png file
    mat = loadmat(src_dir + filename)
    img = mat['ground_truth']
    img[img != -1] = 0  # force not-ground-pixels BLACK
    img[img == -1] = 1  # force ground-pixels WHITE

    # save .png file
    imsave(dst_dir + name + '.png', img)

02f73d0bedbbff7f6677ec1c728d5eaa3f302260
<mask token>

<mask token>
os.getcwd()
<mask token>
for i, filename in enumerate(os.listdir(src_dir)):
    name_split = filename.split('.')
    name = name_split[0]
    print(name)
    mat = loadmat(src_dir + filename)
    img = mat['ground_truth']
    img[img != -1] = 0
    img[img == -1] = 1
    imsave(dst_dir + name + '.png', img)

<mask token>
os.getcwd()
src_dir = './Datasets/2-UMichigan-corridor/mat/'
dst_dir = './Datasets/2-UMichigan-corridor/png/'
for i, filename in enumerate(os.listdir(src_dir)):
    name_split = filename.split('.')
    name = name_split[0]
    print(name)
    mat = loadmat(src_dir + filename)
    img = mat['ground_truth']
    img[img != -1] = 0
    img[img == -1] = 1
    imsave(dst_dir + name + '.png', img)

<mask token>
import os
from scipy.io import loadmat
from scipy.misc import imsave
os.getcwd()
src_dir = './Datasets/2-UMichigan-corridor/mat/'
dst_dir = './Datasets/2-UMichigan-corridor/png/'
for i, filename in enumerate(os.listdir(src_dir)):
    name_split = filename.split('.')
    name = name_split[0]
    print(name)
    mat = loadmat(src_dir + filename)
    img = mat['ground_truth']
    img[img != -1] = 0
    img[img == -1] = 1
    imsave(dst_dir + name + '.png', img)

'''
This script is used to read multiple .mat files and convert to corresponding
.png files (or .jpg or anything else)
'''

import os
from scipy.io import loadmat
from scipy.misc import imsave

os.getcwd()

src_dir = './Datasets/2-UMichigan-corridor/mat/'
dst_dir = './Datasets/2-UMichigan-corridor/png/'

for i, filename in enumerate(os.listdir(src_dir)):
    # get image name from .mat file
    name_split = filename.split(".")
    name = name_split[0]
    print(name)

    # load .mat file and convert to .png file
    mat = loadmat(src_dir + filename)
    img = mat['ground_truth']
    img[img != -1] = 0  # force not-ground-pixels BLACK
    img[img == -1] = 1  # force ground-pixels WHITE

    # save .png file
    imsave(dst_dir + name + '.png', img)
