【发布时间】:2016-02-04 04:45:39
【问题描述】:
我正在尝试读取以下网站 ufldl.stanford.edu/housenumbers 中给出的 mat 文件,在文件 train.tar.gz 中,有一个名为 digitStruct.mat 的 mat 文件。
当我使用 scipy.io 读取 mat 文件时,它会提醒我消息“请使用 hdf reader for matlab v7.3 files”。
原始matlab文件如下所示
load digitStruct.mat
for i = 1:length(digitStruct)
im = imread([digitStruct(i).name]);
for j = 1:length(digitStruct(i).bbox)
[height, width] = size(im);
aa = max(digitStruct(i).bbox(j).top+1,1);
bb = min(digitStruct(i).bbox(j).top+digitStruct(i).bbox(j).height, height);
cc = max(digitStruct(i).bbox(j).left+1,1);
dd = min(digitStruct(i).bbox(j).left+digitStruct(i).bbox(j).width, width);
imshow(im(aa:bb, cc:dd, :));
fprintf('%d\n',digitStruct(i).bbox(j).label );
pause;
end
end
如上图,mat文件有key 'digitStruct',在'digitStruct'中可以找到key 'name'和'bbox',我使用h5py API读取文件。
import h5py
f = h5py.File('train.mat')
print len( f['digitStruct']['name'] ), len(f['digitStruct']['bbox'] )
我可以读取数组,但是当我循环遍历数组时,如何读取每个项目?
for i in f['digitStruct']['name']:
print i # only print out the HDF5 ref
【问题讨论】:
-
嘿,你有解决办法吗?我也有同样的问题。谢谢
标签: python matlab hdf5 mat h5py