MATLAB: How to create a binary grating pattern with Matlab

binary grating patterndifferent direction angledifferent phase

Hello Everyone,
I want to design several binary grating patterns with matlab. The matrix size is 1920*1080, the period is 4 pixels. The patterns have there direction angle, one is zero, the second is 2*pi/3, the last is 4*pi/3. I tried used square function, but the result is not correct. Does anyone know how to do this?
Thank you very much. Xiaolei

Best Answer

Well... what you could do is do:
I = zeros(1920,1080);
cols = 0:1080-1;
I(:,find(mod(cols,4)<2))=1;
and then use imrotate to get your direction angle.