function OUT = hwt(IN, iterations);

[a,b] = size(IN);
count = 0;

OUT = IN;

while count < iterations,

k = 1;
j = 1;
index = 1;

while(k <= b),
  for j = 1:a,
    OUT1(j, index) = (IN(j,k)+IN(j,k+1))/2;
    OUT1(j, (b/2)+(index)) = (IN(j,k) - IN(j,k+1))/2;
  end
  index = index + 1;
  k = k + 2;
end

index = 1;
k = 1;
j = 1;

while(j <= a),
  for k = 1:b,
    OUT(index, k) = (OUT1(j,k) + OUT1(j+1,k))/2;
    OUT((a/2) + (index), k) = (OUT1(j,k) - OUT1(j+1, k))/2;
  end
  index = index + 1;
  j = j + 2;
end

a = a/2;
b = b/2;
count = count+1;
IN = OUT;
end

OUT = round(OUT);
