使用MATLAB将数据文件转换为图像文件

时间:2013-06-14 11:00:30

标签: matlab jpeg ppm

我需要使用Matlab将数据文件转换为ppm / png /任何其他格式?我有一个数据文件有一列和250000行整数,范围从0到5。文件中的数据(如)如下:

2
1
0
5
2
1
3
.
.
.
0
5
1
4

我想将这些数据写入图像文件,例如ppm,jpeg或任何其他格式,我该如何使用Matlab进行操作?

1 个答案:

答案 0 :(得分:2)

让您的数据为A。

A = 1:12;
B = reshape(A,4,[]);
B =
     1     5     9
     2     6    10
     3     7    11
     4     8    12

I = mat2gray(B); %converts the matrix A to the intensity image I
imwrite(I,filename,fmt)