使用matlab创建黑/白方块

时间:2011-10-05 21:23:16

标签: matlab shapes

我要在Matlab中创建这三个简单的正方形:

任何人都可以帮我一把吗?我知道如何通过打开它们(imread)来使用图像,但我不知道如何在0上从matlab创建它们。

2 个答案:

答案 0 :(得分:4)

要创建图像编号3,您必须记住图像只是一个矩阵,黑色和白色可以分别用0和1表示。所以问题就变成了:如何在Matlab中创建一个除了特定区域之外都是零的二维数组?

%# create an empty image (all zeros)
%# use a logical image, since all we want to show 
%# are black and white

img = false(256,256);

%# to add the square, make the top left quarter white
%# by setting the pixel values to true (i.e. 1)

img(1:128,1:128) = true;

%# show the image
figure,imshow(img)

enter image description here

答案 1 :(得分:0)

pcolor可能是一个选项

pcolor(hadamard(20))
colormap(gray(2))
axis ij
axis square