1
$\begingroup$

The classical optical flow equation by Lukas-Kanade can be simplified as follow: $$ \frac{\delta I}{\delta x}\triangle x+\frac{\delta I}{\delta y}\triangle y + \frac{\delta I}{\delta t}\triangle t=0 $$

From here I can approximate the position vector (to the direction of intensity gradient) by: $$ \triangle s=\sqrt{\left(\frac{\frac{\delta I_{t+1}}{\delta x}}{\lvert\triangle I_t\rvert}\right)^2+{\left(\frac{\frac{\delta I_{t+1}}{\delta y}}{\lvert \triangle I_t\rvert}\right)^2}} $$

Where

$$ \lvert \triangle I_t\rvert=\sqrt{\left(\frac{\delta I_{t}}{\delta x}\right)^2+\left(\frac{\delta I_{t}}{\delta y}\right)^2} $$

However, when I try it out in MATLAB it seems that the displacement is not correct. See the code below, where I and I2 are the intensity image $I_t$ and $I_{t+1}$ respectively.

%generate two images
I=[255  255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 0   255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255]; 

I2=[255 255 255 255 255 255 255 255 255 255
255 255 255 255 0   255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255];

I=im2double(I);
I2=im2double(I2);
[Ix, Iy]=imgradientxy(I,'sobel');
[Ix2, Iy2]=imgradientxy(I2,'sobel');
I_scalar=sqrt(Ix.^2+Iy.^2);
intshift=sqrt(round(Ix2./I_scalar).^2+round(Iy2./I_scalar).^2);

As you can see, it has shifted $x=2$, $y=6$ (for the 0 value intensity). Which the intshift should be $6.32$. However that's not the case.

Would anyone please tell me where I did wrong?

$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.