IMAGEWIDTH = 720;
IMAGEHEIGHT = 486;
SUBWIDTH = 220:260;
SUBHEIGHT = 355:365;

%SUBWIDTH = 1:10;
%SUBHEIGHT = 1:10;

[foo, widthLen] = size(SUBWIDTH);
[foo, heightLen] = size(SUBHEIGHT);
yFlip = 0;


ort = dlmread('orientations.txt', ' ');
ind = dlmread('indices.txt', ' ');

u = .5*cos(ort);
v = .5*sin(ort);

uImg = zeros(IMAGEHEIGHT, IMAGEWIDTH);
vImg = zeros(IMAGEHEIGHT, IMAGEWIDTH);
uImg = uImg';
vImg = vImg';

uImg(ind+1) = u;
vImg(ind+1) = v;

uImg = uImg';
vImg = vImg';

[x, y] = meshgrid(SUBWIDTH(1):SUBWIDTH(widthLen),SUBHEIGHT(1):SUBHEIGHT(heightLen));
x2 = reshape(x', 1, widthLen*heightLen);
y2 = reshape(y', 1, widthLen*heightLen);

for i=1:widthLen*heightLen
yFlip(i) = y2(widthLen*heightLen-i+1);
end

subUImg = uImg(SUBWIDTH, SUBHEIGHT);
subVImg = vImg(SUBWIDTH, SUBHEIGHT);

uImgLong = reshape(subUImg', 1, widthLen*heightLen);
vImgLong = reshape(subVImg', 1, widthLen*heightLen);

max(uImgLong)
max(vImgLong)

figure;quiver(x2,yFlip,uImgLong,vImgLong, 0)




