modified in order to avoid sqare root of negative numbers when pixel value very similar to zero