如何将深度图像(.png)转换为mat格式

时间:2019-07-01 18:54:01

标签: python image mat

我从Kitti(卡尔斯鲁厄理工学院)下载了一个数据集,在该数据集中,我的图像尺寸为1216 * 352(宽*高)像素,位深度为24位。并对应那些图像,我有深度图像 尺寸为1216 * 352(宽*高)像素,位深为16位

我想将这些深度图像转换为.mat文件

我尝试在下面使用此代码。但是我认为这只是将文件扩展名更改为.mat文件,而不是结构

enter code here

folder = 'C:\somewhere\somefolder';
filelist = dir(fullfile(folder, '*.png'));  %get list of all jpg files in 
the folder
matnames = regexprep({filelist.name}, '\.png$', '.mat');  %replace .jpg 
by .mat in all file names
for fileidx = 1:numel(filelist)
  img = imread(fullfile(folder, filelist(fileidx).name)); %read image
  save(matnames{fileidx}, 'img');  %save in respective mat file
end

我要使用这些.mat文件的主程序位于

enter code here

import os
import locale
import scipy.io as sio
import numpy as np
import cv2
import functools

#For sorting files in alphabetical order
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

#Paths for GT and predictions
gt_path = "C:\\semodepth-master\\val_selection_cropped\\images_mat
pred_path = "C:\\semodepth-master\\val_selection_cropped\\mat"
#Get the file names for evaluation
gt_files = []
   for f in os.listdir(gt_path):
if '.mat' in f:
    gt_files.append(f)
pred_files = []
for f in os.listdir(pred_path):
if '.mat' in f:
    pred_files.append(f)

#Sort the file names
gt_files.sort(key=functools.cmp_to_key(locale.strcoll))
pred_files.sort(key=functools.cmp_to_key(locale.strcoll))

n_pxls = 0
#Initialize cumulative metric values
crms = 0
crmsl = 0
cabs_rel = 0
csq_rel = 0
cacc1 = 0
cacc2 = 0
cacc3 = 0

for i in range(0, len(gt_files)):
#Load GT and prediction depth maps
gt = sio.loadmat(os.path.join(gt_path, gt_files[i]))
pred = sio.loadmat(os.path.join(pred_path, pred_files[i]))
for key, value in gt.items() :
    print(key)
    print(value)
    print(len(gt))
gt_depths = gt["depth"]//*at this point when i run the code  it give an 
error that no "depth" are available in dictionary*//
h, w = np.shape(gt_depths)
pred_depths = np.squeeze(pred['mat'], axis=[0, 3])
#Resize prediction to match GT size
pred_depths = cv2.resize(pred_depths, (w, h), 
interpolation=cv2.INTER_LINEAR)
 gt = sio.loadmat(os.path.join(gt_path, gt_files[i]))
pred = sio.loadmat(os.path.join(pred_path, pred_files[i]))
for key, value in gt.items() :
    print(key)
    print(value)
    print(len(gt))
gt_depths = gt["depth"]
//*at this point when i run the code  it give an 
error that no "depth" are available in dictionary*//

0 个答案:

没有答案