Creating black/white squares using matlab
I'have to create these three simple squares in 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)
pcolor might be an option
pcolor(hadamard(20))
colormap(gray(2))
axis ij
axis square
精彩评论