как конвертировать изображения глубины (.png) в формат мата - PullRequest
0 голосов
/ 01 июля 2019

Я скачал набор данных из Китти (Технологический институт Карлсруэ), и в этом наборе данных у меня есть изображения размером 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*//
...