improved conversion to double using im2double