How do I represent an image and add a moire pattern?

Hello,
How can I represent an image(256 x 256 px) and then add a vertical pattern(white,black,white,black,etc) with a dimension of 3px each? Please help me.
Thanks

 Accepted Answer

img = zeros(256,256);
img(:, [1:6:end, 2:6:end, 3:6:end]) = 1;

More Answers (1)

Note that 256 is not a multiple of 3 (the width of your columns)
img = repmat([zeros(256, 3), ones(256, 3)], 1, ceil(256/6));
imshow(img);

2 Comments

So..I need to represent an image like this one. (this is made in Photoshop by me). The image needs to have 256 x 256px and each line that you see in the image to have 3px width. I have trouble with the code, could you help me, please?
Once the stupid typo I made is corrected (one of the zeros should have been ones, you get what you want (sort of, the image is 256x258 since 256 is not a multiple by 3).

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!