【问题标题】:How to load .mat images file using MATLAB如何使用 MATLAB 加载 .mat 图像文件
【发布时间】:2021-11-04 02:55:17
【问题描述】:

您好,我是 MATLAB 新手,我一直在尝试弄清楚如何使用 MATLAB 加载 faces1000.mat 文件和 nonfaces1000.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 和 nonfaces1000.mat 图像文件。我会很感激任何帮助,谢谢。

【问题讨论】:

    标签: matlab


    【解决方案1】:

    您可以通过这种方式加载 .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 论坛上的帖子。

    Load an image from .mat

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      • 2013-04-13
      • 2013-09-01
      相关资源
      最近更新 更多