如何将图像转换为矩阵

时间:2013-05-02 10:28:15

标签: matlab image-processing matrix

我感兴趣的是如何将给定的图像转换成只有数字的矩阵形式?例如,让我们看下面的图片

enter image description here

据我所知,matlab中存在特殊功能,它将给定的图像分解为颜色和数字,例如我在这个网站上看到过这段代码

I = imread('test.jpg');
b = dec2bin(I); % b becomes vector
% some actions with binary vector
du = bin2dec(b);
du = reshape(du,size(I)); % converting vector du to 3d Image array 
imwrite(uint8(du), 'du.jpg'); %save our du to file du.jpg

I = imread('du.jpg'); %test if it saved correctly
imshow(du) 

并转换为我的照片,就像这样

I=imread('tensor_in.jpg');

b=dec2bin(I)

并获取以下数组,实际上只有零和一个

00001110
00001111
00010000
00010000
00010001
00010010
00010011
00010101
00010110
00011000
00011001
00011000
00010101
00010101
00010101
00010101
00010101
00010101
00010101
00010101
00011000
00011000
00011000
00011000
00011000
00011000
00011000
00011000
00011011
00011011
00011011
00011011
00011011
00011011
00011011
00011011
00011100
00011100
00011100
00011101
00011101
00011110
00011110
00011101
00011110
00011011
00011011
00011011
00100000
00100011
00101001
00101011
00101111
显然我没有继续,因为它的大小是

<151074x8 char>

并遵循与例如

相同的规则
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

但我感兴趣的是,如果不是获取数字数组,如何使用其他数字获取数组,例如

2 1 3
4 21 23
67 89 100

让我们这样说吧。我可以用matlab做什么吗?请帮帮我

1 个答案:

答案 0 :(得分:4)

Dato,当你使用

I = imread('test.jpg');

您的图片已经是数字的数组形式。每个“数字”都会告诉您部分颜色信息。

如果图像文件是索引形式,您将获得NxM数组(对于大小为NxM的图像)。

如果图像未编入索引,您将获得一个NxMx3阵列,其中三个NxM阵列中的每一个分别对应红色,绿色和蓝色通道。

我建议您研究matlab如何处理图像:http://www.mathworks.de/de/help/matlab/creating_plots/working-with-images-in-matlab-graphics.html