removed pixel loop; added threshold check