0
$\begingroup$

I try to generate an image using this code.

w=10*pi/256;
E=zeros(256,256,100);
for t=1:100
for y=1:size(E,1)
    for x=1:size(E,2)
        E(x,y,t)=255*(sin(w)*sin(w*y*2)+1)/2)+1;
    end
end
imshow(E(:,:,t),[])
title(t);
drawnow
pause(0.1)
end

However I'm confused how to generate the image that shift over time, like for time t=2, the stripes is shifted by 0.0001 in the x direction.

Any idea how to fix this? Thank you.

$\endgroup$
2
$\begingroup$

Your code will produce a constant pattern along $x$ direction, so shifting this constant pattern along $x$ direction won't change anything.

To shift along $y$ direction you could replace $sin(2wy)$ by $sin(2wy + ct)$, and you have to choose $c$ depending on the amount of shift that you want.

Also you could create an initial image (for $t=1$) with an exactly integer number of periods, if at each time step your image shifted by integer number of pixels use circshift function to shift it by the amount that you want. If it doesn't shift by an integer number of pixels, you have to take the FFT of the image and change the phase linearly. in this case you have to change the phase by $c\times W_x$ where $c$ is the ammount of shift in the $x$ direction and the $W_x$ is the spatial frequency in the $x$ direction.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.