function out = medfilt( in, fsiz )

offset = fix((fsiz-1)/2);
[rows,cols] = size( in );
out(rows,cols) = 0;
tmp(rows,cols) = 0;

for y = 1:rows,
        ty = max(1,y-offset);
        by = min(rows,y+offset);
        tmp(y,:) = median(in(ty:by,:));
end
for x = 1:cols,
        lx = max(1,x-offset);
        rx = min(cols,x+offset);
        out(:,x) = median(tmp(:,lx:rx)')';
end
