adaptive threshold first attempt