如何使用MATLAB加载.mat图像文件



嗨,我是MATLAB的新手,我一直在试图弄清楚如何使用MATLAB加载faces1000.mat文件和nonfes1000.mat图像,我有一个load_mnist的代码,它是

mnist_file = 'scrambled_mnist10000.bin';
fid = fopen(mnist_file, 'r');
[number, count] = fread(fid, 1, 'int32');
if count ~= 1
disp('failed to read number');
end
[mnist_permutation, count] = fread(fid, number, 'int32');
if count ~= mnist_permutation
disp('failed to read number');
end

[mnist_labels, count] = fread(fid, number, 'uchar');
if count ~= number
disp('failed to read number');
end
mnist_digits = fread(fid, [28, 28 * number], 'uchar');
mnist_digits = reshape(mnist_digits, [28, 28, number]);
fclose(fid);
disp('loaded mnist digits');

我只是不确定我是否应该以同样的方式加载我的faces1000.mat和nonfes1000.mat图像文件。如果有任何帮助,我将不胜感激,谢谢。

您可以通过这种方式加载.mat文件

% Load entire mat file contents into a structure.
% The structure has a member "I" that is a double 512x512 array.
storedStructure = load('Data.mat');
% Extract out the image from the structure into its own variable.
% Don't use I as the variable name - bad for several reasons.
imageArray = storedStructure.s.I;  % Or storedStructure.I depending on what members your structure has.
% Display the image in a brand new figure window.
figure(1);
% Display double image, scaled appropriately.
% No need to cast to uint8 - could even be bad
% if your double numbers don't span the 0-255 range nicely.
imshow(imageArray, []);

这是基于MATLAB论坛上的一篇帖子。

从.mat 加载图像

最新更新