开发者

Creating black/white squares using matlab

I'have to create these three simple squares in Matlab:

Creating black/white squares using matlab

Can anyone give me a hand? I know how to use images by openning them (imread) but 开发者_StackOverflow社区I dont know how to create them on matlab from 0.


To create image number 3, you have to remember that an image is just a matrix, and that black and white can be represented by 0 and 1, respectively. So the question becomes: How can you create a 2D array in Matlab that is all zeros except for some specific region?

%# 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)

Creating black/white squares using matlab


pcolor might be an option

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜