MATLAB does not make calculations with logical numbers, except for logical tests. When a logical matrix is used in an arithmetic calculation with a numeric matrix, the logical matrix is treated as numeric.
Please put in a breakpoint in your code at the step before "f = uint8(f)" and examine the range of values in the original "f" matrix. The uint8() type conversion rounds values, so if all entries in the original "f" matrix are less than 1/2 then the result would be all 0's.