CIFAR-10的Matlab可视化与转化

进来研究dl4j-examples里面的相关实例,经常用到例如MNIST、CIFAR等二进制图像集合。原程序用到的是二进制文件格式的读取,而如果想要看到里面数值具体的含义,需要对二进制文件进行可视化。

Matlab使用方便、编程简单,且无论在数值计算,还是在图像处理、模拟过程等方面都非常具有优势,缺点就是软件不开源、价格昂贵,因此滋生了如博主一样的广大盗版软件使用者_^_ 。

Matlab基础

1、导入数据:

load('you data path')
%获取文件名称、路径
[filename,filepath]=uigetfile()

2、读写图像:

[X, map] = imread(filename,format);%读入操作
imgray = rgb2gray(X);%转化为灰度图像
imwrite(image,filename);%图像写入文件操作

3、图像展示:

imshow(X,map);%显示图像
% 同一界面中显示多个图像
figure%假设显示四个图像
subplot(221),imshow(image1)
subplot(222),imshow(image2)
subplot(223),imshow(image3)
subplot(224),imshow(image4)

4、其它常识:

clear all%清空所有变量
close all%关闭所有Figure界面
quit/exit%退出Matlab

CIFAR-10数据集

该数据集的访问地址为http://www.cs.toronto.edu/~kriz/cifar.html,其中Python版本的图像显示可以参考python实现cifar10数据集的可视化

Matlab版本的数据集中包含以下文件:

  • batchs.meta.mat
  • data_batch_1.mat
  • data_batch_2.mat
  • data_batch_3.mat
  • data_batch_4.mat
  • data_batch_5.mat
  • readme.html
  • test_batch.mat

其中data_batch_i(1,2,3,4,5).mat中包含10000个32 <script type="math/tex" id="MathJax-Element-24">*</script>32图片,共有50000张图片;test_batch.mat为测试集数据,共有10000张图片。

Matlab代码

for j=1:5,%读取训练集数据
    %读入第j个batch的数据
    load(['data_batch_' num2str(j) '.mat'])
    for i=1:size(data,1),%循环转化并写入文件
        p=data(i,:);
        label=labels(i);

        fig=zeros(32,32,3);
        fig(:,:,1)=reshape(p(1:1024),32,32)';
        fig(:,:,2)=reshape(p(1025:2048),32,32)';
        fig(:,:,3)=reshape(p(2049:end),32,32)';

        %将数据保存为PNG格式
        imwrite(fig/256,['image/batch_' num2str(j) '_label_' num2str(label) '_' num2str(i)  '.png'])
    end;
end;
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值