Fix script to scale threshold with image size